Skip to content

Commit eac0341

Browse files
authored
feat(tf/generate): support generating auth0_user_attribute_profile resources (#1344)
feat(tf/generate): support exporting auth0_user_attribute_profile resources
1 parent 892e228 commit eac0341

File tree

7 files changed

+320
-57
lines changed

7 files changed

+320
-57
lines changed

docs/auth0_terraform_generate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ auth0 terraform generate [flags]
3333
```
3434
--force Skip confirmation.
3535
-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 "./")
36-
-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])
36+
-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])
3737
-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")
3838
```
3939

internal/auth0/auth0.go

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,69 @@ import (
88
// API mimics `management.Management`s general interface, except it refers to
99
// the interfaces instead of the concrete structs.
1010
type API struct {
11-
Action ActionAPI
12-
Anomaly AnomalyAPI
13-
AttackProtection AttackProtectionAPI
14-
Branding BrandingAPI
15-
BrandingTheme BrandingThemeAPI
16-
Client ClientAPI
17-
ClientGrant ClientGrantAPI
18-
Connection ConnectionAPI
19-
CustomDomain CustomDomainAPI
20-
EmailTemplate EmailTemplateAPI
21-
EmailProvider EmailProviderAPI
22-
EventStream EventStreamAPI
23-
Flow FlowAPI
24-
FlowVaultConnection FlowVaultConnectionAPI
25-
Form FormAPI
26-
Log LogAPI
27-
LogStream LogStreamAPI
28-
Organization OrganizationAPI
29-
NetworkACL NetworkACLAPI
30-
Prompt PromptAPI
31-
ResourceServer ResourceServerAPI
32-
Role RoleAPI
33-
Rule RuleAPI
34-
Tenant TenantAPI
35-
User UserAPI
36-
Jobs JobsAPI
37-
SelfServiceProfile SelfServiceProfileAPI
11+
Action ActionAPI
12+
Anomaly AnomalyAPI
13+
AttackProtection AttackProtectionAPI
14+
Branding BrandingAPI
15+
BrandingTheme BrandingThemeAPI
16+
Client ClientAPI
17+
ClientGrant ClientGrantAPI
18+
Connection ConnectionAPI
19+
CustomDomain CustomDomainAPI
20+
EmailTemplate EmailTemplateAPI
21+
EmailProvider EmailProviderAPI
22+
EventStream EventStreamAPI
23+
Flow FlowAPI
24+
FlowVaultConnection FlowVaultConnectionAPI
25+
Form FormAPI
26+
Log LogAPI
27+
LogStream LogStreamAPI
28+
Organization OrganizationAPI
29+
NetworkACL NetworkACLAPI
30+
Prompt PromptAPI
31+
ResourceServer ResourceServerAPI
32+
Role RoleAPI
33+
Rule RuleAPI
34+
Tenant TenantAPI
35+
User UserAPI
36+
Jobs JobsAPI
37+
SelfServiceProfile SelfServiceProfileAPI
38+
UserAttributeProfile UserAttributeProfilesAPI
3839

3940
HTTPClient HTTPClientAPI
4041
}
4142

4243
func NewAPI(m *management.Management) *API {
4344
return &API{
44-
Action: m.Action,
45-
Anomaly: m.Anomaly,
46-
AttackProtection: m.AttackProtection,
47-
Branding: m.Branding,
48-
BrandingTheme: m.BrandingTheme,
49-
Client: m.Client,
50-
ClientGrant: m.ClientGrant,
51-
Connection: m.Connection,
52-
CustomDomain: m.CustomDomain,
53-
EmailTemplate: m.EmailTemplate,
54-
EmailProvider: m.EmailProvider,
55-
EventStream: m.EventStream,
56-
Flow: m.Flow,
57-
FlowVaultConnection: m.Flow.Vault,
58-
Form: m.Form,
59-
Log: m.Log,
60-
LogStream: m.LogStream,
61-
Organization: m.Organization,
62-
NetworkACL: m.NetworkACL,
63-
Prompt: m.Prompt,
64-
ResourceServer: m.ResourceServer,
65-
Role: m.Role,
66-
Rule: m.Rule,
67-
Tenant: m.Tenant,
68-
User: m.User,
69-
Jobs: m.Job,
70-
SelfServiceProfile: m.SelfServiceProfile,
71-
HTTPClient: m,
45+
Action: m.Action,
46+
Anomaly: m.Anomaly,
47+
AttackProtection: m.AttackProtection,
48+
Branding: m.Branding,
49+
BrandingTheme: m.BrandingTheme,
50+
Client: m.Client,
51+
ClientGrant: m.ClientGrant,
52+
Connection: m.Connection,
53+
CustomDomain: m.CustomDomain,
54+
EmailTemplate: m.EmailTemplate,
55+
EmailProvider: m.EmailProvider,
56+
EventStream: m.EventStream,
57+
Flow: m.Flow,
58+
FlowVaultConnection: m.Flow.Vault,
59+
Form: m.Form,
60+
Log: m.Log,
61+
LogStream: m.LogStream,
62+
Organization: m.Organization,
63+
NetworkACL: m.NetworkACL,
64+
Prompt: m.Prompt,
65+
ResourceServer: m.ResourceServer,
66+
Role: m.Role,
67+
Rule: m.Rule,
68+
Tenant: m.Tenant,
69+
User: m.User,
70+
Jobs: m.Job,
71+
SelfServiceProfile: m.SelfServiceProfile,
72+
UserAttributeProfile: m.UserAttributeProfile,
73+
HTTPClient: m,
7274
}
7375
}
7476

internal/auth0/mock/user_attribute_profiles.go

Lines changed: 173 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//go:generate mockgen -source=user_attribute_profiles.go -destination=mock/user_attribute_profiles.go -package=mock
2+
3+
package auth0
4+
5+
import (
6+
"context"
7+
8+
"github.com/auth0/go-auth0/management"
9+
)
10+
11+
type UserAttributeProfilesAPI interface {
12+
Create(ctx context.Context, p *management.UserAttributeProfile, opts ...management.RequestOption) error
13+
14+
List(ctx context.Context, opts ...management.RequestOption) (p *management.UserAttributeProfileList, err error)
15+
16+
Read(ctx context.Context, id string, opts ...management.RequestOption) (p *management.UserAttributeProfile, err error)
17+
18+
Update(ctx context.Context, id string, p *management.UserAttributeProfile, opts ...management.RequestOption) error
19+
20+
Delete(ctx context.Context, id string, opts ...management.RequestOption) error
21+
22+
ListTemplates(ctx context.Context, opts ...management.RequestOption) (p *management.UserAttributeProfileTemplateList, err error)
23+
24+
GetTemplate(ctx context.Context, id string, opts ...management.RequestOption) (p *management.UserAttributeProfileTemplateItem, err error)
25+
}

internal/cli/terraform.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ func (i *terraformInputs) parseResourceFetchers(api *auth0.API) ([]resourceDataF
119119
fetchers = append(fetchers, &tenantResourceFetcher{})
120120
case "auth0_trigger_actions":
121121
fetchers = append(fetchers, &triggerActionsResourceFetcher{api})
122+
case "auth0_user_attribute_profile":
123+
fetchers = append(fetchers, &userAttributeProfilesResourceFetcher{api})
122124
default:
123125
err = errors.Join(err, fmt.Errorf("unsupported resource type: %s", resource))
124126
}

internal/cli/terraform_fetcher.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
var (
15-
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"}
15+
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"}
1616
)
1717

1818
type (
@@ -116,6 +116,10 @@ type (
116116
triggerActionsResourceFetcher struct {
117117
api *auth0.API
118118
}
119+
120+
userAttributeProfilesResourceFetcher struct {
121+
api *auth0.API
122+
}
119123
)
120124

121125
func (f *attackProtectionResourceFetcher) FetchData(_ context.Context) (importDataList, error) {
@@ -688,6 +692,33 @@ func (f *triggerActionsResourceFetcher) FetchData(ctx context.Context) (importDa
688692
return data, nil
689693
}
690694

695+
func (f *userAttributeProfilesResourceFetcher) FetchData(ctx context.Context) (importDataList, error) {
696+
var data importDataList
697+
698+
from := ""
699+
for {
700+
profiles, err := f.api.UserAttributeProfile.List(ctx, management.From(from))
701+
if err != nil {
702+
return nil, err
703+
}
704+
705+
for _, profile := range profiles.UserAttributeProfiles {
706+
data = append(data, importDataItem{
707+
ResourceName: "auth0_user_attribute_profile." + sanitizeResourceName(profile.GetName()),
708+
ImportID: profile.GetID(),
709+
})
710+
}
711+
712+
if !profiles.HasNext() {
713+
break
714+
}
715+
716+
from = profiles.Next
717+
}
718+
719+
return data, nil
720+
}
721+
691722
func (f *actionResourceFetcher) FetchData(ctx context.Context) (importDataList, error) {
692723
var data importDataList
693724

0 commit comments

Comments
 (0)