Infrastructure as Code for ACS¶
Automating the deployment of Azure Communication Services using Bicep or Terraform to ensure consistent and reproducible environments.
graph TD
Plan[Plan IaC] --> Define[Define Resources]
Define --> Deploy[Deploy to Azure]
Deploy --> Verify[Verify Deployment]
Verify --> Update[Update and Redeploy] Bicep Template Examples¶
The following Bicep code creates an ACS resource:
resource acsResource 'Microsoft.Communication/communicationServices@2023-04-01-preview' = {
name: 'my-acs-resource'
location: 'Global'
properties: {
dataLocation: 'UnitedStates'
}
}
Bicep Resource Dependencies¶
ACS resources may depend on other resources like Log Analytics for diagnostic logging.
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
name: 'my-log-analytics'
location: 'eastus'
}
resource diagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
name: 'acs-diagnostics'
scope: acsResource
properties: {
workspaceId: logAnalytics.id
logs: [
{
category: 'SmsLogs'
enabled: true
}
{
category: 'EmailLogs'
enabled: true
}
]
}
}
Terraform Provider Configuration¶
To deploy ACS with Terraform, use the azurerm provider.
resource "azurerm_communication_service" "acs" {
name = "my-acs-resource"
resource_group_name = "my-rg"
data_location = "United States"
}
Resource Dependencies and Ordering¶
Terraform automatically handles dependencies between resources. However, you can explicitly define them using depends_on if necessary.
Prerequisites¶
- Azure CLI or Terraform installed, and Contributor on the target resource group.
- A resource group to hold the ACS resource, plus a Log Analytics workspace if you enable diagnostic logging.
- A source-controlled location for the Bicep or Terraform templates.
When to Use¶
- When you need reproducible, reviewable ACS provisioning instead of portal click-ops.
- When promoting the same ACS configuration across dev, test, and production environments.
- When wiring ACS provisioning into a CI/CD pipeline (see GitHub Actions Deployment).
Procedure¶
- Author the template — define the ACS resource with Bicep (see Bicep Template Examples) or Terraform (see Terraform Provider Configuration).
- Wire dependencies — attach diagnostic settings and any Log Analytics workspace as shown in Bicep Resource Dependencies or Resource Dependencies and Ordering.
- Deploy — run the deployment through your IaC tool:
az deployment group createfor Bicep, orterraform applyfor Terraform. - Promote — parameterize environment-specific values so the same template deploys to each environment.
Verification¶
- Confirm the ACS resource exists with the expected
dataLocationand appears in the target resource group. - Confirm diagnostic settings are attached and routing the expected log categories to the workspace.
- Re-run the deployment to confirm it is idempotent — a second apply should report no changes.
Rollback / Troubleshooting¶
- Deployment fails on data location —
dataLocationis immutable after creation; to change it, delete and recreate the resource in a controlled window. - Terraform drift — run
terraform planto detect out-of-band portal changes and reconcile them back into the template. - Need to roll back — redeploy the previous known-good template version from source control rather than editing resources by hand.