Skip to content

Commit

Permalink
Added support for Custom Email Provider (#1064)
Browse files Browse the repository at this point in the history
* Added support for custom email provider

* bump

* bump

* Dummy
  • Loading branch information
duedares-rvj authored Oct 31, 2024
1 parent 4a0e957 commit c9e8550
Show file tree
Hide file tree
Showing 9 changed files with 594 additions and 303 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
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 {}
}
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
Loading

0 comments on commit c9e8550

Please sign in to comment.