@@ -70,6 +70,16 @@ func ResourceGKEHub2Scope() *schema.Resource {
70
70
Please refer to the field 'effective_labels' for all of the labels present on the resource.` ,
71
71
Elem : & schema.Schema {Type : schema .TypeString },
72
72
},
73
+ "namespace_labels" : {
74
+ Type : schema .TypeMap ,
75
+ Optional : true ,
76
+ Description : `Scope-level cluster namespace labels. For the member clusters bound
77
+ to the Scope, these labels are applied to each namespace under the
78
+ Scope. Scope-level labels take precedence over Namespace-level
79
+ labels ('namespace_labels' in the Fleet Namespace resource) if they
80
+ share a key. Keys and values must be Kubernetes-conformant.` ,
81
+ Elem : & schema.Schema {Type : schema .TypeString },
82
+ },
73
83
"create_time" : {
74
84
Type : schema .TypeString ,
75
85
Computed : true ,
@@ -141,6 +151,12 @@ func resourceGKEHub2ScopeCreate(d *schema.ResourceData, meta interface{}) error
141
151
}
142
152
143
153
obj := make (map [string ]interface {})
154
+ namespaceLabelsProp , err := expandGKEHub2ScopeNamespaceLabels (d .Get ("namespace_labels" ), d , config )
155
+ if err != nil {
156
+ return err
157
+ } else if v , ok := d .GetOkExists ("namespace_labels" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (namespaceLabelsProp )) && (ok || ! reflect .DeepEqual (v , namespaceLabelsProp )) {
158
+ obj ["namespaceLabels" ] = namespaceLabelsProp
159
+ }
144
160
labelsProp , err := expandGKEHub2ScopeEffectiveLabels (d .Get ("effective_labels" ), d , config )
145
161
if err != nil {
146
162
return err
@@ -274,6 +290,9 @@ func resourceGKEHub2ScopeRead(d *schema.ResourceData, meta interface{}) error {
274
290
if err := d .Set ("state" , flattenGKEHub2ScopeState (res ["state" ], d , config )); err != nil {
275
291
return fmt .Errorf ("Error reading Scope: %s" , err )
276
292
}
293
+ if err := d .Set ("namespace_labels" , flattenGKEHub2ScopeNamespaceLabels (res ["namespaceLabels" ], d , config )); err != nil {
294
+ return fmt .Errorf ("Error reading Scope: %s" , err )
295
+ }
277
296
if err := d .Set ("labels" , flattenGKEHub2ScopeLabels (res ["labels" ], d , config )); err != nil {
278
297
return fmt .Errorf ("Error reading Scope: %s" , err )
279
298
}
@@ -303,6 +322,12 @@ func resourceGKEHub2ScopeUpdate(d *schema.ResourceData, meta interface{}) error
303
322
billingProject = project
304
323
305
324
obj := make (map [string ]interface {})
325
+ namespaceLabelsProp , err := expandGKEHub2ScopeNamespaceLabels (d .Get ("namespace_labels" ), d , config )
326
+ if err != nil {
327
+ return err
328
+ } else if v , ok := d .GetOkExists ("namespace_labels" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , namespaceLabelsProp )) {
329
+ obj ["namespaceLabels" ] = namespaceLabelsProp
330
+ }
306
331
labelsProp , err := expandGKEHub2ScopeEffectiveLabels (d .Get ("effective_labels" ), d , config )
307
332
if err != nil {
308
333
return err
@@ -318,6 +343,10 @@ func resourceGKEHub2ScopeUpdate(d *schema.ResourceData, meta interface{}) error
318
343
log .Printf ("[DEBUG] Updating Scope %q: %#v" , d .Id (), obj )
319
344
updateMask := []string {}
320
345
346
+ if d .HasChange ("namespace_labels" ) {
347
+ updateMask = append (updateMask , "namespaceLabels" )
348
+ }
349
+
321
350
if d .HasChange ("effective_labels" ) {
322
351
updateMask = append (updateMask , "labels" )
323
352
}
@@ -473,6 +502,10 @@ func flattenGKEHub2ScopeStateCode(v interface{}, d *schema.ResourceData, config
473
502
return v
474
503
}
475
504
505
+ func flattenGKEHub2ScopeNamespaceLabels (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
506
+ return v
507
+ }
508
+
476
509
func flattenGKEHub2ScopeLabels (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
477
510
if v == nil {
478
511
return v
@@ -507,6 +540,17 @@ func flattenGKEHub2ScopeEffectiveLabels(v interface{}, d *schema.ResourceData, c
507
540
return v
508
541
}
509
542
543
+ func expandGKEHub2ScopeNamespaceLabels (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (map [string ]string , error ) {
544
+ if v == nil {
545
+ return map [string ]string {}, nil
546
+ }
547
+ m := make (map [string ]string )
548
+ for k , val := range v .(map [string ]interface {}) {
549
+ m [k ] = val .(string )
550
+ }
551
+ return m , nil
552
+ }
553
+
510
554
func expandGKEHub2ScopeEffectiveLabels (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (map [string ]string , error ) {
511
555
if v == nil {
512
556
return map [string ]string {}, nil
0 commit comments