Difference between revisions of "Azure/Terraform"
< Azure
Jump to navigation
Jump to search
| Line 9: | Line 9: | ||
STORAGE_ACCOUNT_NAME=tfstate${ARM_SUBSCRIPTION::8} | STORAGE_ACCOUNT_NAME=tfstate${ARM_SUBSCRIPTION::8} | ||
CONTAINER_NAME=tfstate | CONTAINER_NAME=tfstate | ||
REGION=eastus | |||
# Create resource group | # Create resource group | ||
az group create --name $RESOURCE_GROUP_NAME --location | az group create --name $RESOURCE_GROUP_NAME --location $REGION | ||
# Create storage account | # Create storage account | ||
az storage account create --resource-group $RESOURCE_GROUP_NAME --name $STORAGE_ACCOUNT_NAME --sku Standard_LRS --encryption-services blob | az storage account create --resource-group $RESOURCE_GROUP_NAME --name $STORAGE_ACCOUNT_NAME \ | ||
--sku Standard_LRS --encryption-services blob | |||
# Get storage account key | # Get storage account key | ||
Revision as of 20:30, 6 January 2019
Store Terraform state in Azure Storage
Create blob storage
export ARM_SUBSCRIPTION=aabbccdd-1122-11aa22bb3-11aa22bb33cc
#!/bin/bash
RESOURCE_GROUP_NAME=tfstate
STORAGE_ACCOUNT_NAME=tfstate${ARM_SUBSCRIPTION::8}
CONTAINER_NAME=tfstate
REGION=eastus
# Create resource group
az group create --name $RESOURCE_GROUP_NAME --location $REGION
# Create storage account
az storage account create --resource-group $RESOURCE_GROUP_NAME --name $STORAGE_ACCOUNT_NAME \
--sku Standard_LRS --encryption-services blob
# Get storage account key
ACCOUNT_KEY=$(az storage account keys list --resource-group $RESOURCE_GROUP_NAME --account-name $STORAGE_ACCOUNT_NAME --query [0].value -o tsv)
# Create blob container
az storage container create --name $CONTAINER_NAME --account-name $STORAGE_ACCOUNT_NAME --account-key $ACCOUNT_KEY
echo "storage_account_name: $STORAGE_ACCOUNT_NAME"
echo "container_name: $CONTAINER_NAME"
echo "access_key: $ACCOUNT_KEY"
References
- Store Terraform state in Azure Storage official Ms docs
- azurerm Terraform backend official Terraform doc