scottwinkler / terraform-provider-shell

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

add triggers attribute and updates for provider sdk #15

Closed scottwinkler closed 4 years ago

scottwinkler commented 4 years ago

Addresses issue #14 created by @adudek

Add new triggers attribute (type map(any)) for shell_resource, which works exactly like triggers for a null_resource. Changes to the map will taint the resource and cause force new on the resource during the next apply. This provides an alternative to using update to force changes. An example implementation is shown below

resource "shell_script" "triggers" {
  lifecycle_commands {
    create = file("${path.module}/scripts/create.sh")
    read   = file("${path.module}/scripts/read.sh")
    delete = file("${path.module}/scripts/delete.sh")
  }

  triggers = {
    abc = 123
  }
}

Besides this, some new changes to update to latest provider sdk have been made.

References: https://www.terraform.io/docs/extend/plugin-sdk.html https://github.com/hashicorp/tf-sdk-migrator

adudek commented 4 years ago

Updated my project according to build instructions, and performed tests:

terraform init apply without changes (no triggers) - OK destroy without changes (no triggers) - OK apply with triggers - OK apply with trigger elements in different order - OK (nothing was replaced) apply with trigger elements values changed - OK (trigger-changed resources were replaced)