Terraform: local-exec provisioner missing 'command'

Created on 16 Sep 2015  ยท  6Comments  ยท  Source: hashicorp/terraform

Having strange issue while passing vars from one module to another. First module creates VPC incl. subnets, routing tables and SGs. Second module supposed to get vpc_name, region and run local-exec.

module "vpc" {
  source = "../../modules/vpc-terraform"
  region = "${var.region}"
  vpc_name = "${var.vpc_name}"
  vpc_network_prefix = "${var.vpc_network_prefix}"
}

module "consul_cluster_build" {
  source = "../../modules/cluster_build"
  vpc_name = "${module.vpc.vpc_name}"
  region = "${module.vpc.vpc_region}"
  service_name = "consul"
}

Outputs are in place.

cluster_build module is very simple. Get parameters and run chef-provisioning.

variable vpc_name {}
variable vpc_region {}
variable service_name {}
variable environment {}

resource "null_resource" "cluster_provisioning" {
   provisioner "local-exec" {
    command = "EC2_VPC=${var.vpc_name} EC2_REGION=${var.vpc_region} CHEF_ENVIRONMENT=${var.environment} chef-client -z provisioning/drivers/aws-fog.rb provisioning/cluster_${var.service_name}.rb"
  }
}

The reason we are passing vars from vpc module to cluster_build is to make a dependancy working, as module resource has no depends_on.
The apply fails, after successfully creating all vpc module resources, with

Error applying plan:

1 error(s) occurred:

* local-exec provisioner missing 'command'

If I'm passing vars to second module from configuration itself, and not from first module, everything runs. However run fails in chef-provisioning, because we must have vpc before using SGs and subnets in chef-provisioner.

Any Idea?

Thanks in advance!

bug core provisionelocal-exec

Most helpful comment

I'm getting the same issue with the latest terraform:

$ terraform --version
Terraform v0.11.1
+ provider.aws v1.2.0
+ provider.external v1.0.0
+ provider.null v1.0.0
+ provider.random v1.0.0
+ provider.template v1.0.0

module.Sanitise-UserData.null_resource.sanitise_vtm_userdata: Provisioning with 'local-exec'...

Error: Error applying plan:
1 error(s) occurred:
* module.Sanitise-UserData.null_resource.sanitise_vtm_userdata (destroy): 1 error(s) occurred:
* local-exec provisioner command must be a non-empty string

Code:

locals {
  userdata_filename = "ud-${var.environment}.tmp"
}

resource "null_resource" "sanitise_vtm_userdata" {
  provisioner "local-exec" {
    command = "echo '${var.vtm_userdata}' > ${local.userdata_filename}"
  }

  provisioner "local-exec" {
    when    = "create"
    command = "<blah-blah, this works fine with variables>"
  }

  provisioner "local-exec" {
    when    = "destroy"
    command = "rm -f ${local.userdata_filename}*"
  }
}

"Create" command works; but "destroy" doesn't.

All 6 comments

I too am having this issue, but can't seem to find a workaround. (even passing vars in from config results in the error below)

Error applying plan:

11 error(s) occurred:

* local-exec provisioner missing 'command'
* local-exec provisioner missing 'command'
* local-exec provisioner missing 'command'
* local-exec provisioner missing 'command'
* local-exec provisioner missing 'command'
* local-exec provisioner missing 'command'
* local-exec provisioner missing 'command'
* local-exec provisioner missing 'command'
* local-exec provisioner missing 'command'
* local-exec provisioner missing 'command'
* local-exec provisioner missing 'command'

I am trying to curl foreman to generate the necessary ENC data for puppet during creation, but I can't seem to get terraform to let me use vars in the local-exec.

I ran into this and #6287 fixed it for me.

I can't repro this anymore, I'm going to assume this is actually #6287 as @mikedanese stated... Thanks!

I'm getting the same issue with the latest terraform:

$ terraform --version
Terraform v0.11.1
+ provider.aws v1.2.0
+ provider.external v1.0.0
+ provider.null v1.0.0
+ provider.random v1.0.0
+ provider.template v1.0.0

module.Sanitise-UserData.null_resource.sanitise_vtm_userdata: Provisioning with 'local-exec'...

Error: Error applying plan:
1 error(s) occurred:
* module.Sanitise-UserData.null_resource.sanitise_vtm_userdata (destroy): 1 error(s) occurred:
* local-exec provisioner command must be a non-empty string

Code:

locals {
  userdata_filename = "ud-${var.environment}.tmp"
}

resource "null_resource" "sanitise_vtm_userdata" {
  provisioner "local-exec" {
    command = "echo '${var.vtm_userdata}' > ${local.userdata_filename}"
  }

  provisioner "local-exec" {
    when    = "create"
    command = "<blah-blah, this works fine with variables>"
  }

  provisioner "local-exec" {
    when    = "destroy"
    command = "rm -f ${local.userdata_filename}*"
  }
}

"Create" command works; but "destroy" doesn't.

Any good news for this?
Looks like it is not possible to use variables in local-exec command with "when=destroy" block.
Actually, it works fine for first run (execute commands with vars), but if first run fails second run is not possible =>
Error: local-exec provisioner command must be a non-empty string

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings