Skip to content

Commit

Permalink
fix(terraform): Handle error when custom domain is not enabled (#1103)
Browse files Browse the repository at this point in the history
Co-authored-by: Rajat Bajaj <[email protected]>
  • Loading branch information
thomas-auth0 and duedares-rvj authored Dec 16, 2024
1 parent e9c0099 commit 8468c81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/cli/terraform_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
20 changes: 20 additions & 0 deletions internal/cli/terraform_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8468c81

Please sign in to comment.