From ff4430d4b242c8773d6a015b3d15266cceb0a855 Mon Sep 17 00:00:00 2001 From: Scott Winkler Date: Fri, 7 Aug 2020 00:57:20 -0700 Subject: [PATCH] remove force new --- shell/data_source_shell_script.go | 5 +---- shell/resource_shell_script.go | 7 ++----- shell/utility.go | 13 ++++++++++++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/shell/data_source_shell_script.go b/shell/data_source_shell_script.go index f6ab308..f5d1e56 100644 --- a/shell/data_source_shell_script.go +++ b/shell/data_source_shell_script.go @@ -15,14 +15,12 @@ func dataSourceShellScript() *schema.Resource { "lifecycle_commands": { Type: schema.TypeList, Required: true, - ForceNew: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "read": { Type: schema.TypeString, Required: true, - ForceNew: true, }, }, }, @@ -36,13 +34,13 @@ func dataSourceShellScript() *schema.Resource { "sensitive_environment": { Type: schema.TypeMap, Optional: true, + ForceNew: true, Elem: schema.TypeString, Sensitive: true, }, "interpreter": { Type: schema.TypeList, Optional: true, - ForceNew: true, Elem: &schema.Schema{ Type: schema.TypeString, }, @@ -50,7 +48,6 @@ func dataSourceShellScript() *schema.Resource { "working_directory": { Type: schema.TypeString, Optional: true, - ForceNew: true, Default: ".", }, "output": { diff --git a/shell/resource_shell_script.go b/shell/resource_shell_script.go index e647759..77d13e2 100644 --- a/shell/resource_shell_script.go +++ b/shell/resource_shell_script.go @@ -22,14 +22,12 @@ func resourceShellScript() *schema.Resource { "lifecycle_commands": { Type: schema.TypeList, Required: true, - ForceNew: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "create": { Type: schema.TypeString, Required: true, - ForceNew: true, }, "update": { Type: schema.TypeString, @@ -38,7 +36,6 @@ func resourceShellScript() *schema.Resource { "read": { Type: schema.TypeString, Optional: true, - ForceNew: true, }, "delete": { Type: schema.TypeString, @@ -55,18 +52,19 @@ func resourceShellScript() *schema.Resource { "environment": { Type: schema.TypeMap, Optional: true, + ForceNew: true, Elem: schema.TypeString, }, "sensitive_environment": { Type: schema.TypeMap, Optional: true, + ForceNew: true, Elem: schema.TypeString, Sensitive: true, }, "interpreter": { Type: schema.TypeList, Optional: true, - ForceNew: true, Elem: &schema.Schema{ Type: schema.TypeString, }, @@ -74,7 +72,6 @@ func resourceShellScript() *schema.Resource { "working_directory": { Type: schema.TypeString, Optional: true, - ForceNew: true, Default: ".", }, "output": { diff --git a/shell/utility.go b/shell/utility.go index ae3326f..7e80da4 100644 --- a/shell/utility.go +++ b/shell/utility.go @@ -3,6 +3,7 @@ package shell import ( "bytes" "encoding/json" + "errors" "fmt" "log" "os" @@ -98,7 +99,17 @@ func runCommand(c *CommandConfig) (map[string]string, error) { // If the script exited with a non-zero code then send the error up to Terraform if err != nil { - return nil, fmt.Errorf("Error occurred during execution.\n Command: '%s' \n Error: '%s' \n StdOut: \n %s \n StdErr: \n %s", c.Command, err.Error(), stdOutput, stdError) + errorS := "Error occured during shell execution.\n" + errorS += "Error: \n" + err.Error() + "\n\n" + errorS += "Command: \n" + sanitizeString(c.Command, secretValues) + "\n\n" + errorS += "StdOut: \n" + sanitizeString(stdOutput, secretValues) + "\n\n" + errorS += "StdErr: \n" + sanitizeString(stdError, secretValues) + "\n\n" + errorS += fmt.Sprintf("Env: \n%s\n\n", c.Environment) + if c.Action != ActionCreate { + stdin, _ := json.Marshal(c.PreviousOutput) + errorS += fmt.Sprintf("StdIn: \n'%s'\n", stdin) + } + return nil, errors.New(errorS) } log.Printf("-------------------------")