This repository shows you how to use Terraform to manage resources in Azure Government.
Important Note This sample embeds the azurerm provider configuration in the terraform file itself. This isn't a best practice, especially if checking in these files into a source code repository.
-
Create your own copy of terraform-sample.tf
cp terraform-sample.tf.template terraform-sample.tf
-
Log in to Azure Government with the Azure CLI
# Log in az cloud set -n AzureUSGovernment az login
-
Create an Azure AD service principal for Terraform and get all the values required for Terraform to communicate with Azure Government
# Get your subscription SUBSCRIPTION=$(az account show --query id -o tsv) TENANT_ID=$(az account show --query tenantId -o tsv) echo "Subscription: $SUBSCRIPTION" echo "TenantId: $TENANT_ID" # Create an Azure AD Service Principal for Terraform # NOTE: You'll need appId and the password # from the output of this command. az ad sp create-for-rbac -n Terraform -role Contributor -scopes /subscriptions/$SUBSCRIPTION
-
Update the values in the
provider "azure"
section ofterraform-sample.tf
. -
Initialize Terraform
terraform init
-
Deploy to Azure Government using Terraform.
terraform apply