scottwinkler / terraform-provider-shell

Terraform provider for executing shell commands and saving output to state file
Mozilla Public License 2.0
278 stars 61 forks source link

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

Open jamesarosen opened 3 years ago

jamesarosen commented 3 years ago

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"
}
andreykaipov commented 3 years ago

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.

justinmchase commented 3 months ago

This is such a frustrating bug. It can block an entire deploy if someone removes an input variable. It should absolutely be ok to change both at the same time.