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

Allow google_container_cluster.id reference for the value for the gke_cluster of a google_gke_hub_membership #9765

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/4985.txt
Original file line number Diff line number Diff line change
@@ -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`
```
27 changes: 22 additions & 5 deletions google/resource_gke_hub_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'.`,
},
},
},
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion google/resource_gke_hub_membership_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions website/docs/r/gke_hub_membership.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:

Expand Down