WWW Coachdevops Co...
WWW Coachdevops Co...
                                                                                                                                             Search
How to store Terraform state file in Azure Storage | How to
manage Terraform state in Azure Blob Storage | Terraform                                                Contact the Coach
Remote state in Azure Blob storage | Terraform backend                                                    Click To Register for a Devops and Cloud
                                                                                                          Course
One of the amazing features of Terraform is, it tracks the infrastructure that you provision. It does
                                                                                                          Join WhatsApp Group for Course Enquiry
this through the means of state. By default, Terraform stores state information locally in a file
                                                                                                          DevOps Bootcamp Schedule
named terraform.tfstate. This does not work well in a team environment where if any
                                                                                                          About the Coach & Coaching Model
developer wants to make a change he needs to make sure nobody else is updating terraform in
the same time. You need to use remote storage to store state file.
                                                                                                        Contributors
With remote state, Terraform writes the state data to a remote data store, which can then be
shared between all members of a team. Terraform supports storing state in many ways including                    Amy
the below:                                                                                                       Amy
     HashiCorp Consul
     Amazon S3                                                                                          Blog Archive
     Azure Blob Storage
                                                                                                        ►
                                                                                                        ► 2024 (43)
     Google Cloud Storage
                                                                                                        ►
                                                                                                        ► 2023 (62)
     Alibaba Cloud OSS
                                                                                                        ▼
                                                                                                        ▼ 2022 (42)
     Artifactory or Nexus
                                                                                                          ►
                                                                                                          ► December (3)
We will learn how to store state file in Azure Blob storage. We will be creating Azure storage            ►
                                                                                                          ► November (3)
account and container.
                                                                                                          ►
                                                                                                          ► October (2)
                                                                                                          ►
                                                                                                          ► September (6)
                                                                                                          ►
                                                                                                          ► August (4)
                                                                                                          ►
                                                                                                          ► July (2)
                                                                                                          ►
                                                                                                          ► June (1)
                                                                                                          ►
                                                                                                          ► May (10)
                                                                                                          ►
                                                                                                          ► April (1)
                                                                                                          ▼
                                                                                                          ▼ March (2)
                                                                                                            Install Jenkins on Ubuntu 22.0.4 using
                                                                                                               Docker Comp...
                                                                                                             How to store Terraform state file in Azure
                                                                                                               Storage...
                                                                                                          ►
                                                                                                          ► February (2)
                                                                                                          ►
                                                                                                          ► January (6)
                                                                                                        ►
                                                                                                        ► 2021 (52)
                                                                                                        ►
                                                                                                        ► 2020 (81)
                                                                                                        ►
                                                                                                        ► 2019 (51)
                                                                                                        ►
                                                                                                        ► 2018 (12)
                                                                                                        Labels
Watch the steps in YouTube channel:                                                                       ACR
                                                                              Admin password
              How to store Terraform state file in Azure Storage |…
                                                                 |…           AKS
                                                                      Share
                                                                              Ansible
                                                                              Ansible Roles
                                                                              Apache
                                                                              Appservice
                                                                              Appservices
                                                                              Artifactory
                                                                              Automation
                                                                              AWS
                                                                              AWS CLI
                                                                              Azure
                                                                              Azure App Service
    }                                                                         Code Quality
}                                                                             Container Registry
                                                                              Containers
provider "azurerm" {                                                          create VM in Azure
    features {}                                                               Declarative
}                                                                             DevOp coaching schedule
                                                                              DevOps
resource "azurerm_resource_group" "demo-rg" {
                                                                              Devops Best Practices
    name         = "demo-resource-group"
                                                                              DevOps BootCamp
    location = "eastus"
                                                                              DevOps Coaching
}
                                                                              DevOps coaching in Plano Frisco area
                                                                              DevOps Coaching Plano
                                                                              DevOps interview Prep
                                                                              DevOps Interview Questions
terraform init
                                                                              DevOps Interview Tips
terraform plan                                                                DevOps Skills
this will show it will create one resource                                    DevOps Tips
                                                                              DevOps Tools
                                                                              DevOps Training
                                                                              DevOps Training Dallas
                                                                              DevOps Training Frisco
                                                                              Devops Training in Dallas
                                                                              DevOps Troubleshooting
                                                                              Dock
                                                                              Docker
                                                                              Docker Compose
                                                                              Docker Registry
                                                                              DockerHub
                                                                              EC2
                                                                              EC2 bootstrap
                                                                                               Ec2 Creation
terraform apply                                                                                EC2 instance
Now this will create a local terraform state file in your machine.                             ECR
                                                                                               EKS
                                                                                               eksctl
                                                                                               Elastic IP
                                                                                               Freestyle job CICD
                                                                                               Git
                                                                                               GitHub
                                                                                               GitHub Actions
                                                                                               GitHub Runners
                                                                                               GitLab
                                                                                               Grafana
                                                                                               Helm
                                                                                               Helm3
                                                                                               How to connect to EC2 instance
                                                                                               IAC
How to store Terraform state file remotely?
                                                                                               IAM
Step # 1 - Configure Azure storage account
                                                                                               Infrastructure
Before you use Azure Storage as a backend, you must create a storage account. We will create   Infrastructure Automation
using shell script:                                                                            Install Nexus on Ubuntu
                                                                                               install terraform
#!/bin/bash
                                                                                               Integrate ACR with AKS
RESOURCE_GROUP_NAME=tfstate
STORAGE_ACCOUNT_NAME=tfstate$RANDOM                                                            Java
CONTAINER_NAME=tfstate                                                                         Jenkins
# Create resource group
                                                                                               Jenkins integration
az group create --name $RESOURCE_GROUP_NAME --location eastus
# Create storage account                                                                       Jenkins pipeline
az storage account create --resource-group $RESOURCE_GROUP_NAME --name                         Jenkins Pipelines
$STORAGE_ACCOUNT_NAME --sku Standard_LRS --encryption-services blob
# Create blob container                                                                        JFrog
az storage container create --name $CONTAINER_NAME --account-name                              K8S
$STORAGE_ACCOUNT_NAME                                                                          kubectl
This should have created resource group, storage account and container in Azure portal.        Kubernetes
                                                                                               Kubernetes Error
                                                                                               LAMP
                                                                                               Linux
                                                                                               MAC OS
                                                                                               MacOS
                                                                                               Master slave setup
                                                                                               Maven
                                                                                               MFA
                                                                                               Microservices
                                                                                               Migration
                                                                                               Monitoring
                                                                                               Nexus
                                                                                               Nexus 3
                                                                                               Nexus3
                                                                                               Parallelism
                                                                                               Password Reset for SonarQube
                                                                                               PHP
Step # 2 - Configure terraform backend state
                                                                                               Pipeline
                                                                                               Pipelines
To configure the backend state, you need the following Azure storage
                                                                                               Playbooks
information which we created above:
                                                                                               Plug-ins
                                                                                               Postgres
       resource_group_name: name of the resource group under which all
                                                                                               PR
       resources will be created.
                                                                                               Prerequisites
       storage_account_name: The name of the Azure Storage account.                            Prometheus
       container_name: The name of the blob container.                                         Puppet
       key: The name of the state store file to be created.                                    Puppet Agent on Ubuntu
                                                                                               Puppet Master
Create backend.tf file
                                                                                               Puppet Modules
We need to create a backend file.
                                                                                               Puppet7
terraform {                                                                                    Python
    backend "azurerm" {                                                                        QualityGate
        resource_group_name = "tfstate"                                                        Red Hat
        storage_account_name = "<storage_acct_name>"                                           Red Hat Linux
           container_name              = "tfstate"                                                      Redhat
           key                         = "terraform.tfstate"
                                                                                                        RedHat Linux
     }
                                                                                                        remote state
}
                                                                                                        S3
                                                                                                        S3 Bucket
terraform init --reconfigure
                                                                                                        SCM
                                                                                                        Security
                                                                                                        Shell Script
                                                                                                        Slack
                                                                                                        Slave
                                                                                                        Slaves
type yes                                                                                                Sonarqube
                                                                                                        Springboot
                                                                                                        SQL
                                                                                                        SSH
                                                                                                        Teamcity
                                                                                                        Terraform
                                                                                                        Terraform import
                                                                                                        terraform install
                                                                                                        Terrraform
                                                                                                        Tomcat
                                                                                                        Tomcat8
                                                                                                        Tomcat9
This should have created backend file called terraform.tfstate in a container inside azure storage.     Troubleshooting
                                                                                                        Ubuntu
                                                                                                        Ubuntu 18.0.4
                                                                                                        Ubuntu 20.0.4
                                                                                                        Ubuntu 22.0.4
                                                                                                        Ubuntu 24.0.4
                                                                                                        Ubuntu18.0.4
                                                                                                        Ubuntu22.0.4
                                                                                                        Visual Studio Code
                                                                                                        VSCode
                                                                                                        VSTS
                                                                                                        WebApp
                                                                                                        Webhooks
                                                                                                        windows
                                                                                                        YAML
You can view remote state file info:
Report Abuse
YouTube 21K
                                                                                                      Followers               Clustrmaps
                                                                                                      Followers (144)          14,225 Pageviews
                                                                                                      Next                      Sep. 27th - Oct.
                                                                                                                                     27th
This is how you can store terraform state information remotely in Azure storage.
terraform plan
Popular Posts