Skip to content

Commit

Permalink
Add support for importing Flows, Forms and FlowVaultConnections Terra…
Browse files Browse the repository at this point in the history
…form Resources (#1084)

* Added cli support to terraform import flow, form and vault connection

* Added docs + updated test case

* minor update to version

* Added test cases

* Added negative testing
  • Loading branch information
duedares-rvj authored Oct 16, 2024
1 parent e7536d4 commit 865487b
Show file tree
Hide file tree
Showing 10 changed files with 865 additions and 47 deletions.
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_client,auth0_client_grant,auth0_connection,auth0_custom_domain,auth0_email_provider,auth0_email_template,auth0_guardian,auth0_organization,auth0_pages,auth0_prompt,auth0_prompt_custom_text,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_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_organization,auth0_pages,auth0_prompt,auth0_prompt_custom_text,auth0_resource_server,auth0_role,auth0_tenant,auth0_trigger_actions])
```


Expand Down
92 changes: 49 additions & 43 deletions internal/auth0/auth0.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,61 @@ import (
// API mimics `management.Management`s general interface, except it refers to
// the interfaces instead of the concrete structs.
type API struct {
Action ActionAPI
Anomaly AnomalyAPI
AttackProtection AttackProtectionAPI
Branding BrandingAPI
BrandingTheme BrandingThemeAPI
Client ClientAPI
ClientGrant ClientGrantAPI
Connection ConnectionAPI
CustomDomain CustomDomainAPI
EmailTemplate EmailTemplateAPI
EmailProvider EmailProviderAPI
Log LogAPI
LogStream LogStreamAPI
Organization OrganizationAPI
Prompt PromptAPI
ResourceServer ResourceServerAPI
Role RoleAPI
Rule RuleAPI
Tenant TenantAPI
User UserAPI
Jobs JobsAPI
Action ActionAPI
Anomaly AnomalyAPI
AttackProtection AttackProtectionAPI
Branding BrandingAPI
BrandingTheme BrandingThemeAPI
Client ClientAPI
ClientGrant ClientGrantAPI
Connection ConnectionAPI
CustomDomain CustomDomainAPI
EmailTemplate EmailTemplateAPI
EmailProvider EmailProviderAPI
Flow FlowAPI
FlowVaultConnection FlowVaultConnectionAPI
Form FormAPI
Log LogAPI
LogStream LogStreamAPI
Organization OrganizationAPI
Prompt PromptAPI
ResourceServer ResourceServerAPI
Role RoleAPI
Rule RuleAPI
Tenant TenantAPI
User UserAPI
Jobs JobsAPI

HTTPClient HTTPClientAPI
}

func NewAPI(m *management.Management) *API {
return &API{
Action: m.Action,
Anomaly: m.Anomaly,
AttackProtection: m.AttackProtection,
Branding: m.Branding,
BrandingTheme: m.BrandingTheme,
Client: m.Client,
ClientGrant: m.ClientGrant,
Connection: m.Connection,
CustomDomain: m.CustomDomain,
EmailTemplate: m.EmailTemplate,
EmailProvider: m.EmailProvider,
Log: m.Log,
LogStream: m.LogStream,
Organization: m.Organization,
Prompt: m.Prompt,
ResourceServer: m.ResourceServer,
Role: m.Role,
Rule: m.Rule,
Tenant: m.Tenant,
User: m.User,
Jobs: m.Job,
HTTPClient: m,
Action: m.Action,
Anomaly: m.Anomaly,
AttackProtection: m.AttackProtection,
Branding: m.Branding,
BrandingTheme: m.BrandingTheme,
Client: m.Client,
ClientGrant: m.ClientGrant,
Connection: m.Connection,
CustomDomain: m.CustomDomain,
EmailTemplate: m.EmailTemplate,
EmailProvider: m.EmailProvider,
Flow: m.Flow,
FlowVaultConnection: m.Flow.Vault,
Form: m.Form,
Log: m.Log,
LogStream: m.LogStream,
Organization: m.Organization,
Prompt: m.Prompt,
ResourceServer: m.ResourceServer,
Role: m.Role,
Rule: m.Rule,
Tenant: m.Tenant,
User: m.User,
Jobs: m.Job,
HTTPClient: m,
}
}

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

package auth0

import (
"context"

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

type FlowAPI interface {
// Create a new flow.
Create(ctx context.Context, r *management.Flow, opts ...management.RequestOption) error

// Read flow details.
Read(ctx context.Context, id string, opts ...management.RequestOption) (r *management.Flow, err error)

// Update an existing flow.
Update(ctx context.Context, id string, r *management.Flow, opts ...management.RequestOption) error

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

// List flow.
List(ctx context.Context, opts ...management.RequestOption) (r *management.FlowList, err error)
}

type FlowVaultConnectionAPI interface {
// CreateConnection Create a new flow vault connection.
CreateConnection(ctx context.Context, r *management.FlowVaultConnection, opts ...management.RequestOption) error

// GetConnection Retrieve flow vault connection details.
GetConnection(ctx context.Context, id string, opts ...management.RequestOption) (r *management.FlowVaultConnection, err error)

// UpdateConnection Update an existing flow vault connection.
UpdateConnection(ctx context.Context, id string, r *management.FlowVaultConnection, opts ...management.RequestOption) error

// DeleteConnection Delete a flow vault connection.
DeleteConnection(ctx context.Context, id string, opts ...management.RequestOption) error

// GetConnectionList List flow vault connections.
GetConnectionList(ctx context.Context, opts ...management.RequestOption) (r *management.FlowVaultConnectionList, err error)
}
26 changes: 26 additions & 0 deletions internal/auth0/form.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//go:generate mockgen -source=form.go -destination=mock/form_mock.go -package=mock

package auth0

import (
"context"

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

type FormAPI interface {
// Create a new form.
Create(ctx context.Context, r *management.Form, opts ...management.RequestOption) error

// Read form details.
Read(ctx context.Context, id string, opts ...management.RequestOption) (r *management.Form, err error)

// Update an existing action.
Update(ctx context.Context, id string, r *management.Form, opts ...management.RequestOption) error

// Delete an action.
Delete(ctx context.Context, id string, opts ...management.RequestOption) error

// List form.
List(ctx context.Context, opts ...management.RequestOption) (r *management.FormList, err error)
}
Loading

0 comments on commit 865487b

Please sign in to comment.