From c65ddb58094f5cc712076e5493ca56f90bdc0f10 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 11 Sep 2023 17:00:26 -0400 Subject: [PATCH] Add labels field to the GKEHub Scope resource and make it updatable (#8882) (#1412) * Adding Terraform resources for Tenancy APIs in GKEHub * Segregating MembershipBinding and MembershipRBACRoleBinding to keep things simpler in the review * Fixing the docu URIs * Adding TF support for Tenancy API for Membership Binding * Adding dependent membership binding to the same commit chain * Making Scope un-updatable and replacing hard coded project number with the one from test env * Making Scope RRBAC updatable * Making Namespace immutable * Adding update test cases * Removing all memberships field from Scope since it is no longer supported * Removing all_memberships field for Scope from all test cases * Adding labels field to the GKEHub Scope resource * Fixing typo in the comment Signed-off-by: Modular Magician --- .../services/gkehub2/gkehub2_scope.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tfplan2cai/converters/google/resources/services/gkehub2/gkehub2_scope.go b/tfplan2cai/converters/google/resources/services/gkehub2/gkehub2_scope.go index c63f7a32a..0e9240c4b 100644 --- a/tfplan2cai/converters/google/resources/services/gkehub2/gkehub2_scope.go +++ b/tfplan2cai/converters/google/resources/services/gkehub2/gkehub2_scope.go @@ -15,6 +15,8 @@ package gkehub2 import ( + "reflect" + "github.com/GoogleCloudPlatform/terraform-google-conversion/v2/tfplan2cai/converters/google/resources/cai" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" @@ -52,6 +54,23 @@ func GetGKEHub2ScopeCaiObject(d tpgresource.TerraformResourceData, config *trans func GetGKEHub2ScopeApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { obj := make(map[string]interface{}) + labelsProp, err := expandGKEHub2ScopeLabels(d.Get("labels"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { + obj["labels"] = labelsProp + } return obj, nil } + +func expandGKEHub2ScopeLabels(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 +}