@@ -159,11 +159,11 @@ func planSetResource(subcommand string, rctx ResourceContext) PlanResult {
159159 return PlanResult {Status : PlanStatusError , Error : err }
160160 }
161161
162- for k := range rctx .Resources {
162+ for _ , k := range sortedResourceKeys ( rctx .Resources ) {
163163 if _ , ok := currentResources [k ]; ! ok {
164164 return PlanResult {
165165 Status : PlanStatusError ,
166- Error : fmt .Errorf ("unknown resource %s, valid resources: %v" , k , mapKeys (currentResources )),
166+ Error : fmt .Errorf ("unknown resource %s, valid resources: %v" , k , sortedResourceKeys (currentResources )),
167167 }
168168 }
169169 }
@@ -180,7 +180,8 @@ func planSetResource(subcommand string, rctx ResourceContext) PlanResult {
180180 if effective .ClearBefore {
181181 mutations = append (mutations , "clear before set" )
182182 }
183- for k , v := range rctx .Resources {
183+ for _ , k := range sortedResourceKeys (rctx .Resources ) {
184+ v := rctx .Resources [k ]
184185 if currentResources [k ] != v {
185186 mutations = append (mutations , fmt .Sprintf ("set %s=%s (was %q)" , k , v , currentResources [k ]))
186187 }
@@ -269,8 +270,8 @@ func resourceSetInputs(subcommand string, rctx ResourceContext) []subprocess.Exe
269270 inputs = append (inputs , resourceClearInput (subcommand , rctx ))
270271 }
271272 args := []string {subcommand }
272- for key , value := range rctx .Resources {
273- args = append (args , fmt .Sprintf ("--%s" , key ), value )
273+ for _ , key := range sortedResourceKeys ( rctx .Resources ) {
274+ args = append (args , fmt .Sprintf ("--%s" , key ), rctx . Resources [ key ] )
274275 }
275276 if rctx .ProcessType != "" {
276277 args = append (args , "--process-type" , rctx .ProcessType )
@@ -306,3 +307,11 @@ func mapKeys(m map[string]string) []string {
306307 }
307308 return keys
308309}
310+
311+ // sortedResourceKeys returns the resource keys in deterministic (sorted) order so
312+ // plan and apply build byte-identical command args and mutation lists (issue #341).
313+ func sortedResourceKeys (m map [string ]string ) []string {
314+ keys := mapKeys (m )
315+ sort .Strings (keys )
316+ return keys
317+ }
0 commit comments