From 0f4ef311cecea14e37373bb8fc83301fe2b19e3d Mon Sep 17 00:00:00 2001 From: "heiko.rothe" Date: Fri, 11 Jun 2021 13:21:24 +0200 Subject: [PATCH] feat: mark account as deleted if provisioned product is not found --- internal/provider/resource_aws_account.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/provider/resource_aws_account.go b/internal/provider/resource_aws_account.go index 3d5e9343..e02e4c0e 100644 --- a/internal/provider/resource_aws_account.go +++ b/internal/provider/resource_aws_account.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/organizations" "github.com/aws/aws-sdk-go/service/servicecatalog" + "github.com/hashicorp/aws-sdk-go-base/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -193,6 +194,11 @@ func resourceAWSAccountRead(_ context.Context, d *schema.ResourceData, m interfa product, err := scconn.DescribeProvisionedProduct(&servicecatalog.DescribeProvisionedProductInput{ Id: aws.String(d.Id()), }) + + if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, servicecatalog.ErrCodeResourceNotFoundException) { + d.SetId("") + return nil + } if err != nil { return diag.Errorf("error reading configuration of provisioned product: %v", err) }