From 9c0bb5a1c67a81f8b1dfc20a661368efbaa90e7a Mon Sep 17 00:00:00 2001 From: ttewari <60916707+ttewari@users.noreply.github.com> Date: Wed, 16 Oct 2024 19:20:54 +0530 Subject: [PATCH] Fix import for google_essential_contacts_contact (#11995) Co-authored-by: Tripti Tewari --- mmv1/products/essentialcontacts/Contact.yaml | 1 + .../post_import/essential_contacts_contact.go.tmpl | 6 ++++++ .../resource_essential_contacts_contact_test.go | 14 ++++++-------- 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 mmv1/templates/terraform/post_import/essential_contacts_contact.go.tmpl diff --git a/mmv1/products/essentialcontacts/Contact.yaml b/mmv1/products/essentialcontacts/Contact.yaml index 18bf18644c9f..db57147cd9de 100644 --- a/mmv1/products/essentialcontacts/Contact.yaml +++ b/mmv1/products/essentialcontacts/Contact.yaml @@ -38,6 +38,7 @@ timeouts: update_minutes: 20 delete_minutes: 20 custom_code: + post_import: 'templates/terraform/post_import/essential_contacts_contact.go.tmpl' examples: - name: 'essential_contact' primary_resource_id: 'contact' diff --git a/mmv1/templates/terraform/post_import/essential_contacts_contact.go.tmpl b/mmv1/templates/terraform/post_import/essential_contacts_contact.go.tmpl new file mode 100644 index 000000000000..a328ba4d4f56 --- /dev/null +++ b/mmv1/templates/terraform/post_import/essential_contacts_contact.go.tmpl @@ -0,0 +1,6 @@ +// Split resource name into tokens +nameTokens := strings.SplitAfterN(d.Id(), "/", 3) + +if err := d.Set("parent", nameTokens[0]+strings.Trim(nameTokens[1], "/")); err != nil { + return nil, fmt.Errorf("error getting parent for the contact : %s", err) +} \ No newline at end of file diff --git a/mmv1/third_party/terraform/services/essentialcontacts/resource_essential_contacts_contact_test.go b/mmv1/third_party/terraform/services/essentialcontacts/resource_essential_contacts_contact_test.go index f31311dabf9b..e1b3c7dfd039 100644 --- a/mmv1/third_party/terraform/services/essentialcontacts/resource_essential_contacts_contact_test.go +++ b/mmv1/third_party/terraform/services/essentialcontacts/resource_essential_contacts_contact_test.go @@ -27,10 +27,9 @@ func TestAccEssentialContactsContact_update(t *testing.T) { ), }, { - ResourceName: "google_essential_contacts_contact.contact", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent"}, + ResourceName: "google_essential_contacts_contact.contact", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccEssentialContactsContact_v2(context), @@ -40,10 +39,9 @@ func TestAccEssentialContactsContact_update(t *testing.T) { ), }, { - ResourceName: "google_essential_contacts_contact.contact", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"parent"}, + ResourceName: "google_essential_contacts_contact.contact", + ImportState: true, + ImportStateVerify: true, }, }, })