From b801869a79e1eabc37974c3f5a59dab0b828491e Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Fri, 29 Jul 2022 17:34:09 +0000 Subject: [PATCH] Fix Hub Membership Import format (#6341) Signed-off-by: Modular Magician --- .changelog/6341.txt | 3 +++ google/resource_gke_hub_membership.go | 14 ++++++++------ .../resource_gke_hub_membership_generated_test.go | 2 +- website/docs/r/gke_hub_membership.html.markdown | 6 ++++-- 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 .changelog/6341.txt diff --git a/.changelog/6341.txt b/.changelog/6341.txt new file mode 100644 index 00000000000..ccd9e48bcc0 --- /dev/null +++ b/.changelog/6341.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +gkehub: added better support for import for `google_gke_hub_membership` +``` diff --git a/google/resource_gke_hub_membership.go b/google/resource_gke_hub_membership.go index 2bc47722f61..851158c70f5 100644 --- a/google/resource_gke_hub_membership.go +++ b/google/resource_gke_hub_membership.go @@ -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) } @@ -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) } @@ -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 } @@ -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 } @@ -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.+)", + "projects/(?P[^/]+)/locations/global/memberships/(?P[^/]+)", + "(?P[^/]+)/(?P[^/]+)", + "(?P[^/]+)", }, 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) } diff --git a/google/resource_gke_hub_membership_generated_test.go b/google/resource_gke_hub_membership_generated_test.go index 208211f47da..a3a227d1e15 100644 --- a/google/resource_gke_hub_membership_generated_test.go +++ b/google/resource_gke_hub_membership_generated_test.go @@ -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 } diff --git a/website/docs/r/gke_hub_membership.html.markdown b/website/docs/r/gke_hub_membership.html.markdown index 804ef4e4c64..4d7d41e3a5b 100644 --- a/website/docs/r/gke_hub_membership.html.markdown +++ b/website/docs/r/gke_hub_membership.html.markdown @@ -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. @@ -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