Skip to content

Commit

Permalink
Merge branch 'release/v0.3.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
rucciva committed Nov 12, 2020
2 parents 53092b8 + 443d61a commit 9e909ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
48 changes: 15 additions & 33 deletions linux/script-resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const (
attrScriptWorkingDirectory = "working_directory"
attrScriptDirty = "dirty"
attrScriptReadFailed = "read_failed"
attrScriptReadError = "read_error"
attrScriptOutput = "output"
)

Expand Down Expand Up @@ -95,19 +94,16 @@ var schemaScriptResource = map[string]*schema.Schema{
},

attrScriptDirty: {
Type: schema.TypeBool,
Optional: true,
Default: false,
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "`true` if new output is different than previous output. User must not manually set it to `true`",
},
attrScriptReadFailed: {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
attrScriptReadError: {
Type: schema.TypeString,
Optional: true,
Default: "",
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "`true` if read operation result in execution error. User must not manually set it to `true`",
},
}

Expand All @@ -134,7 +130,6 @@ func (h handlerScriptResource) attrInternal() map[string]bool {
return map[string]bool{
attrScriptDirty: true,
attrScriptReadFailed: true,
attrScriptReadError: true,
}
}
func (h handlerScriptResource) attrs() (m map[string]bool) {
Expand Down Expand Up @@ -168,6 +163,9 @@ func (h handlerScriptResource) changedAttrInputs(rd haschange) (changed []string
func (h handlerScriptResource) changedAttrCommands(rd haschange) (changed []string) {
return h.changed(rd, h.attrCommands())
}
func (h handlerScriptResource) changedAttrInternal(rd haschange) (changed []string) {
return h.changed(rd, h.attrInternal())
}

func (h handlerScriptResource) newScript(rd *schema.ResourceData, l *linux, attrLifeCycle string) (s *script) {
if rd == nil {
Expand Down Expand Up @@ -204,16 +202,12 @@ func (h handlerScriptResource) read(ctx context.Context, rd *schema.ResourceData
func (h handlerScriptResource) Read(ctx context.Context, rd *schema.ResourceData, meta interface{}) (d diag.Diagnostics) {
old := cast.ToString(rd.Get(attrScriptOutput))

_ = rd.Set(attrScriptReadFailed, false)
err := h.read(ctx, rd, meta.(*linux))
switch errExit := (*remote.ExitError)(nil); {
case errors.As(err, &errExit):
if errExit := (*remote.ExitError)(nil); errors.As(err, &errExit) {
_ = rd.Set(attrScriptReadFailed, true)
_ = rd.Set(attrScriptReadError, err.Error())
_ = rd.Set(attrScriptOutput, err.Error())
return

default:
_ = rd.Set(attrScriptReadFailed, false)
_ = rd.Set(attrScriptReadError, "")
}
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -318,19 +312,7 @@ func (h handlerScriptResource) CustomizeDiff(c context.Context, rd *schema.Resou
return // updateable
}

for _, key := range rd.GetChangedKeysPrefix("") {
if strings.HasPrefix(key, attrScriptTriggers) {
continue // already force new.
}

// need to remove index from map and list
switch {
case strings.HasPrefix(key, attrScriptEnvironment):
fallthrough
case strings.HasPrefix(key, attrScriptSensitiveEnvironment):
parts := strings.Split(key, ".")
key = strings.Join(parts[:len(parts)-1], ".")
}
for _, key := range append(h.changedAttrInputs(rd), h.changedAttrInternal(rd)...) {
err = rd.ForceNew(key)
if err != nil {
return
Expand Down
11 changes: 9 additions & 2 deletions linux/script-resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ func TestAccLinuxScriptNoUpdate(t *testing.T) {
tc.Script.Environment.
With("FILE", fmt.Sprintf(`"/tmp/linux1/%s"`, acctest.RandString(16)))
})
conf4 := conf2.Copy(func(tc *tfConf) {
conf4 := conf3.Copy(func(tc *tfConf) {
tc.Script.Triggers.
With("HELLO", `"world"`)
})
conf5 := conf2.Copy(func(tc *tfConf) {
tc.Extra.With("Taint", `\n`)
})

Expand All @@ -170,7 +174,10 @@ func TestAccLinuxScriptNoUpdate(t *testing.T) {
Config: testAccLinuxScriptNoUpdateConfig(t, conf3),
},
{
Config: testAccLinuxScriptNoUpdateConfig(t, conf4),
Config: testAccLinuxScriptNoUpdateConfig(t, conf4),
},
{
Config: testAccLinuxScriptNoUpdateConfig(t, conf5),
ExpectNonEmptyPlan: true,
},
},
Expand Down

0 comments on commit 9e909ce

Please sign in to comment.