Skip to content

Commit

Permalink
Merge pull request #68 from scottwinkler/fix/forcenew
Browse files Browse the repository at this point in the history
remove force new
  • Loading branch information
scottwinkler authored Aug 7, 2020
2 parents a83ac8b + ff4430d commit 3c8cd6a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 1 addition & 4 deletions shell/data_source_shell_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand All @@ -36,21 +34,20 @@ 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,
},
},
"working_directory": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: ".",
},
"output": {
Expand Down
7 changes: 2 additions & 5 deletions shell/resource_shell_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -38,7 +36,6 @@ func resourceShellScript() *schema.Resource {
"read": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"delete": {
Type: schema.TypeString,
Expand All @@ -55,26 +52,26 @@ 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,
},
},
"working_directory": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: ".",
},
"output": {
Expand Down
13 changes: 12 additions & 1 deletion shell/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package shell
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -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("-------------------------")
Expand Down

0 comments on commit 3c8cd6a

Please sign in to comment.