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

add an error_tag optional field to resource.shell_script #62

Open mrzor opened 4 years ago

mrzor commented 4 years ago

This is a hack that fixes #60.

I believe the footprint to be reasonably small and that it has some merit.

I'm tempted to use a DiffSuppressFunc that disables the diff entirely for this field, hoping to trigger no changes at all when adding an error_tag or changing it - but that may be counter-intuitive ; and it would take some explaining - so I refrained.

The biggest downside is that it's not very Terraformish. Maybe the real solution for #60 should be within Terraform itself.

The tests pass and I added an extra one, but I'm in no way sure that I did not break anything.

Feel free to close if you believe this fix is too much of a burden to maintain or ill designed.

scottwinkler commented 4 years ago

I think this could be a good idea except i would like to see it combined with the retry block from earlier. For example, I could see something like:

    resource "shell_script" "basic" {
        lifecycle_commands {
          create = <<EOF
            echo "Something went wrong!"
            exit 1
EOF
          delete = "exit 1"
        }
        environment = {
          filename= "create_delete.json"
        }
                on_error = {
                  tag = var.username
                  retry = {
                       exit_code = 30
                       delay = 5
                  }
                }
      }
)