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

Fix Hub Membership Import format #12207

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/6341.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
gkehub: added better support for import for `google_gke_hub_membership`
```
14 changes: 8 additions & 6 deletions google/resource_gke_hub_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func resourceGKEHubMembershipCreate(d *schema.ResourceData, meta interface{}) er
}

// Store the ID now
id, err := replaceVars(d, config, "{{name}}")
id, err := replaceVars(d, config, "projects/{{project}}/locations/global/memberships/{{membership_id}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
Expand All @@ -207,7 +207,7 @@ func resourceGKEHubMembershipCreate(d *schema.ResourceData, meta interface{}) er
}

// This may have caused the ID to update - update it if so.
id, err = replaceVars(d, config, "{{name}}")
id, err = replaceVars(d, config, "projects/{{project}}/locations/global/memberships/{{membership_id}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
Expand All @@ -225,7 +225,7 @@ func resourceGKEHubMembershipRead(d *schema.ResourceData, meta interface{}) erro
return err
}

url, err := replaceVars(d, config, "{{GKEHubBasePath}}{{name}}")
url, err := replaceVars(d, config, "{{GKEHubBasePath}}projects/{{project}}/locations/global/memberships/{{membership_id}}")
if err != nil {
return err
}
Expand Down Expand Up @@ -358,7 +358,7 @@ func resourceGKEHubMembershipDelete(d *schema.ResourceData, meta interface{}) er
}
billingProject = project

url, err := replaceVars(d, config, "{{GKEHubBasePath}}{{name}}")
url, err := replaceVars(d, config, "{{GKEHubBasePath}}projects/{{project}}/locations/global/memberships/{{membership_id}}")
if err != nil {
return err
}
Expand Down Expand Up @@ -391,13 +391,15 @@ func resourceGKEHubMembershipDelete(d *schema.ResourceData, meta interface{}) er
func resourceGKEHubMembershipImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*Config)
if err := parseImportId([]string{
"(?P<name>.+)",
"projects/(?P<project>[^/]+)/locations/global/memberships/(?P<membership_id>[^/]+)",
"(?P<project>[^/]+)/(?P<membership_id>[^/]+)",
"(?P<membership_id>[^/]+)",
}, d, config); err != nil {
return nil, err
}

// Replace import id for the resource id
id, err := replaceVars(d, config, "{{name}}")
id, err := replaceVars(d, config, "projects/{{project}}/locations/global/memberships/{{membership_id}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
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 @@ -130,7 +130,7 @@ func testAccCheckGKEHubMembershipDestroyProducer(t *testing.T) func(s *terraform

config := googleProviderConfig(t)

url, err := replaceVarsForTest(config, rs, "{{GKEHubBasePath}}{{name}}")
url, err := replaceVarsForTest(config, rs, "{{GKEHubBasePath}}projects/{{project}}/locations/global/memberships/{{membership_id}}")
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions website/docs/r/gke_hub_membership.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ The following arguments are supported:

In addition to the arguments listed above, the following computed attributes are exported:

* `id` - an identifier for the resource with format `{{name}}`
* `id` - an identifier for the resource with format `projects/{{project}}/locations/global/memberships/{{membership_id}}`

* `name` -
The unique identifier of the membership.
Expand All @@ -166,7 +166,9 @@ This resource provides the following
Membership can be imported using any of these accepted formats:

```
$ terraform import google_gke_hub_membership.default {{name}}
$ terraform import google_gke_hub_membership.default projects/{{project}}/locations/global/memberships/{{membership_id}}
$ terraform import google_gke_hub_membership.default {{project}}/{{membership_id}}
$ terraform import google_gke_hub_membership.default {{membership_id}}
```

## User Project Overrides
Expand Down