Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add labels field to the GKEHub Membership Binding resource #6216

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/8880.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
GKEHUB: added `labels` fields to `google_gke_hub_membership_binding` resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func ResourceGKEHub2MembershipBinding() *schema.Resource {
Description: `A Workspace resource name in the format
'projects/*/locations/*/scopes/*'.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Labels for this Membership binding.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -137,6 +143,12 @@ func resourceGKEHub2MembershipBindingCreate(d *schema.ResourceData, meta interfa
} else if v, ok := d.GetOkExists("scope"); !tpgresource.IsEmptyValue(reflect.ValueOf(scopeProp)) && (ok || !reflect.DeepEqual(v, scopeProp)) {
obj["scope"] = scopeProp
}
labelsProp, err := expandGKEHub2MembershipBindingLabels(d.Get("labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{GKEHub2BasePath}}projects/{{project}}/locations/{{location}}/memberships/{{membership_id}}/bindings/?membership_binding_id={{membership_binding_id}}")
if err != nil {
Expand Down Expand Up @@ -267,6 +279,9 @@ func resourceGKEHub2MembershipBindingRead(d *schema.ResourceData, meta interface
if err := d.Set("state", flattenGKEHub2MembershipBindingState(res["state"], d, config)); err != nil {
return fmt.Errorf("Error reading MembershipBinding: %s", err)
}
if err := d.Set("labels", flattenGKEHub2MembershipBindingLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading MembershipBinding: %s", err)
}

return nil
}
Expand All @@ -293,6 +308,12 @@ func resourceGKEHub2MembershipBindingUpdate(d *schema.ResourceData, meta interfa
} else if v, ok := d.GetOkExists("scope"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, scopeProp)) {
obj["scope"] = scopeProp
}
labelsProp, err := expandGKEHub2MembershipBindingLabels(d.Get("labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{GKEHub2BasePath}}projects/{{project}}/locations/{{location}}/memberships/{{membership_id}}/bindings/{{membership_binding_id}}")
if err != nil {
Expand All @@ -305,6 +326,10 @@ func resourceGKEHub2MembershipBindingUpdate(d *schema.ResourceData, meta interfa
if d.HasChange("scope") {
updateMask = append(updateMask, "scope")
}

if d.HasChange("labels") {
updateMask = append(updateMask, "labels")
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down Expand Up @@ -461,6 +486,21 @@ func flattenGKEHub2MembershipBindingStateCode(v interface{}, d *schema.ResourceD
return v
}

func flattenGKEHub2MembershipBindingLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func expandGKEHub2MembershipBindingScope(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandGKEHub2MembershipBindingLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ resource "google_gke_hub_membership_binding" "example" {
scope = google_gke_hub_scope.example.name
membership_id = "tf-test-membership%{random_suffix}"
location = "global"
labels = {
keyb = "valueb"
keya = "valuea"
keyc = "valuec"
}
depends_on = [
google_gke_hub_membership.example,
google_gke_hub_scope.example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ resource "google_gke_hub_membership_binding" "example" {
scope = google_gke_hub_scope.example.name
membership_id = "tf-test-membership%{random_suffix}"
location = "global"
labels = {
keyb = "valueb"
keya = "valuea"
keyc = "valuec"
}
depends_on = [
google_gke_hub_membership.example,
google_gke_hub_scope.example
Expand Down Expand Up @@ -110,6 +115,11 @@ resource "google_gke_hub_membership_binding" "example" {
scope = google_gke_hub_scope.example2.name
membership_id = "tf-test-membership%{random_suffix}"
location = "global"
labels = {
updated_keyb = "updated_valueb"
updated_keya = "updated_valuea"
updated_keyc = "updated_valuec"
}
depends_on = [
google_gke_hub_membership.example,
google_gke_hub_scope.example2
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/gke_hub_membership_binding.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ resource "google_gke_hub_membership_binding" "example" {
scope = google_gke_hub_scope.example.name
membership_id = "tf-test-membership%{random_suffix}"
location = "global"
labels = {
keyb = "valueb"
keya = "valuea"
keyc = "valuec"
}
depends_on = [
google_gke_hub_membership.example,
google_gke_hub_scope.example
Expand Down Expand Up @@ -91,6 +96,10 @@ The following arguments are supported:
- - -


* `labels` -
(Optional)
Labels for this Membership binding.

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand Down
Loading