Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXCDT-534: auth0_prompt resource export support #833

Merged
merged 7 commits into from
Sep 6, 2023
2 changes: 1 addition & 1 deletion docs/auth0_terraform_generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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_client,auth0_client_grant,auth0_connection,auth0_custom_domain,auth0_email_provider,auth0_guardian,auth0_log_stream,auth0_organization,auth0_pages,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_client,auth0_client_grant,auth0_connection,auth0_custom_domain,auth0_email_provider,auth0_guardian,auth0_log_stream,auth0_organization,auth0_pages,auth0_prompt,auth0_role,auth0_tenant,auth0_trigger_actions])
```


Expand Down
2 changes: 2 additions & 0 deletions internal/cli/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (i *terraformInputs) parseResourceFetchers(api *auth0.API) ([]resourceDataF
fetchers = append(fetchers, &organizationResourceFetcher{api})
case "auth0_pages":
fetchers = append(fetchers, &pagesResourceFetcher{})
case "auth0_prompt":
fetchers = append(fetchers, &promptResourceFetcher{})
case "auth0_role":
fetchers = append(fetchers, &roleResourceFetcher{api})
case "auth0_tenant":
Expand Down
13 changes: 12 additions & 1 deletion internal/cli/terraform_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/auth0/auth0-cli/internal/auth0"
)

var defaultResources = []string{"auth0_action", "auth0_attack_protection", "auth0_branding", "auth0_client", "auth0_client_grant", "auth0_connection", "auth0_custom_domain", "auth0_email_provider", "auth0_guardian", "auth0_log_stream", "auth0_organization", "auth0_pages", "auth0_role", "auth0_tenant", "auth0_trigger_actions"}
var defaultResources = []string{"auth0_action", "auth0_attack_protection", "auth0_branding", "auth0_client", "auth0_client_grant", "auth0_connection", "auth0_custom_domain", "auth0_email_provider", "auth0_guardian", "auth0_log_stream", "auth0_organization", "auth0_pages", "auth0_prompt", "auth0_role", "auth0_tenant", "auth0_trigger_actions"}

type (
importDataList []importDataItem
Expand Down Expand Up @@ -61,6 +61,8 @@ type (

pagesResourceFetcher struct{}

promptResourceFetcher struct{}

roleResourceFetcher struct {
api *auth0.API
}
Expand Down Expand Up @@ -284,6 +286,15 @@ func (f *pagesResourceFetcher) FetchData(_ context.Context) (importDataList, err
}, nil
}

func (f *promptResourceFetcher) FetchData(_ context.Context) (importDataList, error) {
return []importDataItem{
{
ResourceName: "auth0_prompt.prompts",
ImportID: uuid.NewString(),
},
}, nil
}

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

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

func TestPromptProviderResourceFetcher_FetchData(t *testing.T) {
t.Run("it successfully generates prompts import data", func(t *testing.T) {
fetcher := promptResourceFetcher{}

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

func TestRoleResourceFetcher_FetchData(t *testing.T) {
t.Run("it successfully retrieves roles data", func(t *testing.T) {
ctrl := gomock.NewController(t)
Expand Down