diff --git a/README.md b/README.md index 9d994ff..d806ed9 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ resource "shell_script" "github_repository" { DESCRIPTION = "description" } - + //sensitive environment variables are exactly the //same as environment variables except they don't //show up in log files @@ -178,6 +178,11 @@ resource "shell_script" "github_repository" { triggers = { when_value_changed = var.some_value } + + //if your shell_script resource is in a module that is instanciated several + //times, an error_tag can help you figure out which precise resource is impacted + //in case of an error + error_tag = "repo for ${var.username}" } output "id" { @@ -198,4 +203,3 @@ To run automated tests: ```sh $ make test ``` - diff --git a/shell/resource_shell_script.go b/shell/resource_shell_script.go index e647759..35af2ba 100644 --- a/shell/resource_shell_script.go +++ b/shell/resource_shell_script.go @@ -87,6 +87,11 @@ func resourceShellScript() *schema.Resource { Optional: true, Default: false, }, + "error_tag": { + Type: schema.TypeString, + Optional: true, + Default: "", + }, }, } } @@ -123,6 +128,7 @@ func create(d *schema.ResourceData, meta interface{}, stack []Action) error { interpreter := getInterpreter(client, d) workingDirectory := d.Get("working_directory").(string) enableParallelism := client.config.EnableParallelism + errorTag := d.Get("error_tag").(string) d.MarkNewResource() commandConfig := &CommandConfig{ @@ -133,6 +139,7 @@ func create(d *schema.ResourceData, meta interface{}, stack []Action) error { Interpreter: interpreter, Action: ActionCreate, EnableParallelism: enableParallelism, + ErrorTag: errorTag, } output, err := runCommand(commandConfig) if err != nil { @@ -180,6 +187,7 @@ func read(d *schema.ResourceData, meta interface{}, stack []Action) error { workingDirectory := d.Get("working_directory").(string) previousOutput := expandOutput(d.Get("output")) enableParallelism := client.config.EnableParallelism + errorTag := d.Get("error_tag").(string) commandConfig := &CommandConfig{ Command: command, @@ -190,6 +198,7 @@ func read(d *schema.ResourceData, meta interface{}, stack []Action) error { Action: ActionRead, PreviousOutput: previousOutput, EnableParallelism: enableParallelism, + ErrorTag: errorTag, } output, err := runCommand(commandConfig) if err != nil { @@ -242,6 +251,7 @@ func update(d *schema.ResourceData, meta interface{}, stack []Action) error { workingDirectory := d.Get("working_directory").(string) previousOutput := expandOutput(d.Get("output")) enableParallelism := client.config.EnableParallelism + errorTag := d.Get("error_tag").(string) commandConfig := &CommandConfig{ Command: command, @@ -252,6 +262,7 @@ func update(d *schema.ResourceData, meta interface{}, stack []Action) error { Action: ActionDelete, PreviousOutput: previousOutput, EnableParallelism: enableParallelism, + ErrorTag: errorTag, } output, err := runCommand(commandConfig) if err != nil { @@ -286,6 +297,7 @@ func delete(d *schema.ResourceData, meta interface{}, stack []Action) error { workingDirectory := d.Get("working_directory").(string) previousOutput := expandOutput(d.Get("output")) enableParallelism := client.config.EnableParallelism + errorTag := d.Get("error_tag").(string) commandConfig := &CommandConfig{ Command: command, @@ -296,6 +308,7 @@ func delete(d *schema.ResourceData, meta interface{}, stack []Action) error { Action: ActionDelete, PreviousOutput: previousOutput, EnableParallelism: enableParallelism, + ErrorTag: errorTag, } _, err := runCommand(commandConfig) if err != nil { diff --git a/shell/resource_shell_script_test.go b/shell/resource_shell_script_test.go index abb9ec6..70e995b 100644 --- a/shell/resource_shell_script_test.go +++ b/shell/resource_shell_script_test.go @@ -45,6 +45,20 @@ func TestAccShellShellScript_basic_error(t *testing.T) { }) } +func TestAccShellShellScript_basic_tagged_error(t *testing.T) { + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckShellScriptDestroy, + Steps: []resource.TestStep{ + { + Config: testAccShellScriptConfig_basic_tagged_error(), + ExpectNonEmptyPlan: true, + ExpectError: regexp.MustCompile("Tag: testErrorTag"), + }, + }, + }) +} + func TestAccShellShellScript_create_read_delete(t *testing.T) { resourceName := "shell_script.crd" rString := acctest.RandString(8) @@ -175,6 +189,26 @@ EOF `) } +func testAccShellScriptConfig_basic_tagged_error() string { + return fmt.Sprintf(` + resource "shell_script" "basic" { + lifecycle_commands { + create = <