Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/auth0_terraform_generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ auth0 terraform generate [flags]
```
--force Skip confirmation.
-o, --output-dir string Output directory for the generated Terraform config files. If not provided, the files will be saved in the current working directory. (default "./")
-r, --resources strings Resource types to generate Terraform config for. If not provided, config files for all available resources will be generated. (default [auth0_action,auth0_attack_protection,auth0_branding,auth0_phone_provider,auth0_client,auth0_client_grant,auth0_connection,auth0_custom_domain,auth0_flow,auth0_flow_vault_connection,auth0_form,auth0_email_provider,auth0_email_template,auth0_guardian,auth0_log_stream,auth0_network_acl,auth0_organization,auth0_pages,auth0_prompt,auth0_prompt_custom_text,auth0_prompt_screen_renderer,auth0_resource_server,auth0_role,auth0_self_service_profile,auth0_tenant,auth0_trigger_actions,auth0_user_attribute_profile])
-r, --resources strings Resource types to generate Terraform config for. If not provided, config files for all available resources will be generated. (default [auth0_action,auth0_attack_protection,auth0_branding,auth0_branding_theme,auth0_phone_provider,auth0_client,auth0_client_grant,auth0_connection,auth0_custom_domain,auth0_flow,auth0_flow_vault_connection,auth0_form,auth0_email_provider,auth0_email_template,auth0_guardian,auth0_log_stream,auth0_network_acl,auth0_organization,auth0_pages,auth0_prompt,auth0_prompt_custom_text,auth0_prompt_screen_renderer,auth0_resource_server,auth0_role,auth0_self_service_profile,auth0_tenant,auth0_trigger_actions,auth0_user_attribute_profile])
-v, --tf-version string Terraform version that ought to be used while generating the terraform files for resources. If not provided, 1.5.0 is used by default (default "1.5.0")
```

Expand Down
2 changes: 2 additions & 0 deletions internal/cli/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func (i *terraformInputs) parseResourceFetchers(api *auth0.API) ([]resourceDataF
fetchers = append(fetchers, &attackProtectionResourceFetcher{})
case "auth0_branding":
fetchers = append(fetchers, &brandingResourceFetcher{})
case "auth0_branding_theme":
fetchers = append(fetchers, &brandingThemeResourceFetcher{api})
case "auth0_phone_provider":
fetchers = append(fetchers, &phoneProviderResourceFetcher{api})
case "auth0_client", "auth0_client_credentials":
Expand Down
24 changes: 23 additions & 1 deletion internal/cli/terraform_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var (
defaultResources = []string{"auth0_action", "auth0_attack_protection", "auth0_branding", "auth0_phone_provider", "auth0_client", "auth0_client_grant", "auth0_connection", "auth0_custom_domain", "auth0_flow", "auth0_flow_vault_connection", "auth0_form", "auth0_email_provider", "auth0_email_template", "auth0_guardian", "auth0_log_stream", "auth0_network_acl", "auth0_organization", "auth0_pages", "auth0_prompt", "auth0_prompt_custom_text", "auth0_prompt_screen_renderer", "auth0_resource_server", "auth0_role", "auth0_self_service_profile", "auth0_tenant", "auth0_trigger_actions", "auth0_user_attribute_profile"}
defaultResources = []string{"auth0_action", "auth0_attack_protection", "auth0_branding", "auth0_branding_theme", "auth0_phone_provider", "auth0_client", "auth0_client_grant", "auth0_connection", "auth0_custom_domain", "auth0_flow", "auth0_flow_vault_connection", "auth0_form", "auth0_email_provider", "auth0_email_template", "auth0_guardian", "auth0_log_stream", "auth0_network_acl", "auth0_organization", "auth0_pages", "auth0_prompt", "auth0_prompt_custom_text", "auth0_prompt_screen_renderer", "auth0_resource_server", "auth0_role", "auth0_self_service_profile", "auth0_tenant", "auth0_trigger_actions", "auth0_user_attribute_profile"}
)

type (
Expand All @@ -37,6 +37,10 @@ type (

brandingResourceFetcher struct{}

brandingThemeResourceFetcher struct {
api *auth0.API
}

phoneProviderResourceFetcher struct {
api *auth0.API
}
Expand Down Expand Up @@ -139,6 +143,24 @@ func (f *brandingResourceFetcher) FetchData(_ context.Context) (importDataList,
},
}, nil
}
func (f *brandingThemeResourceFetcher) FetchData(ctx context.Context) (importDataList, error) {
var data importDataList

theme, err := f.api.BrandingTheme.Default(ctx)
if err != nil {
if mErr, ok := err.(management.Error); ok && mErr.Status() == http.StatusNotFound {
return nil, nil
}
return nil, err
}

data = append(data, importDataItem{
ResourceName: "auth0_branding_theme.default",
ImportID: theme.GetID(),
})

return data, nil
}

func (f *phoneProviderResourceFetcher) FetchData(ctx context.Context) (importDataList, error) {
var data importDataList
Expand Down
70 changes: 70 additions & 0 deletions internal/cli/terraform_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,76 @@ func TestBrandingResourceFetcher_FetchData(t *testing.T) {
})
}

func TestBrandingThemeResourceFetcher_FetchData(t *testing.T) {
t.Run("it successfully retrieves branding theme data", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

brandingThemeAPI := mock.NewMockBrandingThemeAPI(ctrl)
brandingThemeAPI.EXPECT().
Default(gomock.Any()).
Return(&management.BrandingTheme{
ID: auth0.String("theme_123"),
}, nil)

fetcher := brandingThemeResourceFetcher{
api: &auth0.API{
BrandingTheme: brandingThemeAPI,
},
}

expectedData := importDataList{
{
ResourceName: "auth0_branding_theme.default",
ImportID: "theme_123",
},
}

data, err := fetcher.FetchData(context.Background())
assert.NoError(t, err)
assert.Equal(t, expectedData, data)
})

t.Run("it returns an error if api call fails", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

brandingThemeAPI := mock.NewMockBrandingThemeAPI(ctrl)
brandingThemeAPI.EXPECT().
Default(gomock.Any()).
Return(nil, fmt.Errorf("failed to get default theme"))

fetcher := brandingThemeResourceFetcher{
api: &auth0.API{
BrandingTheme: brandingThemeAPI,
},
}

_, err := fetcher.FetchData(context.Background())
assert.EqualError(t, err, "failed to get default theme")
})

t.Run("it returns nil data if branding theme is not found", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mErr := mockManagamentError{status: http.StatusNotFound}
brandingThemeAPI := mock.NewMockBrandingThemeAPI(ctrl)
brandingThemeAPI.EXPECT().
Default(gomock.Any()).
Return(nil, mErr)

fetcher := brandingThemeResourceFetcher{
api: &auth0.API{
BrandingTheme: brandingThemeAPI,
},
}

_, err := fetcher.FetchData(context.Background())
assert.NoError(t, err)
})
}

func Test_phoneProviderResourceFetcher_FetchData(t *testing.T) {
t.Run("it successfully retrieves twilio's phone providers data", func(t *testing.T) {
ctrl := gomock.NewController(t)
Expand Down
Loading