scottwinkler / terraform-provider-shell

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

Provider doesn't perform "update" when i'm changing the update script. #124

Open arielbeckjit opened 1 year ago

arielbeckjit commented 1 year ago

Hi, so i have the following configuration:

resource "shell_script" "configure-data-api" {
  environment = {
    ENV = 1
  }
  sensitive_environment = {
    AUTH = var.creds
  }
  lifecycle_commands {
    create = file("${path.module}/configure_data_api_scripts/create.sh")
    update = file("${path.module}/configure_data_api_scripts/update.sh")
    read   = file("${path.module}/configure_data_api_scripts/get.sh")
    delete = file("${path.module}/configure_data_api_scripts/delete.sh")
  }
  interpreter = ["/bin/bash", "-c"]

  lifecycle {
    ignore_changes = [
      sensitive_environment
    ]
  }

  working_directory = path.module
}

The read is the one that outputs the state. I've enabled debug, and when i've done change in the update (echo something to file) - it just doesn't run. When i change afterward an env var, then it runs.

this is the log i'm seeing, it looks like update wasn't even run (no debug log from update)

2023-05-07T20:50:52.571+0300 [WARN]  Provider "registry.terraform.io/scottwinkler/shell" produced an invalid plan for module.......configure-data-api, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .dirty: planned value cty.False for a non-computed attribute
      - .read_error: planned value cty.StringVal("") for a non-computed attribute
module........configure-data-api: Modifying... [id=ch922u7o42dch29efo30]
2023-05-07T20:50:52.593+0300 [INFO]  Starting apply for module........shell_script.configure-data-api
2023-05-07T20:50:52.593+0300 [DEBUG] module......].shell_script.configure-data-api: applying the planned Update change
module.......t.configure-data-api: Modifications complete after 0s [id=ch922u7o42dch29efo30]

I've managed to see where's the problem, this code when update is performed:

    if d.HasChanges("lifecycle_commands", "interpreter") {
        return
    }

lifecycle_commands changes of course, because script is updated - so the update is not triggered...

related PR that added the bug https://github.com/scottwinkler/terraform-provider-shell/issues/81