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 2, 2024
1 parent 7bd124f commit 2d7880d
Show file tree
Hide file tree
Showing 33 changed files with 2,095 additions and 2 deletions.
9 changes: 9 additions & 0 deletions internal/services/communication/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"

"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/go-azure-sdk/resource-manager/communication/2023-03-31/emailservices"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)
Expand All @@ -15,6 +16,7 @@ type Client struct {
ServiceClient *communicationservices.CommunicationServicesClient

EmailServicesClient *emailservices.EmailServicesClient
DomainClient *domains.DomainsClient
}

func NewClient(o *common.ClientOptions) (*Client, error) {
Expand All @@ -30,8 +32,15 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
}
o.Configure(emailServicesClient.Client, o.Authorizers.ResourceManager)

domainsClient, err := domains.NewDomainsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Domain Service client: %+v", err)
}
o.Configure(domainsClient.Client, o.Authorizers.ResourceManager)

return &Client{
ServiceClient: servicesClient,
EmailServicesClient: emailServicesClient,
DomainClient: domainsClient,
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type CommunicationServiceResourceModel struct {
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
DataLocation string `tfschema:"data_location"`
LinkedDomains []string `tfschema:"linked_domains"`
Tags map[string]string `tfschema:"tags"`

PrimaryConnectionString string `tfschema:"primary_connection_string"`
Expand Down Expand Up @@ -146,7 +147,8 @@ func (r CommunicationServiceResource) Create() sdk.ResourceFunc {
// The location is always `global` from the Azure Portal
Location: location.Normalize("global"),
Properties: &communicationservices.CommunicationServiceProperties{
DataLocation: model.DataLocation,
DataLocation: model.DataLocation,
LinkedDomains: pointer.To(model.LinkedDomains),
},
Tags: pointer.To(model.Tags),
}
Expand Down Expand Up @@ -191,6 +193,10 @@ func (r CommunicationServiceResource) Update() sdk.ResourceFunc {
props.DataLocation = model.DataLocation
}

if metadata.ResourceData.HasChange("linked_domains") {
props.LinkedDomains = pointer.To(model.LinkedDomains)
}

existing.Model.Properties = &props

if metadata.ResourceData.HasChange("tags") {
Expand Down Expand Up @@ -239,6 +245,7 @@ func (CommunicationServiceResource) Read() sdk.ResourceFunc {
if model := resp.Model; model != nil {
if props := model.Properties; props != nil {
state.DataLocation = props.DataLocation
state.LinkedDomains = pointer.From(props.LinkedDomains)
}

state.Tags = pointer.From(model.Tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,25 @@ func (r CommunicationServiceTestResource) complete(data acceptance.TestData) str
return fmt.Sprintf(`
%s
resource "azurerm_email_communication_service" "test" {
name = "acctest-CommunicationService-%[2]d"
resource_group_name = azurerm_resource_group.test.name
data_location = "United States"
}
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
}
resource "azurerm_communication_service" "test" {
name = "acctest-CommunicationService-%d"
name = "acctest-CommunicationService-%[2]d"
resource_group_name = azurerm_resource_group.test.name
data_location = "United States"
linked_domains = [azurerm_email_communication_service_domain.test.id]
tags = {
env = "Test"
Expand Down
Loading

0 comments on commit 2d7880d

Please sign in to comment.