From 9ca3017c15d185e837132562f9281b5ca1ac59c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Mon, 3 Jun 2024 21:23:04 +0200 Subject: [PATCH] New Resource: `azurerm_email_communication_service_domain` --- .../communication_service_resource.go | 10 +++++ .../communication_service_resource_test.go | 8 ++-- .../email_service_domain_resource.go | 41 ++++++++++--------- .../email_service_domain_resource_test.go | 13 +++--- ...communication_service_domain.html.markdown | 6 +-- 5 files changed, 41 insertions(+), 37 deletions(-) diff --git a/internal/services/communication/communication_service_resource.go b/internal/services/communication/communication_service_resource.go index 61b20a7cbf49..e4fbdbcfd593 100644 --- a/internal/services/communication/communication_service_resource.go +++ b/internal/services/communication/communication_service_resource.go @@ -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" @@ -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(), } } diff --git a/internal/services/communication/communication_service_resource_test.go b/internal/services/communication/communication_service_resource_test.go index 60f16440afd4..0b1e11c5137b 100644 --- a/internal/services/communication/communication_service_resource_test.go +++ b/internal/services/communication/communication_service_resource_test.go @@ -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" { diff --git a/internal/services/communication/email_service_domain_resource.go b/internal/services/communication/email_service_domain_resource.go index 4b4cec685bbf..99e43e14f8a7 100644 --- a/internal/services/communication/email_service_domain_resource.go +++ b/internal/services/communication/email_service_domain_resource.go @@ -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" ) @@ -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"` @@ -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": { @@ -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(), @@ -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) { @@ -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) } @@ -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 } @@ -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 { @@ -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 } diff --git a/internal/services/communication/email_service_domain_resource_test.go b/internal/services/communication/email_service_domain_resource_test.go index af8b202c2af3..6a7f508a4d69 100644 --- a/internal/services/communication/email_service_domain_resource_test.go +++ b/internal/services/communication/email_service_domain_resource_test.go @@ -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" } @@ -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 } @@ -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" diff --git a/website/docs/r/email_communication_service_domain.html.markdown b/website/docs/r/email_communication_service_domain.html.markdown index d646c6a6c645..962f716e0f53 100644 --- a/website/docs/r/email_communication_service_domain.html.markdown +++ b/website/docs/r/email_communication_service_domain.html.markdown @@ -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.