Skip to content

Commit

Permalink
Allow google_container_cluster.id reference for the value for the g…
Browse files Browse the repository at this point in the history
…ke_cluster of a `google_gke_hub_membership` (#4985) (#9765)

Co-authored-by: upodroid <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: upodroid <[email protected]>
  • Loading branch information
modular-magician and upodroid authored Aug 10, 2021
1 parent 5afacad commit 50194d2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
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

0 comments on commit 50194d2

Please sign in to comment.