terraform-provider-shell icon indicating copy to clipboard operation
terraform-provider-shell copied to clipboard

Error: "changes to `lifecycle_commands` and/or `interpreter` should not be follwed by changes to other arguments"

Open jamesarosen opened this issue 4 years ago • 4 comments

When I tried to run terraform plan, I received this error:

changes to `lifecycle_commands` and/or `interpreter` should not be follwed by changes to other arguments

I'm not sure what it means. I'm using a shell resource like so:

# modules/foo/main.tf
resource "shell_script" "this" {
  lifecycle_commands {
    create = file("${path.module}/create.sh")
    delete = ""
    read   = ""
    update = file("${path.module}/update.sh")
  }

  environment = {
    NAME = "${var.name}"
  }
}

# modules/foo/variables.tf
variable "name" {
  type = string
}

# a_bunch_of_foos.tf
module "foo-1" {
  source = "./modules/foo"
  name   = "bar"
}

module "foo-2" {
  source = "./modules/foo"
  name   = "baz"
}

module "foo-2" {
  source = "./modules/foo"
  name   = "quux"
}

jamesarosen avatar Feb 25 '21 20:02 jamesarosen

Just ran into this too. The referenced code helped me understand what I should do differently.

Seems like if either lifecycle_commands or interpreter change, then any of environment, sensitive_environment, or working_directory can't also change in the same plan. You have to break up your changes across two plans. I'm not quite sure why this is a requirement, but that's the workaround.

In my case, I had to change the script defining my lifecycle command first, and run its plan and apply. Then I changed my environment, and ran its plan and applied again.

andreykaipov avatar Jun 24 '21 19:06 andreykaipov