This guide provides step-by-step instructions for deploying the Azure infrastructure using Terraform and Bicep.
-
Azure CLI (>= 2.0)
az --version
Install: https://docs.microsoft.com/cli/azure/install-azure-cli
-
Terraform (>= 1.0)
terraform version
Install: https://www.terraform.io/downloads
-
Bicep CLI (>= 0.4)
az bicep version
Install: https://learn.microsoft.com/azure/azure-resource-manager/bicep/install
- Contributor or Owner role on the subscription
- Permissions to create resource groups and resources
az login# List subscriptions
az account list --output table
# Set active subscription
az account set --subscription "<subscription-id>"git clone <repository-url>
cd testRepo01cd terraform/resource-groups/data-platformEdit variables.tf or create a terraform.tfvars file:
# terraform.tfvars
environment = "dev"
location = "eastus"
project_name = "dataplatform"
tags = {
Environment = "dev"
ManagedBy = "Terraform"
Project = "DataPlatform"
}terraform initThis will:
- Download required providers
- Initialize backend
- Validate configuration
terraform plan -out=tfplanReview the plan carefully to understand what will be created.
terraform apply tfplanOr apply directly:
terraform applyEnter yes when prompted.
terraform outputTo get specific output:
terraform output storage_account_nameFor team environments, configure remote state:
# backend.tf
terraform {
backend "azurerm" {
resource_group_name = "tfstate-rg"
storage_account_name = "tfstate123"
container_name = "tfstate"
key = "dataplatform.terraform.tfstate"
}
}cd bicep/resource-groups/data-platformEdit main.parameters.json:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"value": "dev"
},
"location": {
"value": "eastus"
},
"projectName": {
"value": "dataplatform"
}
}
}az deployment sub validate \
--location eastus \
--template-file main.bicep \
--parameters main.parameters.jsonaz deployment sub what-if \
--location eastus \
--template-file main.bicep \
--parameters main.parameters.jsonSubscription-level deployment:
az deployment sub create \
--location eastus \
--template-file main.bicep \
--parameters main.parameters.json \
--name dataplatform-deploymentResource group deployment (if resource group exists):
az deployment group create \
--resource-group rg-dataplatform-dev \
--template-file main.bicep \
--parameters main.parameters.jsonaz deployment sub show \
--name dataplatform-deployment \
--query properties.outputs# List resources in resource group
az resource list \
--resource-group rg-dataplatform-dev \
--output table# Get function app URL
func_url=$(terraform output -raw function_app_url)
echo "Function App URL: $func_url"
# Test endpoint
curl https://${func_url}# Get Application Insights details
az monitor app-insights component show \
--app appi-dataplatform-dev \
--resource-group rg-dataplatform-devIf using Key Vault, grant access to your identity:
# Get your object ID
object_id=$(az ad signed-in-user show --query id -o tsv)
# Set access policy
az keyvault set-policy \
--name kv-dataplatform-dev \
--object-id $object_id \
--secret-permissions get list set deleteAdd your IP to SQL Server firewall:
# Get your public IP
my_ip=$(curl -s https://api.ipify.org)
# Add firewall rule
az sql server firewall-rule create \
--resource-group rg-dataplatform-dev \
--server sql-dataplatform-dev \
--name AllowMyIP \
--start-ip-address $my_ip \
--end-ip-address $my_ipError:
The storage account name 'stdataplatformdev' is already taken.
Solution: Add a unique suffix to the storage account name:
storage_account_name = "st${var.project_name}${var.environment}${random_string.suffix.result}"Error:
Authorization failed for user
Solution:
- Verify you have Contributor or Owner role
- Check subscription is correct:
az account show
Error:
The subscription is not registered to use namespace 'Microsoft.Storage'
Solution:
az provider register --namespace Microsoft.Storage
az provider register --namespace Microsoft.Web
az provider register --namespace Microsoft.Logic
az provider register --namespace Microsoft.Sql
az provider register --namespace Microsoft.DocumentDB
az provider register --namespace Microsoft.KeyVaultError:
Error acquiring the state lock
Solution:
- Wait for other operations to complete
- If stuck, manually break lock (use with caution):
terraform force-unlock <lock-id>
Error:
Unable to compile Bicep file
Solution:
- Update Bicep CLI:
az bicep upgrade - Validate syntax:
az bicep build --file main.bicep
cd terraform/resource-groups/data-platform
terraform destroy# Delete resource group
az group delete --name rg-dataplatform-dev --yes --no-wait# Check if resource group still exists
az group exists --name rg-dataplatform-dev- Configure CI/CD pipelines for automated deployments
- Implement environment-specific configurations
- Add monitoring and alerting
- Set up backup and disaster recovery
- Implement security best practices
- Review and optimize costs
For issues or questions:
- Check the documentation
- Review example configurations
- Consult Azure documentation
- Open an issue in the repository