11package shell
22
33import (
4+ "fmt"
45 "log"
56 "reflect"
67 "runtime"
@@ -87,6 +88,10 @@ func resourceShellScript() *schema.Resource {
8788 Type : schema .TypeString ,
8889 Optional : true ,
8990 Default : "" ,
91+ ValidateFunc : func (i interface {}, s string ) ([]string , []error ) {
92+ x0 := fmt .Errorf ("`read_error` cannot be set from configuration" )
93+ return []string {}, []error {x0 }
94+ },
9095 },
9196 },
9297 }
@@ -110,7 +115,19 @@ func resourceShellScriptRead(d *schema.ResourceData, meta interface{}) error {
110115 return nil
111116}
112117
113- func resourceShellScriptUpdate (d * schema.ResourceData , meta interface {}) error {
118+ func resourceShellScriptUpdate (d * schema.ResourceData , meta interface {}) (err error ) {
119+ if d .HasChange ("lifecycle_commands.0.read" ) {
120+ err = read (d , meta , []Action {ActionUpdate })
121+ if err != nil {
122+ _ = restoreOldResourceData (d )
123+ }
124+ return
125+ }
126+
127+ if d .HasChanges ("lifecycle_commands" , "interpreter" ) {
128+ return
129+ }
130+
114131 return update (d , meta , []Action {ActionUpdate })
115132}
116133
@@ -124,6 +141,18 @@ func resourceShellScriptCustomizeDiff(d *schema.ResourceDiff, i interface{}) (er
124141 }
125142
126143 if d .HasChange ("lifecycle_commands" ) || d .HasChange ("interpreter" ) {
144+ for _ , k := range []string {
145+ "environment" , "sensitive_environment" , "working_directory" } {
146+
147+ if d .HasChange (k ) {
148+ return fmt .Errorf ("changes to `lifecycle_commands` and/or `interpreter`" +
149+ " should not be follwed by changes to other arguments" )
150+ }
151+ }
152+
153+ if d .HasChange ("lifecycle_commands.0.read" ) {
154+ _ = d .SetNewComputed ("output" ) // assume output will change
155+ }
127156 return
128157 }
129158
@@ -135,16 +164,20 @@ func resourceShellScriptCustomizeDiff(d *schema.ResourceDiff, i interface{}) (er
135164 }
136165
137166 if _ , ok := d .GetOk ("lifecycle_commands.0.update" ); ok {
167+ for _ , k := range []string {
168+ "environment" , "sensitive_environment" , "working_directory" } {
169+
170+ if d .HasChange (k ) {
171+ _ = d .SetNewComputed ("output" ) // assume output will change
172+ }
173+ }
138174 return // updateable
139175 }
140176
141177 // all the other arguments
142178 for _ , k := range []string {
143- "environment" ,
144- "sensitive_environment" ,
145- "working_directory" ,
146- "dirty" ,
147- } {
179+ "environment" , "sensitive_environment" , "working_directory" , "dirty" } {
180+
148181 if ! d .HasChange (k ) {
149182 continue
150183 }
@@ -299,11 +332,6 @@ func restoreOldResourceData(rd *schema.ResourceData, except ...string) (err erro
299332}
300333
301334func update (d * schema.ResourceData , meta interface {}, stack []Action ) error {
302- if d .HasChanges ("lifecycle_commands" , "interpreter" ) {
303- _ = restoreOldResourceData (d , "lifecycle_commands" , "interpreter" , "dirty" , "read_error" )
304- return nil
305- }
306-
307335 log .Printf ("[DEBUG] Updating shell script resource..." )
308336 d .Set ("dirty" , false )
309337 printStackTrace (stack )
0 commit comments