@@ -640,6 +640,24 @@ Please refer to the field 'effective_labels' for all of the labels present on th
640
640
},
641
641
},
642
642
},
643
+ "rbacrolebindingactuation" : {
644
+ Type : schema .TypeList ,
645
+ Optional : true ,
646
+ Description : `RBACRolebinding Actuation feature spec.` ,
647
+ MaxItems : 1 ,
648
+ Elem : & schema.Resource {
649
+ Schema : map [string ]* schema.Schema {
650
+ "allowed_custom_roles" : {
651
+ Type : schema .TypeList ,
652
+ Optional : true ,
653
+ Description : `The list of allowed custom roles (ClusterRoles). If a custom role is not part of this list, it cannot be used in a fleet scope RBACRoleBinding. If a custom role in this list is in use, it cannot be removed from the list until the scope RBACRolebindings using it are deleted.` ,
654
+ Elem : & schema.Schema {
655
+ Type : schema .TypeString ,
656
+ },
657
+ },
658
+ },
659
+ },
660
+ },
643
661
},
644
662
},
645
663
},
@@ -781,6 +799,31 @@ func resourceGKEHub2FeatureCreate(d *schema.ResourceData, meta interface{}) erro
781
799
}
782
800
783
801
headers := make (http.Header )
802
+ // Check if the fleet feature already exists. Do an update if so.
803
+
804
+ getUrl , err := tpgresource .ReplaceVars (d , config , "{{GKEHub2BasePath}}projects/{{project}}/locations/{{location}}/features/{{name}}" )
805
+ if err != nil {
806
+ return err
807
+ }
808
+ _ , err = transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
809
+ Config : config ,
810
+ Method : "GET" ,
811
+ Project : billingProject ,
812
+ RawURL : getUrl ,
813
+ UserAgent : userAgent ,
814
+ Headers : headers ,
815
+ })
816
+
817
+ if err == nil {
818
+ // Fleet feature already exists
819
+ log .Printf ("[DEBUG] Fleet feature already exists %s" , d .Get ("name" ))
820
+ id , err := tpgresource .ReplaceVars (d , config , "projects/{{project}}/locations/{{location}}/features/{{name}}" )
821
+ if err != nil {
822
+ return fmt .Errorf ("Error constructing id: %s" , err )
823
+ }
824
+ d .SetId (id )
825
+ return resourceGKEHub2FeatureUpdate (d , meta )
826
+ }
784
827
res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
785
828
Config : config ,
786
829
Method : "POST" ,
@@ -1019,6 +1062,61 @@ func resourceGKEHub2FeatureDelete(d *schema.ResourceData, meta interface{}) erro
1019
1062
}
1020
1063
1021
1064
headers := make (http.Header )
1065
+ // Special handling for the mandatory 'rbacrolebindingactuation' feature.
1066
+ // Instead of deleting it, we reset it to a default state by sending a PATCH request.
1067
+ if d .Get ("name" ).(string ) == "rbacrolebindingactuation" {
1068
+ log .Printf ("[DEBUG] Mandatory feature 'rbacrolebindingactuation' detected. Resetting instead of deleting." )
1069
+
1070
+ patchUrl , err := tpgresource .ReplaceVarsForId (d , config , "{{GKEHub2BasePath}}projects/{{project}}/locations/{{location}}/features/{{name}}" )
1071
+ if err != nil {
1072
+ return err
1073
+ }
1074
+
1075
+ // Construct the request body to clear the desired field.
1076
+ obj := map [string ]interface {}{
1077
+ "spec" : map [string ]interface {}{
1078
+ "rbacrolebindingactuation" : map [string ]interface {}{
1079
+ "allowedCustomRoles" : []string {},
1080
+ },
1081
+ },
1082
+ }
1083
+
1084
+ // A specific updateMask is required for a PATCH request.
1085
+ updateMask := "spec.rbacrolebindingactuation.allowedCustomRoles"
1086
+ url , err := transport_tpg .AddQueryParams (patchUrl , map [string ]string {"updateMask" : updateMask })
1087
+ if err != nil {
1088
+ return err
1089
+ }
1090
+
1091
+ log .Printf ("[DEBUG] Sending PATCH to reset Feature %q: %#v" , d .Id (), obj )
1092
+
1093
+ // Send the raw PATCH request.
1094
+ res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
1095
+ Config : config ,
1096
+ Method : "PATCH" ,
1097
+ Project : billingProject ,
1098
+ RawURL : url ,
1099
+ UserAgent : userAgent ,
1100
+ Body : obj ,
1101
+ Timeout : d .Timeout (schema .TimeoutDelete ), // Use the delete timeout for this reset operation.
1102
+ Headers : headers ,
1103
+ })
1104
+ if err != nil {
1105
+ return fmt .Errorf ("error resetting Feature %q: %s" , d .Id (), err )
1106
+ }
1107
+
1108
+ // Wait for the long-running operation to complete.
1109
+ err = GKEHub2OperationWaitTime (
1110
+ config , res , tpgresource .GetResourceNameFromSelfLink (project ), "Resetting Feature" , userAgent ,
1111
+ d .Timeout (schema .TimeoutDelete ))
1112
+
1113
+ if err != nil {
1114
+ return fmt .Errorf ("error waiting to reset Feature %q: %s" , d .Id (), err )
1115
+ }
1116
+
1117
+ log .Printf ("[DEBUG] Finished resetting Feature %q" , d .Id ())
1118
+ return nil
1119
+ }
1022
1120
1023
1121
log .Printf ("[DEBUG] Deleting Feature %q" , d .Id ())
1024
1122
res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
@@ -1120,6 +1218,8 @@ func flattenGKEHub2FeatureSpec(v interface{}, d *schema.ResourceData, config *tr
1120
1218
flattenGKEHub2FeatureSpecFleetobservability (original ["fleetobservability" ], d , config )
1121
1219
transformed ["clusterupgrade" ] =
1122
1220
flattenGKEHub2FeatureSpecClusterupgrade (original ["clusterupgrade" ], d , config )
1221
+ transformed ["rbacrolebindingactuation" ] =
1222
+ flattenGKEHub2FeatureSpecRbacrolebindingactuation (original ["rbacrolebindingactuation" ], d , config )
1123
1223
return []interface {}{transformed }
1124
1224
}
1125
1225
func flattenGKEHub2FeatureSpecMulticlusteringress (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
@@ -1298,6 +1398,23 @@ func flattenGKEHub2FeatureSpecClusterupgradeGkeUpgradeOverridesPostConditionsSoa
1298
1398
return v
1299
1399
}
1300
1400
1401
+ func flattenGKEHub2FeatureSpecRbacrolebindingactuation (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1402
+ if v == nil {
1403
+ return nil
1404
+ }
1405
+ original := v .(map [string ]interface {})
1406
+ if len (original ) == 0 {
1407
+ return nil
1408
+ }
1409
+ transformed := make (map [string ]interface {})
1410
+ transformed ["allowed_custom_roles" ] =
1411
+ flattenGKEHub2FeatureSpecRbacrolebindingactuationAllowedCustomRoles (original ["allowedCustomRoles" ], d , config )
1412
+ return []interface {}{transformed }
1413
+ }
1414
+ func flattenGKEHub2FeatureSpecRbacrolebindingactuationAllowedCustomRoles (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1415
+ return v
1416
+ }
1417
+
1301
1418
func flattenGKEHub2FeatureFleetDefaultMemberConfig (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1302
1419
if v == nil {
1303
1420
return nil
@@ -1914,6 +2031,13 @@ func expandGKEHub2FeatureSpec(v interface{}, d tpgresource.TerraformResourceData
1914
2031
transformed ["clusterupgrade" ] = transformedClusterupgrade
1915
2032
}
1916
2033
2034
+ transformedRbacrolebindingactuation , err := expandGKEHub2FeatureSpecRbacrolebindingactuation (original ["rbacrolebindingactuation" ], d , config )
2035
+ if err != nil {
2036
+ return nil , err
2037
+ } else if val := reflect .ValueOf (transformedRbacrolebindingactuation ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2038
+ transformed ["rbacrolebindingactuation" ] = transformedRbacrolebindingactuation
2039
+ }
2040
+
1917
2041
return transformed , nil
1918
2042
}
1919
2043
@@ -2177,6 +2301,29 @@ func expandGKEHub2FeatureSpecClusterupgradeGkeUpgradeOverridesPostConditionsSoak
2177
2301
return v , nil
2178
2302
}
2179
2303
2304
+ func expandGKEHub2FeatureSpecRbacrolebindingactuation (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2305
+ l := v .([]interface {})
2306
+ if len (l ) == 0 || l [0 ] == nil {
2307
+ return nil , nil
2308
+ }
2309
+ raw := l [0 ]
2310
+ original := raw .(map [string ]interface {})
2311
+ transformed := make (map [string ]interface {})
2312
+
2313
+ transformedAllowedCustomRoles , err := expandGKEHub2FeatureSpecRbacrolebindingactuationAllowedCustomRoles (original ["allowed_custom_roles" ], d , config )
2314
+ if err != nil {
2315
+ return nil , err
2316
+ } else if val := reflect .ValueOf (transformedAllowedCustomRoles ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2317
+ transformed ["allowedCustomRoles" ] = transformedAllowedCustomRoles
2318
+ }
2319
+
2320
+ return transformed , nil
2321
+ }
2322
+
2323
+ func expandGKEHub2FeatureSpecRbacrolebindingactuationAllowedCustomRoles (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2324
+ return v , nil
2325
+ }
2326
+
2180
2327
func expandGKEHub2FeatureFleetDefaultMemberConfig (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2181
2328
l := v .([]interface {})
2182
2329
if len (l ) == 0 || l [0 ] == nil {
0 commit comments