@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
"log"
23
23
"reflect"
24
+ "strings"
24
25
"time"
25
26
26
27
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
@@ -850,24 +851,12 @@ func resourceEdgecontainerClusterUpdate(d *schema.ResourceData, meta interface{}
850
851
billingProject = project
851
852
852
853
obj := make (map [string ]interface {})
853
- fleetProp , err := expandEdgecontainerClusterFleet (d .Get ("fleet" ), d , config )
854
- if err != nil {
855
- return err
856
- } else if v , ok := d .GetOkExists ("fleet" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , fleetProp )) {
857
- obj ["fleet" ] = fleetProp
858
- }
859
854
networkingProp , err := expandEdgecontainerClusterNetworking (d .Get ("networking" ), d , config )
860
855
if err != nil {
861
856
return err
862
857
} else if v , ok := d .GetOkExists ("networking" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , networkingProp )) {
863
858
obj ["networking" ] = networkingProp
864
859
}
865
- authorizationProp , err := expandEdgecontainerClusterAuthorization (d .Get ("authorization" ), d , config )
866
- if err != nil {
867
- return err
868
- } else if v , ok := d .GetOkExists ("authorization" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , authorizationProp )) {
869
- obj ["authorization" ] = authorizationProp
870
- }
871
860
defaultMaxPodsPerNodeProp , err := expandEdgecontainerClusterDefaultMaxPodsPerNode (d .Get ("default_max_pods_per_node" ), d , config )
872
861
if err != nil {
873
862
return err
@@ -923,35 +912,81 @@ func resourceEdgecontainerClusterUpdate(d *schema.ResourceData, meta interface{}
923
912
}
924
913
925
914
log .Printf ("[DEBUG] Updating Cluster %q: %#v" , d .Id (), obj )
915
+ updateMask := []string {}
926
916
927
- // err == nil indicates that the billing_project value was found
928
- if bp , err := tpgresource .GetBillingProject (d , config ); err == nil {
929
- billingProject = bp
917
+ if d .HasChange ("networking" ) {
918
+ updateMask = append (updateMask , "networking" )
930
919
}
931
920
932
- res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
933
- Config : config ,
934
- Method : "PUT" ,
935
- Project : billingProject ,
936
- RawURL : url ,
937
- UserAgent : userAgent ,
938
- Body : obj ,
939
- Timeout : d .Timeout (schema .TimeoutUpdate ),
940
- })
921
+ if d .HasChange ("default_max_pods_per_node" ) {
922
+ updateMask = append (updateMask , "defaultMaxPodsPerNode" )
923
+ }
941
924
942
- if err != nil {
943
- return fmt .Errorf ("Error updating Cluster %q: %s" , d .Id (), err )
944
- } else {
945
- log .Printf ("[DEBUG] Finished updating Cluster %q: %#v" , d .Id (), res )
925
+ if d .HasChange ("maintenance_policy" ) {
926
+ updateMask = append (updateMask , "maintenancePolicy" )
946
927
}
947
928
948
- err = EdgecontainerOperationWaitTime (
949
- config , res , project , "Updating Cluster" , userAgent ,
950
- d .Timeout (schema .TimeoutUpdate ))
929
+ if d .HasChange ("control_plane" ) {
930
+ updateMask = append (updateMask , "controlPlane" )
931
+ }
932
+
933
+ if d .HasChange ("system_addons_config" ) {
934
+ updateMask = append (updateMask , "systemAddonsConfig" )
935
+ }
936
+
937
+ if d .HasChange ("external_load_balancer_ipv4_address_pools" ) {
938
+ updateMask = append (updateMask , "externalLoadBalancerIpv4AddressPools" )
939
+ }
940
+
941
+ if d .HasChange ("control_plane_encryption" ) {
942
+ updateMask = append (updateMask , "controlPlaneEncryption" )
943
+ }
944
+
945
+ if d .HasChange ("release_channel" ) {
946
+ updateMask = append (updateMask , "releaseChannel" )
947
+ }
951
948
949
+ if d .HasChange ("effective_labels" ) {
950
+ updateMask = append (updateMask , "labels" )
951
+ }
952
+ // updateMask is a URL parameter but not present in the schema, so ReplaceVars
953
+ // won't set it
954
+ url , err = transport_tpg .AddQueryParams (url , map [string ]string {"updateMask" : strings .Join (updateMask , "," )})
952
955
if err != nil {
953
956
return err
954
957
}
958
+
959
+ // err == nil indicates that the billing_project value was found
960
+ if bp , err := tpgresource .GetBillingProject (d , config ); err == nil {
961
+ billingProject = bp
962
+ }
963
+
964
+ // if updateMask is empty we are not updating anything so skip the post
965
+ if len (updateMask ) > 0 {
966
+ res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
967
+ Config : config ,
968
+ Method : "PATCH" ,
969
+ Project : billingProject ,
970
+ RawURL : url ,
971
+ UserAgent : userAgent ,
972
+ Body : obj ,
973
+ Timeout : d .Timeout (schema .TimeoutUpdate ),
974
+ })
975
+
976
+ if err != nil {
977
+ return fmt .Errorf ("Error updating Cluster %q: %s" , d .Id (), err )
978
+ } else {
979
+ log .Printf ("[DEBUG] Finished updating Cluster %q: %#v" , d .Id (), res )
980
+ }
981
+
982
+ err = EdgecontainerOperationWaitTime (
983
+ config , res , project , "Updating Cluster" , userAgent ,
984
+ d .Timeout (schema .TimeoutUpdate ))
985
+
986
+ if err != nil {
987
+ return err
988
+ }
989
+ }
955
990
d .Partial (true )
956
991
957
992
if d .HasChange ("target_version" ) {
0 commit comments