From 87e41a1831604c1e98db848afd4e278dd75b63f1 Mon Sep 17 00:00:00 2001 From: Zahiar Ahmed <310030+zahiar@users.noreply.github.com> Date: Sat, 2 Apr 2022 22:19:20 +0100 Subject: [PATCH] GH-77 Address bug with Branch Restriction plans (#86) Specifically when you provision a Branch Restriction via Terraform, and then delete it via the UI, this results in plans erroring, due to Bitbucket's API returning a 404. We now look for the 404 and treat that as the resource has been deleted. --- bitbucket/resource_bitbucket_branch_restriction.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bitbucket/resource_bitbucket_branch_restriction.go b/bitbucket/resource_bitbucket_branch_restriction.go index f7be0ff..0775471 100644 --- a/bitbucket/resource_bitbucket_branch_restriction.go +++ b/bitbucket/resource_bitbucket_branch_restriction.go @@ -138,6 +138,14 @@ func resourceBitbucketBranchRestrictionRead(ctx context.Context, resourceData *s }, ) if err != nil { + // Handles a case whereby if the branch restrictions were deleted after being provisioned, Bitbucket's API + // returns a 404, so we treat that as the item having been deleted, therefore Terraform will re-provision + // if necessary. + if err.Error() == "404 Not Found" { + resourceData.SetId("") + return nil + } + return diag.FromErr(fmt.Errorf("unable to get branch restriction with error: %s", err)) }