From a5e553518b76ab336d8c61555d7f0ca7255ef9ec Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 15 Sep 2021 18:42:18 -0500 Subject: [PATCH] fixed writing to state (#5186) (#10082) Signed-off-by: Modular Magician --- .changelog/5186.txt | 3 +++ google/resource_google_organization_policy.go | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 .changelog/5186.txt diff --git a/.changelog/5186.txt b/.changelog/5186.txt new file mode 100644 index 00000000000..ca865a28278 --- /dev/null +++ b/.changelog/5186.txt @@ -0,0 +1,3 @@ +```release-note:bug +platform: fixed a bug in wrongly writing to state when creation failed on `google_organization_policy` +``` diff --git a/google/resource_google_organization_policy.go b/google/resource_google_organization_policy.go index e07a5a863c0..fef41c8b8a4 100644 --- a/google/resource_google_organization_policy.go +++ b/google/resource_google_organization_policy.go @@ -174,8 +174,6 @@ func resourceGoogleOrganizationPolicy() *schema.Resource { } func resourceGoogleOrganizationPolicyCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId(fmt.Sprintf("%s/%s", d.Get("org_id"), d.Get("constraint").(string))) - if isOrganizationPolicyUnset(d) { return resourceGoogleOrganizationPolicyDelete(d, meta) } @@ -184,6 +182,7 @@ func resourceGoogleOrganizationPolicyCreate(d *schema.ResourceData, meta interfa return err } + d.SetId(fmt.Sprintf("%s/%s", d.Get("org_id"), d.Get("constraint").(string))) return resourceGoogleOrganizationPolicyRead(d, meta) }