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

Add two output-only fields (membership_id, membership_location) under google_container_cluster.fleet #6983

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/9974.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
container: added output-only fields `membership_id` and `membership_location` under `fleet` in `google_container_cluster` resource
```
27 changes: 24 additions & 3 deletions google-beta/services/container/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2048,6 +2048,16 @@ func ResourceContainerCluster() *schema.Resource {
Computed: true,
Description: `Whether the cluster has been registered via the fleet API.`,
},
"membership_id": {
Type: schema.TypeString,
Computed: true,
Description: `Short name of the fleet membership, for example "member-1".`,
},
"membership_location": {
Type: schema.TypeString,
Computed: true,
Description: `Location of the fleet membership, for example "us-central1".`,
},
},
},
},
Expand Down Expand Up @@ -6025,11 +6035,22 @@ func flattenFleet(c *container.Fleet) []map[string]interface{} {
if c == nil {
return nil
}

// Parse membership_id and membership_location from full membership name.
var membership_id, membership_location string
membershipRE := regexp.MustCompile(`^(//[a-zA-Z0-9\.\-]+)?/?projects/([^/]+)/locations/([a-zA-Z0-9\-]+)/memberships/([^/]+)$`)
if match := membershipRE.FindStringSubmatch(c.Membership); match != nil {
membership_id = match[4]
membership_location = match[3]
}

return []map[string]interface{}{
{
"project": c.Project,
"membership": c.Membership,
"pre_registered": c.PreRegistered,
"project": c.Project,
"membership": c.Membership,
"membership_id": membership_id,
"membership_location": membership_location,
"pre_registered": c.PreRegistered,
},
}
}
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,10 @@ exported:

* `fleet.0.membership` - The resource name of the fleet Membership resource associated to this cluster with format `//gkehub.googleapis.com/projects/{{project}}/locations/{{location}}/memberships/{{name}}`. See the official doc for [fleet management](https://cloud.google.com/kubernetes-engine/docs/fleets-overview).

* `fleet.0.membership_id` - The short name of the fleet membership, extracted from `fleet.0.membership`. You can use this field to configure `membership_id` under [google_gkehub_feature_membership](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/gke_hub_feature_membership).

* `fleet.0.membership_location` - The location of the fleet membership, extracted from `fleet.0.membership`. You can use this field to configure `membership_location` under [google_gkehub_feature_membership](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/gke_hub_feature_membership).

## Timeouts

This resource provides the following
Expand Down
Loading