Multiuser Executions in Terraform
- Terraform is storing the state in local folders
- Consider the scenario where a terraform template has to be executed by any team member to create a dev environment
- The default location is local folder, the state has to be in common location which is accesible to all team members
- Locking is required for giving access to only one a time
- The above discussed features can be done in terraform with the help of backends
Terraform Backend
- Refer Here for official docs
- As discussed in the class have a look at following backend configuration to use s3 backend
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.68.0"
}
}
backend "s3" {
bucket = "terraformbackendforlt"
key = "demo/terraform.tfstate"
region = "ap-south-1"
dynamodb_table = "myterraformstate"
}
}
provider "aws" {
# Configuration options
}
- Findout how to use azurerm backend, as we have tried in the class the following providers section was used
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "4.3.0"
}
}
backend "azurerm" {
resource_group_name = "terraformstate"
storage_account_name = "lttfstaterepo"
container_name = "state"
key = "demo/terraform.tfstate"
}
}
provider "azurerm" {
# Configuration options
features {
}
}
Handling multiple environments
- Consider the following template

- In this template we have two tfvars with different variable values
- The problem with backend configuration is it is designed to manage only one environment

- To solve the above mentioned problem we will be workspaces with backends