Skip to content

Commit 61ee872

Browse files
Allow google_container_cluster.id reference for the value for the gke_cluster of a google_gke_hub_membership (#4985) (#3502)
Co-authored-by: upodroid <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: upodroid <[email protected]>
1 parent 97b8e82 commit 61ee872

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

.changelog/4985.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
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`
3+
```

google-beta/resource_gke_hub_feature_membership_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"testing"
77

8-
"github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
8+
dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
99
gkehub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

google-beta/resource_gke_hub_membership.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ import (
2424
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2525
)
2626

27+
func suppressGkeHubEndpointSelfLinkDiff(_, old, new string, _ *schema.ResourceData) bool {
28+
// The custom expander injects //container.googleapis.com/ if a selflink is supplied.
29+
selfLink := strings.TrimPrefix(old, "//container.googleapis.com/")
30+
if selfLink == new {
31+
return true
32+
}
33+
34+
return false
35+
}
36+
2737
func resourceGKEHubMembership() *schema.Resource {
2838
return &schema.Resource{
2939
Create: resourceGKEHubMembershipCreate,
@@ -89,13 +99,15 @@ with length <2000 characters. For example: 'https://container.googleapis.com/v1/
8999
Elem: &schema.Resource{
90100
Schema: map[string]*schema.Schema{
91101
"resource_link": {
92-
Type: schema.TypeString,
93-
Required: true,
94-
ForceNew: true,
102+
Type: schema.TypeString,
103+
Required: true,
104+
ForceNew: true,
105+
DiffSuppressFunc: suppressGkeHubEndpointSelfLinkDiff,
95106
Description: `Self-link of the GCP resource for the GKE cluster.
96107
For example: '//container.googleapis.com/projects/my-project/zones/us-west1-a/clusters/my-cluster'.
97108
It can be at the most 1000 characters in length. If the cluster is provisioned with Terraform,
98-
this is '"//container.googleapis.com/${google_container_cluster.my-cluster.id}"'.`,
109+
this can be '"//container.googleapis.com/${google_container_cluster.my-cluster.id}"' or
110+
'google_container_cluster.my-cluster.id'.`,
99111
},
100112
},
101113
},
@@ -531,7 +543,12 @@ func expandGKEHubMembershipEndpointGkeCluster(v interface{}, d TerraformResource
531543
}
532544

533545
func expandGKEHubMembershipEndpointGkeClusterResourceLink(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
534-
return v, nil
546+
if strings.HasPrefix(v.(string), "//container.googleapis.com/") {
547+
return v, nil
548+
} else {
549+
v = "//container.googleapis.com/" + v.(string)
550+
return v, nil
551+
}
535552
}
536553

537554
func expandGKEHubMembershipAuthority(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {

google-beta/resource_gke_hub_membership_generated_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ resource "google_gke_hub_membership" "membership" {
108108
membership_id = "basic%{random_suffix}"
109109
endpoint {
110110
gke_cluster {
111-
resource_link = "//container.googleapis.com/${google_container_cluster.primary.id}"
111+
resource_link = google_container_cluster.primary.id
112112
}
113113
}
114114
authority {

website/docs/r/gke_hub_membership.html.markdown

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ resource "google_gke_hub_membership" "membership" {
7272
membership_id = "basic"
7373
endpoint {
7474
gke_cluster {
75-
resource_link = "//container.googleapis.com/${google_container_cluster.primary.id}"
75+
resource_link = google_container_cluster.primary.id
7676
}
7777
}
7878
authority {
@@ -133,7 +133,8 @@ The `gke_cluster` block supports:
133133
Self-link of the GCP resource for the GKE cluster.
134134
For example: `//container.googleapis.com/projects/my-project/zones/us-west1-a/clusters/my-cluster`.
135135
It can be at the most 1000 characters in length. If the cluster is provisioned with Terraform,
136-
this is `"//container.googleapis.com/${google_container_cluster.my-cluster.id}"`.
136+
this can be `"//container.googleapis.com/${google_container_cluster.my-cluster.id}"` or
137+
`google_container_cluster.my-cluster.id`.
137138

138139
The `authority` block supports:
139140

0 commit comments

Comments
 (0)