matti / terraform-shell-resource

Run (exec) a command in shell and capture the output (stdout, stderr) and status code (exit status)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update from version 1.2.0 to 1.3.0 failed

wszychta opened this issue · comments

Hello,

I have made below change in terraform code:
from:

module "rcp_secret" {
  source = "matti/resource/shell"
  version = "1.2.0"
  command = "openssl rand -hex 16"
}
module "rcp_secret" {
  source = "matti/resource/shell"
  version = "1.3.0"
  command = "openssl rand -hex 16"
}

This is terraform output of this change:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with
the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # module.rcp_secret.null_resource.contents must be replaced
-/+ resource "null_resource" "contents" {
      ~ id       = "725547638413077160" -> (known after apply)
      ~ triggers = {
          - "exitstatus" = "0"
          - "id"         = "3950419151389654331"
          - "stderr"     = ""
          - "stdout"     = "XXXXXXXXXXXXXXXXXXXXXXXXX"
        } -> (known after apply) # forces replacement
    }

  # module.rcp_secret.null_resource.shell must be replaced
-/+ resource "null_resource" "shell" {
      ~ id       = "3950419151389654331" -> (known after apply)
      ~ triggers = { # forces replacement
          - "command_chomped"              = "openssl rand -hex 16" -> null
          + "command_unix"                 = "openssl rand -hex 16"
          - "command_when_destroy_chomped" = ":" -> null
          + "command_when_destroy_unix"    = ":"
          + "command_when_destroy_windows" = "% ':'"
          + "command_windows"              = "openssl rand -hex 16"
          + "fail_on_error"                = "false"
            # (7 unchanged elements hidden)
        }
    }

Plan: 2 to add, 0 to change, 2 to destroy.

and terraform error after apply:

│ Error: Missing map element
│ 
│   on .terraform/modules/rcp_secret/main.tf line 50, in resource "null_resource" "shell":
│   50:     command = dirname("/") == "\\" ? self.triggers.command_when_destroy_windows : self.triggers.command_when_destroy_unix
│     ├────────────────
│     │ self.triggers is map of string with 9 elements
│ 
│ This map does not have an element with the key "command_when_destroy_unix".

I wanted to just inform you about this issue. I believe that it will happen with other commands and operating systems. To run this code I used:

  • Operating system: Kubuntu 21.04
  • Terraform version: 1.0.0

I am running into the exact same problem.

My terraform state was created by version 1.2.0 of the module and only contains the following triggers:

"triggers": {
  "command_chomped": "<My command>",
  "command_when_destroy_chomped": ":",
  "environment_keys": "",
  "environment_values": "",
  "random_uuid": "<UUID>",
  "sensitive_environment_keys": "",
  "sensitive_environment_values": "<ID>",
  "trigger": "",
  "working_dir": ""
}

it looks like the switch from command and command_when_destroy to the unix and windows specific commands was a breaking change and maybe should've been in a 2.0.0 release?

This was the change between versions 1.2.0 and 1.3.0 in PR #40

cc: @KyleKotowick @matti

commented

Hello All,

Can someone please share a workaround for the above, I tried moving from version v1.1.0 to v1.5.0 and got the same error.

I'm not using this hack actively anymore (and to be frank I don't even know how this stays together) - somebody ™️ should write a golang provider instead OR take over this project.

I've been maintaining similar but separate modules (re-writes, not a fork) here:
shell-data
shell-resource

They seem to be working well, but they could certainly benefit from more users/testers.

Just a heads up for everyone, I just released new versions of those two modules that are complete re-writes and offer a lot more features.

Hopefully they should address most of the issues with Matti's module and the older versions of the above modules.