diff --git a/.changelog/4985.txt b/.changelog/4985.txt new file mode 100644 index 00000000000..fb20257e750 --- /dev/null +++ b/.changelog/4985.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +gkehub: `google_gke_hub_membership` supports both `//container.googleapis.com/${google_container_cluster.my-cluster.id}` and `google_container_cluster.my-cluster.id` in `endpoint.0.gke_cluster.0.resource_link` +``` diff --git a/google/resource_gke_hub_membership.go b/google/resource_gke_hub_membership.go index 66c356e156d..e82f2913907 100644 --- a/google/resource_gke_hub_membership.go +++ b/google/resource_gke_hub_membership.go @@ -24,6 +24,16 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) +func suppressGkeHubEndpointSelfLinkDiff(_, old, new string, _ *schema.ResourceData) bool { + // The custom expander injects //container.googleapis.com/ if a selflink is supplied. + selfLink := strings.TrimPrefix(old, "//container.googleapis.com/") + if selfLink == new { + return true + } + + return false +} + func resourceGKEHubMembership() *schema.Resource { return &schema.Resource{ Create: resourceGKEHubMembershipCreate, @@ -83,13 +93,15 @@ with length <2000 characters. For example: 'https://container.googleapis.com/v1/ Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "resource_link": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: suppressGkeHubEndpointSelfLinkDiff, Description: `Self-link of the GCP resource for the GKE cluster. For example: '//container.googleapis.com/projects/my-project/zones/us-west1-a/clusters/my-cluster'. It can be at the most 1000 characters in length. If the cluster is provisioned with Terraform, -this is '"//container.googleapis.com/${google_container_cluster.my-cluster.id}"'.`, +this can be '"//container.googleapis.com/${google_container_cluster.my-cluster.id}"' or +'google_container_cluster.my-cluster.id'.`, }, }, }, @@ -498,7 +510,12 @@ func expandGKEHubMembershipEndpointGkeCluster(v interface{}, d TerraformResource } func expandGKEHubMembershipEndpointGkeClusterResourceLink(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { - return v, nil + if strings.HasPrefix(v.(string), "//container.googleapis.com/") { + return v, nil + } else { + v = "//container.googleapis.com/" + v.(string) + return v, nil + } } func expandGKEHubMembershipAuthority(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { diff --git a/google/resource_gke_hub_membership_generated_test.go b/google/resource_gke_hub_membership_generated_test.go index c89254291ee..a62e2f59b33 100644 --- a/google/resource_gke_hub_membership_generated_test.go +++ b/google/resource_gke_hub_membership_generated_test.go @@ -108,7 +108,7 @@ resource "google_gke_hub_membership" "membership" { membership_id = "basic%{random_suffix}" endpoint { gke_cluster { - resource_link = "//container.googleapis.com/${google_container_cluster.primary.id}" + resource_link = google_container_cluster.primary.id } } authority { diff --git a/website/docs/r/gke_hub_membership.html.markdown b/website/docs/r/gke_hub_membership.html.markdown index 3d6db4ca47f..17481776386 100644 --- a/website/docs/r/gke_hub_membership.html.markdown +++ b/website/docs/r/gke_hub_membership.html.markdown @@ -72,7 +72,7 @@ resource "google_gke_hub_membership" "membership" { membership_id = "basic" endpoint { gke_cluster { - resource_link = "//container.googleapis.com/${google_container_cluster.primary.id}" + resource_link = google_container_cluster.primary.id } } authority { @@ -133,7 +133,8 @@ The `gke_cluster` block supports: Self-link of the GCP resource for the GKE cluster. For example: `//container.googleapis.com/projects/my-project/zones/us-west1-a/clusters/my-cluster`. It can be at the most 1000 characters in length. If the cluster is provisioned with Terraform, - this is `"//container.googleapis.com/${google_container_cluster.my-cluster.id}"`. + this can be `"//container.googleapis.com/${google_container_cluster.my-cluster.id}"` or + `google_container_cluster.my-cluster.id`. The `authority` block supports: