@@ -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}
140135func (h handlerScriptResource ) attrs () (m map [string ]bool ) {
@@ -168,6 +163,9 @@ func (h handlerScriptResource) changedAttrInputs(rd haschange) (changed []string
168163func (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
172170func (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
204202func (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
0 commit comments