@@ -640,6 +640,24 @@ Please refer to the field 'effective_labels' for all of the labels present on th
640640 },
641641 },
642642 },
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+ },
643661 },
644662 },
645663 },
@@ -781,6 +799,31 @@ func resourceGKEHub2FeatureCreate(d *schema.ResourceData, meta interface{}) erro
781799 }
782800
783801 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+ }
784827 res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
785828 Config : config ,
786829 Method : "POST" ,
@@ -1019,6 +1062,61 @@ func resourceGKEHub2FeatureDelete(d *schema.ResourceData, meta interface{}) erro
10191062 }
10201063
10211064 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+ }
10221120
10231121 log .Printf ("[DEBUG] Deleting Feature %q" , d .Id ())
10241122 res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
@@ -1120,6 +1218,8 @@ func flattenGKEHub2FeatureSpec(v interface{}, d *schema.ResourceData, config *tr
11201218 flattenGKEHub2FeatureSpecFleetobservability (original ["fleetobservability" ], d , config )
11211219 transformed ["clusterupgrade" ] =
11221220 flattenGKEHub2FeatureSpecClusterupgrade (original ["clusterupgrade" ], d , config )
1221+ transformed ["rbacrolebindingactuation" ] =
1222+ flattenGKEHub2FeatureSpecRbacrolebindingactuation (original ["rbacrolebindingactuation" ], d , config )
11231223 return []interface {}{transformed }
11241224}
11251225func flattenGKEHub2FeatureSpecMulticlusteringress (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
@@ -1298,6 +1398,23 @@ func flattenGKEHub2FeatureSpecClusterupgradeGkeUpgradeOverridesPostConditionsSoa
12981398 return v
12991399}
13001400
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+
13011418func flattenGKEHub2FeatureFleetDefaultMemberConfig (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
13021419 if v == nil {
13031420 return nil
@@ -1914,6 +2031,13 @@ func expandGKEHub2FeatureSpec(v interface{}, d tpgresource.TerraformResourceData
19142031 transformed ["clusterupgrade" ] = transformedClusterupgrade
19152032 }
19162033
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+
19172041 return transformed , nil
19182042}
19192043
@@ -2177,6 +2301,29 @@ func expandGKEHub2FeatureSpecClusterupgradeGkeUpgradeOverridesPostConditionsSoak
21772301 return v , nil
21782302}
21792303
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+
21802327func expandGKEHub2FeatureFleetDefaultMemberConfig (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
21812328 l := v .([]interface {})
21822329 if len (l ) == 0 || l [0 ] == nil {
0 commit comments