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-522: auth0_attack_protection resource export support #817

Merged
merged 3 commits into from
Aug 31, 2023
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 @@ -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_branding,auth0_client,auth0_client_grant,auth0_connection,auth0_custom_domain,auth0_organization,auth0_pages,auth0_role,auth0_tenant])
-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_organization,auth0_pages,auth0_role,auth0_tenant])
```


Expand Down
2 changes: 2 additions & 0 deletions internal/cli/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func (i *terraformInputs) parseResourceFetchers(api *auth0.API) ([]resourceDataF
switch resource {
case "auth0_action":
fetchers = append(fetchers, &actionResourceFetcher{api})
case "auth0_attack_protection":
fetchers = append(fetchers, &attackProtectionResourceFetcher{})
case "auth0_branding":
fetchers = append(fetchers, &brandingResourceFetcher{})
case "auth0_client":
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_branding", "auth0_client", "auth0_client_grant", "auth0_connection", "auth0_custom_domain", "auth0_organization", "auth0_pages", "auth0_role", "auth0_tenant"}
var defaultResources = []string{"auth0_action", "auth0_attack_protection", "auth0_branding", "auth0_client", "auth0_client_grant", "auth0_connection", "auth0_custom_domain", "auth0_organization", "auth0_pages", "auth0_role", "auth0_tenant"}

type (
importDataList []importDataItem
Expand All @@ -30,6 +30,8 @@ type (
api *auth0.API
}

attackProtectionResourceFetcher struct{}

brandingResourceFetcher struct{}
clientResourceFetcher struct {
api *auth0.API
Expand Down Expand Up @@ -59,6 +61,15 @@ type (
tenantResourceFetcher struct{}
)

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

func (f *brandingResourceFetcher) FetchData(_ context.Context) (importDataList, error) {
return []importDataItem{
{
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 @@ -141,6 +141,18 @@ func TestActionResourceFetcher_FetchData(t *testing.T) {
})
}

func TestAttackProtectionResourceFetcher_FetchData(t *testing.T) {
t.Run("it successfully generates attack protection import data", func(t *testing.T) {
fetcher := attackProtectionResourceFetcher{}

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

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