Skip to content

Commit 9e909ce

Browse files
committed
Merge branch 'release/v0.3.7'
2 parents 53092b8 + 443d61a commit 9e909ce

File tree

2 files changed

+24
-35
lines changed

2 files changed

+24
-35
lines changed

linux/script-resource.go

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const (
3030
attrScriptWorkingDirectory = "working_directory"
3131
attrScriptDirty = "dirty"
3232
attrScriptReadFailed = "read_failed"
33-
attrScriptReadError = "read_error"
3433
attrScriptOutput = "output"
3534
)
3635

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

9796
attrScriptDirty: {
98-
Type: schema.TypeBool,
99-
Optional: true,
100-
Default: false,
97+
Type: schema.TypeBool,
98+
Optional: true,
99+
Default: false,
100+
Description: "`true` if new output is different than previous output. User must not manually set it to `true`",
101101
},
102102
attrScriptReadFailed: {
103-
Type: schema.TypeBool,
104-
Optional: true,
105-
Default: false,
106-
},
107-
attrScriptReadError: {
108-
Type: schema.TypeString,
109-
Optional: true,
110-
Default: "",
103+
Type: schema.TypeBool,
104+
Optional: true,
105+
Default: false,
106+
Description: "`true` if read operation result in execution error. User must not manually set it to `true`",
111107
},
112108
}
113109

@@ -134,7 +130,6 @@ func (h handlerScriptResource) attrInternal() map[string]bool {
134130
return map[string]bool{
135131
attrScriptDirty: true,
136132
attrScriptReadFailed: true,
137-
attrScriptReadError: true,
138133
}
139134
}
140135
func (h handlerScriptResource) attrs() (m map[string]bool) {
@@ -168,6 +163,9 @@ func (h handlerScriptResource) changedAttrInputs(rd haschange) (changed []string
168163
func (h handlerScriptResource) changedAttrCommands(rd haschange) (changed []string) {
169164
return h.changed(rd, h.attrCommands())
170165
}
166+
func (h handlerScriptResource) changedAttrInternal(rd haschange) (changed []string) {
167+
return h.changed(rd, h.attrInternal())
168+
}
171169

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

205+
_ = rd.Set(attrScriptReadFailed, false)
207206
err := h.read(ctx, rd, meta.(*linux))
208-
switch errExit := (*remote.ExitError)(nil); {
209-
case errors.As(err, &errExit):
207+
if errExit := (*remote.ExitError)(nil); errors.As(err, &errExit) {
210208
_ = rd.Set(attrScriptReadFailed, true)
211-
_ = rd.Set(attrScriptReadError, err.Error())
209+
_ = rd.Set(attrScriptOutput, err.Error())
212210
return
213-
214-
default:
215-
_ = rd.Set(attrScriptReadFailed, false)
216-
_ = rd.Set(attrScriptReadError, "")
217211
}
218212
if err != nil {
219213
return diag.FromErr(err)
@@ -318,19 +312,7 @@ func (h handlerScriptResource) CustomizeDiff(c context.Context, rd *schema.Resou
318312
return // updateable
319313
}
320314

321-
for _, key := range rd.GetChangedKeysPrefix("") {
322-
if strings.HasPrefix(key, attrScriptTriggers) {
323-
continue // already force new.
324-
}
325-
326-
// need to remove index from map and list
327-
switch {
328-
case strings.HasPrefix(key, attrScriptEnvironment):
329-
fallthrough
330-
case strings.HasPrefix(key, attrScriptSensitiveEnvironment):
331-
parts := strings.Split(key, ".")
332-
key = strings.Join(parts[:len(parts)-1], ".")
333-
}
315+
for _, key := range append(h.changedAttrInputs(rd), h.changedAttrInternal(rd)...) {
334316
err = rd.ForceNew(key)
335317
if err != nil {
336318
return

linux/script-resource_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ func TestAccLinuxScriptNoUpdate(t *testing.T) {
151151
tc.Script.Environment.
152152
With("FILE", fmt.Sprintf(`"/tmp/linux1/%s"`, acctest.RandString(16)))
153153
})
154-
conf4 := conf2.Copy(func(tc *tfConf) {
154+
conf4 := conf3.Copy(func(tc *tfConf) {
155+
tc.Script.Triggers.
156+
With("HELLO", `"world"`)
157+
})
158+
conf5 := conf2.Copy(func(tc *tfConf) {
155159
tc.Extra.With("Taint", `\n`)
156160
})
157161

@@ -170,7 +174,10 @@ func TestAccLinuxScriptNoUpdate(t *testing.T) {
170174
Config: testAccLinuxScriptNoUpdateConfig(t, conf3),
171175
},
172176
{
173-
Config: testAccLinuxScriptNoUpdateConfig(t, conf4),
177+
Config: testAccLinuxScriptNoUpdateConfig(t, conf4),
178+
},
179+
{
180+
Config: testAccLinuxScriptNoUpdateConfig(t, conf5),
174181
ExpectNonEmptyPlan: true,
175182
},
176183
},

0 commit comments

Comments
 (0)