Skip to content

Commit

Permalink
Merge branch 'v1' into feature/DXCDT-492-rp-logout-tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught authored Jul 28, 2023
2 parents c6b912e + 278308d commit c212249
Show file tree
Hide file tree
Showing 7 changed files with 2,295 additions and 1,441 deletions.
32 changes: 31 additions & 1 deletion docs/resources/email_provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@ resource "auth0_email_provider" "sendgrid_email_provider" {
api_key = "secretAPIKey"
}
}
# This is an example on how to set up the email provider with Azure CS.
resource "auth0_email_provider" "smtp_email_provider" {
name = "azure_cs"
enabled = true
default_from_address = "[email protected]"
credentials {
azure_cs_connection_string = "azure_cs_connection_string"
}
}
# This is an example on how to set up the email provider with MS365.
resource "auth0_email_provider" "smtp_email_provider" {
name = "ms365"
enabled = true
default_from_address = "[email protected]"
credentials {
ms365_tenant_id = "ms365_tenant_id"
ms365_client_id = "ms365_client_id"
ms365_client_secret = "ms365_client_secret"
}
}
```

<!-- schema generated by tfplugindocs -->
Expand All @@ -57,7 +83,7 @@ resource "auth0_email_provider" "sendgrid_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 `mailgun`, `mandrill`, `sendgrid`, `ses`, `smtp`, and `sparkpost`.
- `name` (String) Name of the email provider. Options include `azure_cs`, `mailgun`, `mandrill`, `ms365`, `sendgrid`, `ses`, `smtp` and `sparkpost`.

### Optional

Expand All @@ -75,7 +101,11 @@ Optional:

- `access_key_id` (String, Sensitive) AWS Access Key ID. Used only for AWS.
- `api_key` (String, Sensitive) API Key for your email service. Will always be encrypted in our database.
- `azure_cs_connection_string` (String, Sensitive) Azure Communication Services Connection String.
- `domain` (String) Domain name.
- `ms365_client_id` (String, Sensitive) Microsoft 365 Client ID.
- `ms365_client_secret` (String, Sensitive) Microsoft 365 Client Secret.
- `ms365_tenant_id` (String, Sensitive) Microsoft 365 Tenant ID.
- `region` (String) Default region. Used only for AWS, Mailgun, and SparkPost.
- `secret_access_key` (String, Sensitive) AWS Secret Key. Will always be encrypted in our database. Used only for AWS.
- `smtp_host` (String) Hostname or IP address of your SMTP server. Used only for SMTP.
Expand Down
26 changes: 26 additions & 0 deletions examples/resources/auth0_email_provider/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,29 @@ resource "auth0_email_provider" "sendgrid_email_provider" {
api_key = "secretAPIKey"
}
}


# This is an example on how to set up the email provider with Azure CS.
resource "auth0_email_provider" "smtp_email_provider" {
name = "azure_cs"
enabled = true
default_from_address = "[email protected]"

credentials {
azure_cs_connection_string = "azure_cs_connection_string"
}
}


# This is an example on how to set up the email provider with MS365.
resource "auth0_email_provider" "smtp_email_provider" {
name = "ms365"
enabled = true
default_from_address = "[email protected]"

credentials {
ms365_tenant_id = "ms365_tenant_id"
ms365_client_id = "ms365_client_id"
ms365_client_secret = "ms365_client_secret"
}
}
24 changes: 24 additions & 0 deletions internal/auth0/email/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func expandEmailProvider(config cty.Value) *management.EmailProvider {
expandEmailProviderMailgun(config, emailProvider)
case management.EmailProviderSMTP:
expandEmailProviderSMTP(config, emailProvider)
case management.EmailProviderAzureCS:
expandEmailProviderAzureCS(config, emailProvider)
case management.EmailProviderMS365:
expandEmailProviderMS365(config, emailProvider)
}

return emailProvider
Expand Down Expand Up @@ -131,6 +135,26 @@ func expandEmailProviderSMTP(config cty.Value, emailProvider *management.EmailPr
})
}

func expandEmailProviderAzureCS(config cty.Value, emailProvider *management.EmailProvider) {
config.GetAttr("credentials").ForEachElement(func(_ cty.Value, credentials cty.Value) (stop bool) {
emailProvider.Credentials = &management.EmailProviderCredentialsAzureCS{
ConnectionString: value.String(credentials.GetAttr("azure_cs_connection_string")),
}
return stop
})
}

func expandEmailProviderMS365(config cty.Value, emailProvider *management.EmailProvider) {
config.GetAttr("credentials").ForEachElement(func(_ cty.Value, credentials cty.Value) (stop bool) {
emailProvider.Credentials = &management.EmailProviderCredentialsMS365{
TenantID: value.String(credentials.GetAttr("ms365_tenant_id")),
ClientID: value.String(credentials.GetAttr("ms365_client_id")),
ClientSecret: value.String(credentials.GetAttr("ms365_client_secret")),
}
return stop
})
}

func expandEmailTemplate(config cty.Value) *management.EmailTemplate {
emailTemplate := &management.EmailTemplate{
Template: value.String(config.GetAttr("template")),
Expand Down
10 changes: 10 additions & 0 deletions internal/auth0/email/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ func flattenEmailProviderCredentials(d *schema.ResourceData, emailProvider *mana
"smtp_user": credentialsType.GetSMTPUser(),
"smtp_pass": d.Get("credentials.0.smtp_pass").(string),
}
case *management.EmailProviderCredentialsAzureCS:
credentials = map[string]interface{}{
"azure_cs_connection_string": d.Get("credentials.0.azure_cs_connection_string").(string),
}
case *management.EmailProviderCredentialsMS365:
credentials = map[string]interface{}{
"ms365_tenant_id": d.Get("credentials.0.ms365_tenant_id").(string),
"ms365_client_id": d.Get("credentials.0.ms365_client_id").(string),
"ms365_client_secret": d.Get("credentials.0.ms365_client_secret").(string),
}
}

return []interface{}{credentials}
Expand Down
32 changes: 30 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{"mailgun", "mandrill", "sendgrid", "ses", "smtp", "sparkpost"},
[]string{"azure_cs", "mailgun", "mandrill", "ms365", "sendgrid", "ses", "smtp", "sparkpost"},
false,
),
Description: "Name of the email provider. " +
"Options include `mailgun`, `mandrill`, `sendgrid`, `ses`, `smtp`, and `sparkpost`.",
"Options include `azure_cs`, `mailgun`, `mandrill`, `ms365`, `sendgrid`, `ses`, `smtp` and `sparkpost`.",
},
"enabled": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -114,6 +114,34 @@ func NewResource() *schema.Resource {
ValidateFunc: validation.StringIsNotEmpty,
Description: "SMTP password. Used only for SMTP.",
},
"azure_cs_connection_string": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "Azure Communication Services Connection String.",
},
"ms365_tenant_id": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "Microsoft 365 Tenant ID.",
},
"ms365_client_id": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "Microsoft 365 Client ID.",
},
"ms365_client_secret": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
Description: "Microsoft 365 Client Secret.",
},
},
},
},
Expand Down
88 changes: 88 additions & 0 deletions internal/auth0/email/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,54 @@ resource "auth0_email_provider" "my_email_provider" {
}
`

const testAccCreateAzureCSEmailProvider = `
resource "auth0_email_provider" "my_email_provider" {
name = "azure_cs"
enabled = true
default_from_address = "[email protected]"
credentials {
azure_cs_connection_string = "azure_cs_connection_string"
}
}
`

const testAccUpdateAzureCSEmailProvider = `
resource "auth0_email_provider" "my_email_provider" {
name = "azure_cs"
enabled = false
default_from_address = ""
credentials {
azure_cs_connection_string = "azure_cs_updated_connection_string"
}
}
`

const testAccCreateMS365EmailProvider = `
resource "auth0_email_provider" "my_email_provider" {
name = "ms365"
enabled = true
default_from_address = "[email protected]"
credentials {
ms365_tenant_id = "ms365_tenant_id"
ms365_client_id = "ms365_client_id"
ms365_client_secret = "ms365_client_secret"
}
}
`

const testAccUpdateMS365EmailProvider = `
resource "auth0_email_provider" "my_email_provider" {
name = "ms365"
enabled = false
default_from_address = ""
credentials {
ms365_tenant_id = "ms365_updated_tenant_id"
ms365_client_id = "ms365_updated_client_id"
ms365_client_secret = "ms365_updated_client_secret"
}
}
`

const testAccAlreadyConfiguredEmailProviderWillNotConflict = `
resource "auth0_email_provider" "my_email_provider" {
name = "mailgun"
Expand Down Expand Up @@ -255,6 +303,46 @@ func TestAccEmail(t *testing.T) {
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "credentials.0.region", "eu"),
),
},
{
Config: testAccCreateAzureCSEmailProvider,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "name", "azure_cs"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "enabled", "true"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "default_from_address", "[email protected]"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "credentials.0.azure_cs_connection_string", "azure_cs_connection_string"),
),
},
{
Config: testAccUpdateAzureCSEmailProvider,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "name", "azure_cs"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "enabled", "false"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "default_from_address", ""),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "credentials.0.azure_cs_connection_string", "azure_cs_updated_connection_string"),
),
},
{
Config: testAccCreateMS365EmailProvider,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "name", "ms365"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "enabled", "true"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "default_from_address", "[email protected]"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "credentials.0.ms365_tenant_id", "ms365_tenant_id"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "credentials.0.ms365_client_id", "ms365_client_id"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "credentials.0.ms365_client_secret", "ms365_client_secret"),
),
},
{
Config: testAccUpdateMS365EmailProvider,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "name", "ms365"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "enabled", "false"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "default_from_address", ""),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "credentials.0.ms365_tenant_id", "ms365_updated_tenant_id"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "credentials.0.ms365_client_id", "ms365_updated_client_id"),
resource.TestCheckResourceAttr("auth0_email_provider.my_email_provider", "credentials.0.ms365_client_secret", "ms365_updated_client_secret"),
),
},
{
Config: testAccAlreadyConfiguredEmailProviderWillNotConflict,
Check: resource.ComposeTestCheckFunc(
Expand Down
Loading

0 comments on commit c212249

Please sign in to comment.