Skip to content
Merged
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_tenant,auth0_trigger_actions])
-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])
-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/auth0/auth0.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type API struct {
Tenant TenantAPI
User UserAPI
Jobs JobsAPI
SelfServiceProfile SelfServiceProfileAPI

HTTPClient HTTPClientAPI
}
Expand Down Expand Up @@ -66,6 +67,7 @@ func NewAPI(m *management.Management) *API {
Tenant: m.Tenant,
User: m.User,
Jobs: m.Job,
SelfServiceProfile: m.SelfServiceProfile,
HTTPClient: m,
}
}
Expand Down
153 changes: 153 additions & 0 deletions internal/auth0/mock/self_service_profiles.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions internal/auth0/self_service_profiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//go:generate mockgen -source=self_service_profiles.go -destination=mock/self_service_profiles.go -package=mock

package auth0

import (
"context"

"github.com/auth0/go-auth0/management"
)

type SelfServiceProfileAPI interface {
// Create a new sSelf Service Profiles.
Create(ctx context.Context, p *management.SelfServiceProfile, opts ...management.RequestOption) error

// List all Self Service Profiles.
List(ctx context.Context, opts ...management.RequestOption) (p *management.SelfServiceProfileList, err error)

// Read Self Service Profile details for a given profile ID.
Read(ctx context.Context, id string, opts ...management.RequestOption) (p *management.SelfServiceProfile, err error)

// Update an existing Self Service Profile.
Update(ctx context.Context, id string, p *management.SelfServiceProfile, opts ...management.RequestOption) error

// Delete a Self Service Profile.
Delete(ctx context.Context, id string, opts ...management.RequestOption) error

// GetCustomText retrieves text customizations for a given self-service profile, language and Self Service SSO Flow page.
GetCustomText(ctx context.Context, id string, language string, page string, opts ...management.RequestOption) (payload map[string]interface{}, err error)
}
2 changes: 2 additions & 0 deletions internal/cli/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ func (i *terraformInputs) parseResourceFetchers(api *auth0.API) ([]resourceDataF
fetchers = append(fetchers, &resourceServerResourceFetcher{api})
case "auth0_role", "auth0_role_permissions":
fetchers = append(fetchers, &roleResourceFetcher{api})
case "auth0_self_service_profile":
fetchers = append(fetchers, &selfServiceProfileFetcher{api})
case "auth0_tenant":
fetchers = append(fetchers, &tenantResourceFetcher{})
case "auth0_trigger_actions":
Expand Down
51 changes: 50 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_tenant", "auth0_trigger_actions"}
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"}
)

type (
Expand Down Expand Up @@ -107,6 +107,10 @@ type (
api *auth0.API
}

selfServiceProfileFetcher struct {
api *auth0.API
}

tenantResourceFetcher struct{}

triggerActionsResourceFetcher struct {
Expand Down Expand Up @@ -610,6 +614,51 @@ func (f *roleResourceFetcher) FetchData(ctx context.Context) (importDataList, er
return data, nil
}

var selfServiceProfileLanguages = []string{"en"}
var selfServiceProfilePages = []string{"get-started"}

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

var page int
for {
profiles, err := f.api.SelfServiceProfile.List(ctx, management.Page(page))
if err != nil {
return nil, err
}

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

for _, lang := range selfServiceProfileLanguages {
for _, page := range selfServiceProfilePages {
customText, err := f.api.SelfServiceProfile.GetCustomText(ctx, profile.GetID(), lang, page)
if err != nil {
return nil, err
}
if len(customText) == 0 {
continue
}

data = append(data, importDataItem{
ResourceName: "auth0_self_service_profile_custom_text." + sanitizeResourceName(profile.GetName()+"_"+lang+"_"+page),
ImportID: profile.GetID() + "::" + lang + "::" + page,
})
}
}
}

if !profiles.HasNext() {
break
}
}

return data, nil
}

func (f *tenantResourceFetcher) FetchData(_ context.Context) (importDataList, error) {
return []importDataItem{
{
Expand Down
74 changes: 74 additions & 0 deletions internal/cli/terraform_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,80 @@ func TestRoleResourceFetcher_FetchData(t *testing.T) {
})
}

func TestSelfServiceProfileFetcher(t *testing.T) {
t.Run("it successfully generates self service profile import data with custom text", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

selfServiceProfileAPI := mock.NewMockSelfServiceProfileAPI(ctrl)

selfServiceProfileAPI.EXPECT().
List(gomock.Any(), gomock.Any()).
Return(&management.SelfServiceProfileList{
SelfServiceProfile: []*management.SelfServiceProfile{
{
ID: auth0.String("ss_profile_1"),
Name: auth0.String("Self Service Profile 1"),
},
},
}, nil)

selfServiceProfileAPI.EXPECT().
GetCustomText(gomock.Any(), "ss_profile_1", "en", "get-started").
Return(map[string]interface{}{
"introduction": "hello, world",
}, nil)

fetcher := selfServiceProfileFetcher{
api: &auth0.API{
SelfServiceProfile: selfServiceProfileAPI,
},
}

data, err := fetcher.FetchData(context.Background())
assert.NoError(t, err)
assert.Len(t, data, 2)
assert.Equal(t, data[0].ResourceName, "auth0_self_service_profile.self_service_profile_1")
assert.Greater(t, len(data[0].ImportID), 0)
assert.Equal(t, data[1].ResourceName, "auth0_self_service_profile_custom_text.self_service_profile_1_en_get_started")
assert.Greater(t, len(data[1].ImportID), 0)
})

t.Run("it successfully generates self service profile import data without custom text", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

selfServiceProfileAPI := mock.NewMockSelfServiceProfileAPI(ctrl)

selfServiceProfileAPI.EXPECT().
List(gomock.Any(), gomock.Any()).
Return(&management.SelfServiceProfileList{
SelfServiceProfile: []*management.SelfServiceProfile{
{
ID: auth0.String("ss_profile_1"),
Name: auth0.String("Self Service Profile 1"),
},
},
}, nil)

selfServiceProfileAPI.EXPECT().
GetCustomText(gomock.Any(), "ss_profile_1", "en", "get-started").
Return(map[string]interface{}{}, nil)

fetcher := selfServiceProfileFetcher{
api: &auth0.API{
SelfServiceProfile: selfServiceProfileAPI,
},
}

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

func TestTenantResourceFetcher_FetchData(t *testing.T) {
t.Run("it successfully generates tenant import data", func(t *testing.T) {
fetcher := tenantResourceFetcher{}
Expand Down
Loading