Skip to content

Commit

Permalink
Remove IGA-* triggers
Browse files Browse the repository at this point in the history
Added explicit check for handling missing env variables for login (auth0#1065)

* Added explicit check for handling missing env variables for login

* Minor changes

* Minor update to test

* Updated test case

* Updated test case

Added support for Custom Email Provider (auth0#1064)

* Added support for custom email provider

* bump

* bump

* Dummy
  • Loading branch information
Widcket authored and kushalshit27 committed Oct 31, 2024
1 parent 152ca2d commit 509cf61
Show file tree
Hide file tree
Showing 16 changed files with 614 additions and 346 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ This project is licensed under the MPL-2.0 license. See the [LICENSE](LICENSE) f
report.

</div>

15 changes: 12 additions & 3 deletions docs/resources/email_provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ resource "auth0_email_provider" "sendgrid_email_provider" {
# This is an example on how to set up the email provider with Azure CS.
resource "auth0_email_provider" "smtp_email_provider" {
resource "auth0_email_provider" "azure_cs_email_provider" {
name = "azure_cs"
enabled = true
default_from_address = "[email protected]"
Expand All @@ -63,7 +63,7 @@ resource "auth0_email_provider" "smtp_email_provider" {
# This is an example on how to set up the email provider with MS365.
resource "auth0_email_provider" "smtp_email_provider" {
resource "auth0_email_provider" "ms365_email_provider" {
name = "ms365"
enabled = true
default_from_address = "[email protected]"
Expand All @@ -74,6 +74,15 @@ resource "auth0_email_provider" "smtp_email_provider" {
ms365_client_secret = "ms365_client_secret"
}
}
# This is an example on how to set up the email provider with a custom action.
# Make sure a corresponding action exists with custom-email-provider as supported triggers
resource "auth0_email_provider" "custom_email_provider" {
name = "custom"
enabled = true
default_from_address = "[email protected]"
credentials {}
}
```

<!-- schema generated by tfplugindocs -->
Expand All @@ -83,7 +92,7 @@ resource "auth0_email_provider" "smtp_email_provider" {

- `credentials` (Block List, Min: 1, Max: 1) Configuration settings for the credentials for the email provider. (see [below for nested schema](#nestedblock--credentials))
- `default_from_address` (String) Email address to use as the sender when no other "from" address is specified.
- `name` (String) Name of the email provider. Options include `azure_cs`, `mailgun`, `mandrill`, `ms365`, `sendgrid`, `ses`, `smtp` and `sparkpost`.
- `name` (String) Name of the email provider. Options include `azure_cs`, `custom`, `mailgun`, `mandrill`, `ms365`, `sendgrid`, `ses`, `smtp` and `sparkpost`.

### Optional

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/trigger_action.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ resource "auth0_trigger_action" "post_login_alert_action" {
### Required

- `action_id` (String) The ID of the action to bind to the trigger.
- `trigger` (String) The ID of the trigger to bind with. Available options: `post-login`, `credentials-exchange`, `pre-user-registration`, `post-user-registration`, `post-change-password`, `send-phone-message`, `password-reset-post-challenge`, `iga-approval`, `iga-certification`, `iga-fulfillment-assignment`, `iga-fulfillment-execution`.
- `trigger` (String) The ID of the trigger to bind with. Available options: `post-login`, `credentials-exchange`, `pre-user-registration`, `post-user-registration`, `post-change-password`, `send-phone-message`, `password-reset-post-challenge`.

### Optional

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/trigger_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ resource "auth0_trigger_actions" "login_flow" {
### Required

- `actions` (Block List, Min: 1) The list of actions bound to this trigger. (see [below for nested schema](#nestedblock--actions))
- `trigger` (String) The ID of the trigger to bind with. Options include: `post-login`, `credentials-exchange`, `pre-user-registration`, `post-user-registration`, `post-change-password`, `send-phone-message`, `password-reset-post-challenge`, `iga-approval` , `iga-certification` , `iga-fulfillment-assignment`, `iga-fulfillment-execution`.
- `trigger` (String) The ID of the trigger to bind with. Options include: `post-login`, `credentials-exchange`, `pre-user-registration`, `post-user-registration`, `post-change-password`, `send-phone-message`, `password-reset-post-challenge`.

### Read-Only

Expand Down
13 changes: 11 additions & 2 deletions examples/resources/auth0_email_provider/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ resource "auth0_email_provider" "sendgrid_email_provider" {


# This is an example on how to set up the email provider with Azure CS.
resource "auth0_email_provider" "smtp_email_provider" {
resource "auth0_email_provider" "azure_cs_email_provider" {
name = "azure_cs"
enabled = true
default_from_address = "[email protected]"
Expand All @@ -50,7 +50,7 @@ resource "auth0_email_provider" "smtp_email_provider" {


# This is an example on how to set up the email provider with MS365.
resource "auth0_email_provider" "smtp_email_provider" {
resource "auth0_email_provider" "ms365_email_provider" {
name = "ms365"
enabled = true
default_from_address = "[email protected]"
Expand All @@ -61,3 +61,12 @@ resource "auth0_email_provider" "smtp_email_provider" {
ms365_client_secret = "ms365_client_secret"
}
}

# This is an example on how to set up the email provider with a custom action.
# Make sure a corresponding action exists with custom-email-provider as supported triggers
resource "auth0_email_provider" "custom_email_provider" {
name = "custom"
enabled = true
default_from_address = "[email protected]"
credentials {}
}
6 changes: 1 addition & 5 deletions internal/auth0/action/resource_trigger_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ func NewTriggerActionResource() *schema.Resource {
"post-change-password",
"send-phone-message",
"password-reset-post-challenge",
"iga-approval",
"iga-certification",
"iga-fulfillment-assignment",
"iga-fulfillment-execution",
}, false),
Description: "The ID of the trigger to bind with. Available options: `post-login`, `credentials-exchange`, `pre-user-registration`, `post-user-registration`, `post-change-password`, `send-phone-message`, `password-reset-post-challenge`, `iga-approval`, `iga-certification`, `iga-fulfillment-assignment`, `iga-fulfillment-execution`.",
Description: "The ID of the trigger to bind with. Available options: `post-login`, `credentials-exchange`, `pre-user-registration`, `post-user-registration`, `post-change-password`, `send-phone-message`, `password-reset-post-challenge`.",
},
"action_id": {
Type: schema.TypeString,
Expand Down
7 changes: 1 addition & 6 deletions internal/auth0/action/resource_trigger_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@ func NewTriggerActionsResource() *schema.Resource {
"post-change-password",
"send-phone-message",
"password-reset-post-challenge",
"iga-approval",
"iga-certification",
"iga-fulfillment-assignment",
"iga-fulfillment-execution",
}, false),
Description: "The ID of the trigger to bind with. Options include: `post-login`, `credentials-exchange`, " +
"`pre-user-registration`, `post-user-registration`, `post-change-password`, `send-phone-message`, " +
"`password-reset-post-challenge`, `iga-approval` , `iga-certification` , `iga-fulfillment-assignment`, " +
"`iga-fulfillment-execution`.",
"`password-reset-post-challenge`.",
},
"actions": {
Type: schema.TypeList,
Expand Down
2 changes: 2 additions & 0 deletions internal/auth0/email/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func expandEmailProvider(config cty.Value) *management.EmailProvider {
expandEmailProviderAzureCS(config, emailProvider)
case management.EmailProviderMS365:
expandEmailProviderMS365(config, emailProvider)
case management.EmailProviderCustom:
emailProvider.Credentials = &management.EmailProviderCredentialsCustom{}
}

return emailProvider
Expand Down
2 changes: 2 additions & 0 deletions internal/auth0/email/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func flattenEmailProviderCredentials(data *schema.ResourceData, emailProvider *m
"ms365_client_id": data.Get("credentials.0.ms365_client_id").(string),
"ms365_client_secret": data.Get("credentials.0.ms365_client_secret").(string),
}
case *management.EmailProviderCredentialsCustom:
credentials = map[string]interface{}{}
}

return []interface{}{credentials}
Expand Down
4 changes: 2 additions & 2 deletions internal/auth0/email/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func NewResource() *schema.Resource {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(
[]string{"azure_cs", "mailgun", "mandrill", "ms365", "sendgrid", "ses", "smtp", "sparkpost"},
[]string{"azure_cs", "custom", "mailgun", "mandrill", "ms365", "sendgrid", "ses", "smtp", "sparkpost"},
false,
),
Description: "Name of the email provider. " +
"Options include `azure_cs`, `mailgun`, `mandrill`, `ms365`, `sendgrid`, `ses`, `smtp` and `sparkpost`.",
"Options include `azure_cs`, `custom`, `mailgun`, `mandrill`, `ms365`, `sendgrid`, `ses`, `smtp` and `sparkpost`.",
},
"enabled": {
Type: schema.TypeBool,
Expand Down
34 changes: 34 additions & 0 deletions internal/auth0/email/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,24 @@ resource "auth0_email_provider" "my_email_provider" {
}
`

const testAccCreateCustomEmailProvider = `
resource "auth0_email_provider" "my_email_provider" {
name = "custom"
enabled = true
credentials {}
default_from_address = "[email protected]"
}
`

const testAccUpdateCustomEmailProvider = `
resource "auth0_email_provider" "my_email_provider" {
name = "custom"
enabled = false
default_from_address = "[email protected]"
credentials {}
}
`

const testAccAlreadyConfiguredEmailProviderWillNotConflict = `
resource "auth0_email_provider" "my_email_provider" {
name = "mailgun"
Expand Down Expand Up @@ -343,6 +361,22 @@ func TestAccEmail(t *testing.T) {
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "credentials.0.ms365_client_secret", "ms365_updated_client_secret"),
),
},
{
Config: testAccCreateCustomEmailProvider,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "name", "custom"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "enabled", "true"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "default_from_address", "[email protected]"),
),
},
{
Config: testAccUpdateCustomEmailProvider,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "name", "custom"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "enabled", "false"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "default_from_address", "[email protected]"),
),
},
{
Config: testAccAlreadyConfiguredEmailProviderWillNotConflict,
Check: resource.ComposeTestCheckFunc(
Expand Down
11 changes: 11 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ func ConfigureProvider(terraformVersion *string) schema.ConfigureContextFunc {
audience := data.Get("audience").(string)
debug := data.Get("debug").(bool)

if apiToken == "" && (clientID == "" || clientSecret == "" || domain == "") {
return nil, diag.Diagnostics{
{
Severity: diag.Error,
Summary: "Missing environment variables",
Detail: fmt.Sprintf("Either AUTH0_API_TOKEN or AUTH0_DOMAIN:AUTH0_CLIENT_ID:AUTH0_CLIENT_SECRET must be configured. " +
"Ref: https://registry.terraform.io/providers/auth0/auth0/latest/docs"),
},
}
}

apiClient, err := management.New(domain,
authenticationOption(clientID, clientSecret, apiToken, audience),
management.WithDebug(debug),
Expand Down
7 changes: 4 additions & 3 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestConfigureProvider(t *testing.T) {
name: "it can configure a provider with client credentials",
givenTerraformConfig: map[string]interface{}{
"domain": "example.auth0.com",
"clientID": "1234567",
"client_id": "1234567",
"client_secret": "secret",
},
expectedDiagnostics: nil,
Expand All @@ -34,7 +34,7 @@ func TestConfigureProvider(t *testing.T) {
name: "it can configure a provider with client credentials and audience",
givenTerraformConfig: map[string]interface{}{
"domain": "example.auth0.com",
"clientID": "1234567",
"client_id": "1234567",
"client_secret": "secret",
"audience": "myaudience",
},
Expand All @@ -56,7 +56,8 @@ func TestConfigureProvider(t *testing.T) {
expectedDiagnostics: diag.Diagnostics{
diag.Diagnostic{
Severity: diag.Error,
Summary: "parse \"https://example.com:path\": invalid port \":path\" after host",
Summary: "Missing environment variables",
Detail: "Either AUTH0_API_TOKEN or AUTH0_DOMAIN:AUTH0_CLIENT_ID:AUTH0_CLIENT_SECRET must be configured. Ref: https://registry.terraform.io/providers/auth0/auth0/latest/docs",
},
},
},
Expand Down
28 changes: 1 addition & 27 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package provider

import (
"context"
"fmt"
"os"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/auth0/terraform-provider-auth0/internal/auth0/flow"

"github.com/auth0/terraform-provider-auth0/internal/auth0/form"
Expand Down Expand Up @@ -176,29 +172,7 @@ func New() *schema.Provider {
},
}

provider.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
var diags diag.Diagnostics

// Check required environment variables.
requiredEnvVars := []string{"AUTH0_DOMAIN", "AUTH0_CLIENT_ID", "AUTH0_CLIENT_SECRET"}
for _, varName := range requiredEnvVars {
value, exists := os.LookupEnv(varName)
if !exists || value == "" {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf("Missing environment variable: %s", varName),
Detail: fmt.Sprintf("The environment variable %s must be set and cannot be empty.", varName),
})
}
}

if len(diags) > 0 {
return nil, diags
}

// Call the original configuration function if no errors.
return config.ConfigureProvider(&provider.TerraformVersion)(ctx, d)
}
provider.ConfigureContextFunc = config.ConfigureProvider(&provider.TerraformVersion)

return provider
}
Loading

0 comments on commit 509cf61

Please sign in to comment.