Skip to content

Commit

Permalink
New Resource: azurerm_email_communication_service_domain
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Jun 3, 2024
1 parent ae6e9b8 commit 9ca3017
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 37 deletions.
10 changes: 10 additions & 0 deletions internal/services/communication/communication_service_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/communication/2023-03-31/communicationservices"
"github.com/hashicorp/go-azure-sdk/resource-manager/communication/2023-03-31/domains"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/communication/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/communication/validate"
Expand Down Expand Up @@ -84,6 +85,15 @@ func (CommunicationServiceResource) Arguments() map[string]*pluginsdk.Schema {
}, false),
},

"linked_domains": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: domains.ValidateDomainID,
},
},

"tags": commonschema.Tags(),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,9 @@ resource "azurerm_email_communication_service" "test" {
}
resource "azurerm_email_communication_service_domain" "test" {
name = azurerm_email_communication_service_domain.test.name
resource_group_name = azurerm_email_communication_service_domain.test.resource_group_name
email_service_name = azurerm_email_communication_service_domain.test.email_service_name
domain_management = azurerm_email_communication_service_domain.test.domain_management
name = "AzureManagedDomain"
email_service_id = azurerm_email_communication_service.test.id
domain_management = "AzureManaged"
}
resource "azurerm_communication_service" "test" {
Expand Down
41 changes: 21 additions & 20 deletions internal/services/communication/email_service_domain_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/communication/2023-03-31/domains"
"github.com/hashicorp/go-azure-sdk/resource-manager/communication/2023-03-31/emailservices"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/communication/helper"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/communication/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
)
Expand All @@ -25,12 +25,11 @@ var _ sdk.ResourceWithUpdate = EmailCommunicationServiceDomainResource{}
type EmailCommunicationServiceDomainResource struct{}

type EmailCommunicationServiceDomainResourceModel struct {
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
EMailServiceName string `tfschema:"email_service_name"`
DomainManagement string `tfschema:"domain_management"`
UserEngagementTracking bool `tfschema:"user_engagement_tracking"`
Tags map[string]string `tfschema:"tags"`
Name string `tfschema:"name"`
EMailServiceID string `tfschema:"email_service_id"`
DomainManagement string `tfschema:"domain_management"`
UserEngagementTrackingEnabled bool `tfschema:"user_engagement_tracking_enabled"`
Tags map[string]string `tfschema:"tags"`

FromSenderDomain string `tfschema:"from_sender_domain"`
MailFromSenderDomain string `tfschema:"mail_from_sender_domain"`
Expand All @@ -53,13 +52,11 @@ func (EmailCommunicationServiceDomainResource) Arguments() map[string]*pluginsdk
ForceNew: true,
},

"resource_group_name": commonschema.ResourceGroupName(),

"email_service_name": {
"email_service_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.CommunicationServiceName,
ValidateFunc: domains.ValidateEmailServiceID,
},

"domain_management": {
Expand All @@ -69,10 +66,10 @@ func (EmailCommunicationServiceDomainResource) Arguments() map[string]*pluginsdk
ValidateFunc: validation.StringInSlice(domains.PossibleValuesForDomainManagement(), false),
},

"user_engagement_tracking": {
"user_engagement_tracking_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
Default: false,
},

"tags": commonschema.Tags(),
Expand Down Expand Up @@ -127,7 +124,12 @@ func (r EmailCommunicationServiceDomainResource) Create() sdk.ResourceFunc {
return err
}

id := domains.NewDomainID(subscriptionId, model.ResourceGroupName, model.EMailServiceName, model.Name)
eMailServiceID, err := emailservices.ParseEmailServiceID(model.EMailServiceID)
if err != nil {
return fmt.Errorf("parsing parent email_service_id: %+v", err)
}

id := domains.NewDomainID(subscriptionId, eMailServiceID.ResourceGroupName, eMailServiceID.EmailServiceName, model.Name)

existing, err := client.Get(ctx, id)
if err != nil && !response.WasNotFound(existing.HttpResponse) {
Expand All @@ -142,7 +144,7 @@ func (r EmailCommunicationServiceDomainResource) Create() sdk.ResourceFunc {
}

properties.UserEngagementTracking = pointer.To(domains.UserEngagementTrackingDisabled)
if model.UserEngagementTracking {
if model.UserEngagementTrackingEnabled {
properties.UserEngagementTracking = pointer.To(domains.UserEngagementTrackingEnabled)
}

Expand Down Expand Up @@ -190,9 +192,9 @@ func (r EmailCommunicationServiceDomainResource) Update() sdk.ResourceFunc {

props := pointer.From(domain.Properties)

if metadata.ResourceData.HasChange("user_engagement_tracking") {
if metadata.ResourceData.HasChange("user_engagement_tracking_enabled") {
userEngagementTracking := domains.UserEngagementTrackingDisabled
if model.UserEngagementTracking {
if model.UserEngagementTrackingEnabled {
userEngagementTracking = domains.UserEngagementTrackingEnabled
}

Expand Down Expand Up @@ -237,8 +239,7 @@ func (EmailCommunicationServiceDomainResource) Read() sdk.ResourceFunc {
}

state.Name = id.DomainName
state.ResourceGroupName = id.ResourceGroupName
state.EMailServiceName = id.EmailServiceName
state.EMailServiceID = emailservices.NewEmailServiceID(id.SubscriptionId, id.ResourceGroupName, id.EmailServiceName).ID()

if model := resp.Model; model != nil {
if props := model.Properties; props != nil {
Expand All @@ -249,7 +250,7 @@ func (EmailCommunicationServiceDomainResource) Read() sdk.ResourceFunc {
state.MailFromSenderDomain = pointer.From(props.MailFromSenderDomain)

if props.UserEngagementTracking != nil {
state.UserEngagementTracking = *props.UserEngagementTracking == domains.UserEngagementTrackingEnabled
state.UserEngagementTrackingEnabled = *props.UserEngagementTracking == domains.UserEngagementTrackingEnabled

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ func (r EmailServiceDomainTestResource) basic(data acceptance.TestData) string {
resource "azurerm_email_communication_service_domain" "test" {
name = "AzureManagedDomain"
resource_group_name = azurerm_resource_group.test.name
email_service_name = azurerm_email_communication_service.test.name
email_service_id = azurerm_email_communication_service.test.id
domain_management = "AzureManaged"
}
Expand All @@ -111,8 +110,7 @@ func (r EmailServiceDomainTestResource) requiresImport(data acceptance.TestData)
resource "azurerm_email_communication_service_domain" "import" {
name = azurerm_email_communication_service_domain.test.name
resource_group_name = azurerm_email_communication_service_domain.test.resource_group_name
email_service_name = azurerm_email_communication_service_domain.test.email_service_name
email_service_id = azurerm_email_communication_service_domain.test.email_service_id
domain_management = azurerm_email_communication_service_domain.test.domain_management
}
Expand All @@ -125,11 +123,10 @@ func (r EmailServiceDomainTestResource) complete(data acceptance.TestData, userT
resource "azurerm_email_communication_service_domain" "test" {
name = "example.com"
resource_group_name = azurerm_resource_group.test.name
email_service_name = azurerm_email_communication_service.test.name
email_service_id = azurerm_email_communication_service.test.id
domain_management = "CustomerManaged"
user_engagement_tracking = %s
domain_management = "CustomerManaged"
user_engagement_tracking_enabled = %s
tags = {
env = "Test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ The following arguments are supported:

* `name` - (Required) The name of the Email Communication Service resource. If `domain_management` is `AzureManaged`, the name must be `AzureManagedDomain`. Changing this forces a new Email Communication Service to be created.

* `resource_group_name` - (Required) The name of the Resource Group where the Email Communication Service should exist. Changing this forces a new Email Communication Service to be created.

* `email_service_name` - (Required) The name of the Email Communication Service where the Domain belongs to. Changing this forces a new Email Communication Service to be created.
* `email_service_id` - (Required) The resource ID of the Email Communication Service where the Domain belongs to. Changing this forces a new Email Communication Service to be created.

* `domain_management` - (Required) Describes how a Domains resource is being managed. Possible values are `AzureManaged`, `CustomerManaged`, `CustomerManagedInExchangeOnline`. Changing this forces a new Email Communication Service to be created.

---

* `user_engagement_tracking` - (Optional) Describes user engagement tracking is enabled or disabled.
* `user_engagement_tracking_enabled` - (Optional) Describes user engagement tracking is enabled or disabled. Defaults to `false`.

* `tags` - (Optional) A mapping of tags which should be assigned to the Email Communication Service.

Expand Down

0 comments on commit 9ca3017

Please sign in to comment.