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_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,auth0_prompt_screen_partial,auth0_phone_notification_template])
-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,auth0_prompt_screen_partial,auth0_phone_notification_template,auth0_token_exchange_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 @@ -129,6 +129,8 @@ func (i *terraformInputs) parseResourceFetchers(api *auth0.API, apiv3 *auth0.API
fetchers = append(fetchers, &triggerActionsResourceFetcher{api})
case "auth0_user_attribute_profile":
fetchers = append(fetchers, &userAttributeProfilesResourceFetcher{api})
case "auth0_token_exchange_profile":
fetchers = append(fetchers, &tokenExchangeProfileResourceFetcher{api})
default:
err = errors.Join(err, fmt.Errorf("unsupported resource type: %s", resource))
}
Expand Down
33 changes: 32 additions & 1 deletion internal/cli/terraform_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
"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", "auth0_prompt_screen_partial",
"auth0_phone_notification_template",
"auth0_phone_notification_template", "auth0_token_exchange_profile",
}
)

Expand Down Expand Up @@ -138,6 +138,10 @@ type (
phoneNotificationTemplateResourceFetcher struct {
apiv3 *auth0.APIV3
}

tokenExchangeProfileResourceFetcher struct {
api *auth0.API
}
)

func (f *attackProtectionResourceFetcher) FetchData(_ context.Context) (importDataList, error) {
Expand Down Expand Up @@ -818,6 +822,33 @@ func (f *userAttributeProfilesResourceFetcher) FetchData(ctx context.Context) (i
return data, nil
}

func (f *tokenExchangeProfileResourceFetcher) FetchData(ctx context.Context) (importDataList, error) {
var data importDataList

from := ""
for {
profiles, err := f.api.TokenExchange.List(ctx, management.From(from))
if err != nil {
return nil, err
}

for _, profile := range profiles.TokenExchangeProfiles {
data = append(data, importDataItem{
ResourceName: "auth0_token_exchange_profile." + sanitizeResourceName(profile.GetName()),
ImportID: profile.GetID(),
})
}

if !profiles.HasNext() {
break
}

from = profiles.Next
}

return data, nil
}

func (f *actionResourceFetcher) FetchData(ctx context.Context) (importDataList, error) {
var data importDataList

Expand Down
30 changes: 30 additions & 0 deletions internal/cli/terraform_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2448,6 +2448,36 @@ func TestUserAttributeProfileResourceFetcher(t *testing.T) {
})
}

func TestTokenExchangeProfileResourceFetcher(t *testing.T) {
t.Run("it successfully generates token exchange profile import data", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

tokenExchangeAPI := mock.NewMockTokenExchangeAPI(ctrl)

tokenExchangeAPI.EXPECT().
List(gomock.Any(), gomock.Any()).
Return(&management.TokenExchangeProfileList{
TokenExchangeProfiles: []*management.TokenExchangeProfile{
{
ID: auth0.String("tep_123456"),
Name: auth0.String("Token Exchange Profile 1"),
}}}, nil)

fetcher := tokenExchangeProfileResourceFetcher{
api: &auth0.API{
TokenExchange: tokenExchangeAPI,
},
}

data, err := fetcher.FetchData(context.Background())
assert.NoError(t, err)
assert.Len(t, data, 1)
assert.Equal(t, data[0].ResourceName, "auth0_token_exchange_profile.token_exchange_profile_1")
assert.Greater(t, len(data[0].ImportID), 0)
})
}

func Test_promptScreenPartialResourceFetcher_FetchData(t *testing.T) {
t.Run("it successfully retrieves screen partial prompts data", func(t *testing.T) {
fetcher := promptScreenPartialResourceFetcher{}
Expand Down
9 changes: 9 additions & 0 deletions internal/cli/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,15 @@ func TestTerraformInputs_ParseResourceFetchers(t *testing.T) {
&phoneNotificationTemplateResourceFetcher{apiv3},
},
},
{
name: "it can successfully parse resources: auth0_token_exchange_profile",
input: terraformInputs{
Resources: []string{"auth0_token_exchange_profile"},
},
expectedDataFetchers: []resourceDataFetcher{
&tokenExchangeProfileResourceFetcher{api},
},
},
{
name: "it can successfully parse resources: auth0_client, auth0_connection",
input: terraformInputs{
Expand Down