Skip to content

Commit 3c8cd6a

Browse files
authored
Merge pull request #68 from scottwinkler/fix/forcenew
remove force new
2 parents a83ac8b + ff4430d commit 3c8cd6a

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

shell/data_source_shell_script.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ func dataSourceShellScript() *schema.Resource {
1515
"lifecycle_commands": {
1616
Type: schema.TypeList,
1717
Required: true,
18-
ForceNew: true,
1918
MaxItems: 1,
2019
Elem: &schema.Resource{
2120
Schema: map[string]*schema.Schema{
2221
"read": {
2322
Type: schema.TypeString,
2423
Required: true,
25-
ForceNew: true,
2624
},
2725
},
2826
},
@@ -36,21 +34,20 @@ func dataSourceShellScript() *schema.Resource {
3634
"sensitive_environment": {
3735
Type: schema.TypeMap,
3836
Optional: true,
37+
ForceNew: true,
3938
Elem: schema.TypeString,
4039
Sensitive: true,
4140
},
4241
"interpreter": {
4342
Type: schema.TypeList,
4443
Optional: true,
45-
ForceNew: true,
4644
Elem: &schema.Schema{
4745
Type: schema.TypeString,
4846
},
4947
},
5048
"working_directory": {
5149
Type: schema.TypeString,
5250
Optional: true,
53-
ForceNew: true,
5451
Default: ".",
5552
},
5653
"output": {

shell/resource_shell_script.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ func resourceShellScript() *schema.Resource {
2222
"lifecycle_commands": {
2323
Type: schema.TypeList,
2424
Required: true,
25-
ForceNew: true,
2625
MaxItems: 1,
2726
Elem: &schema.Resource{
2827
Schema: map[string]*schema.Schema{
2928
"create": {
3029
Type: schema.TypeString,
3130
Required: true,
32-
ForceNew: true,
3331
},
3432
"update": {
3533
Type: schema.TypeString,
@@ -38,7 +36,6 @@ func resourceShellScript() *schema.Resource {
3836
"read": {
3937
Type: schema.TypeString,
4038
Optional: true,
41-
ForceNew: true,
4239
},
4340
"delete": {
4441
Type: schema.TypeString,
@@ -55,26 +52,26 @@ func resourceShellScript() *schema.Resource {
5552
"environment": {
5653
Type: schema.TypeMap,
5754
Optional: true,
55+
ForceNew: true,
5856
Elem: schema.TypeString,
5957
},
6058
"sensitive_environment": {
6159
Type: schema.TypeMap,
6260
Optional: true,
61+
ForceNew: true,
6362
Elem: schema.TypeString,
6463
Sensitive: true,
6564
},
6665
"interpreter": {
6766
Type: schema.TypeList,
6867
Optional: true,
69-
ForceNew: true,
7068
Elem: &schema.Schema{
7169
Type: schema.TypeString,
7270
},
7371
},
7472
"working_directory": {
7573
Type: schema.TypeString,
7674
Optional: true,
77-
ForceNew: true,
7875
Default: ".",
7976
},
8077
"output": {

shell/utility.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package shell
33
import (
44
"bytes"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"log"
89
"os"
@@ -98,7 +99,17 @@ func runCommand(c *CommandConfig) (map[string]string, error) {
9899

99100
// If the script exited with a non-zero code then send the error up to Terraform
100101
if err != nil {
101-
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)
102+
errorS := "Error occured during shell execution.\n"
103+
errorS += "Error: \n" + err.Error() + "\n\n"
104+
errorS += "Command: \n" + sanitizeString(c.Command, secretValues) + "\n\n"
105+
errorS += "StdOut: \n" + sanitizeString(stdOutput, secretValues) + "\n\n"
106+
errorS += "StdErr: \n" + sanitizeString(stdError, secretValues) + "\n\n"
107+
errorS += fmt.Sprintf("Env: \n%s\n\n", c.Environment)
108+
if c.Action != ActionCreate {
109+
stdin, _ := json.Marshal(c.PreviousOutput)
110+
errorS += fmt.Sprintf("StdIn: \n'%s'\n", stdin)
111+
}
112+
return nil, errors.New(errorS)
102113
}
103114

104115
log.Printf("-------------------------")

0 commit comments

Comments
 (0)