From 8468c8162669a4fc4c1ddc35d1263aaf5f54916f Mon Sep 17 00:00:00 2001 From: thomas-auth0 <97907117+thomas-auth0@users.noreply.github.com> Date: Mon, 16 Dec 2024 07:23:24 +0100 Subject: [PATCH] fix(terraform): Handle error when custom domain is not enabled (#1103) Co-authored-by: Rajat Bajaj --- internal/cli/terraform_fetcher.go | 10 ++++++++-- internal/cli/terraform_fetcher_test.go | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/internal/cli/terraform_fetcher.go b/internal/cli/terraform_fetcher.go index 221e9140..5ca9c914 100644 --- a/internal/cli/terraform_fetcher.go +++ b/internal/cli/terraform_fetcher.go @@ -244,10 +244,16 @@ func (f *customDomainResourceFetcher) FetchData(ctx context.Context) (importData customDomains, err := f.api.CustomDomain.List(ctx) if err != nil { - if strings.Contains(err.Error(), "The account is not allowed to perform this operation, please contact our support team") { - return data, nil + errNotEnabled := []string{ + "The account is not allowed to perform this operation, please contact our support team", + "There must be a verified credit card on file to perform this operation", } + for _, e := range errNotEnabled { + if strings.Contains(err.Error(), e) { + return data, nil + } + } return nil, err } diff --git a/internal/cli/terraform_fetcher_test.go b/internal/cli/terraform_fetcher_test.go index e24e5d08..054f3bae 100644 --- a/internal/cli/terraform_fetcher_test.go +++ b/internal/cli/terraform_fetcher_test.go @@ -561,6 +561,26 @@ func TestCustomDomainResourceFetcher_FetchData(t *testing.T) { assert.NoError(t, err) assert.Len(t, data, 0) }) + + t.Run("it returns empty set error if no verified CC error occurs", func(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + customDomainAPI := mock.NewMockCustomDomainAPI(ctrl) + customDomainAPI.EXPECT(). + List(gomock.Any()). + Return(nil, fmt.Errorf("403 Forbidden: There must be a verified credit card on file to perform this operation")) + + fetcher := customDomainResourceFetcher{ + api: &auth0.API{ + CustomDomain: customDomainAPI, + }, + } + + data, err := fetcher.FetchData(context.Background()) + assert.NoError(t, err) + assert.Len(t, data, 0) + }) } func TestFormResourceFetcher_FetchData(t *testing.T) {