Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Terraform Backend Tutorial

Terraform is a popular open-source infrastructure as code tool used to create and manage infrastructure resources. The state of the infrastructure resources managed by Terraform is stored in a backend, which can be a remote storage location such as Amazon S3.

To configure Terraform to use an S3 backend, you will need to perform the following steps:

  1. Create an S3 bucket – create a new S3 bucket or use an existing one for storing the Terraform state file.
  2. Create an S3 access key – generate an access key and secret key with the appropriate permissions for accessing the S3 bucket.
  3. Configure Terraform backend – add the following code block to your Terraform configuration file, replacing the values with your specific S3 bucket and access key information:

List of Terraform Backends Options (May 2026)

#Terraform BackendSupported in latest Terraform v1.15.x May 2026Used For / Cloud
1localYesLocal machine state file
2remoteYesHCP Terraform / Terraform Enterprise
3s3YesAWS S3 remote state
4azurermYesAzure Storage Account backend
5gcsYesGoogle Cloud Storage backend
6consulYesHashiCorp Consul state backend
7cosYesTencent Cloud Object Storage
8httpYesGeneric HTTP remote backend
9kubernetesYesKubernetes Secret-based state
10ociYesOracle Cloud Infrastructure Object Storage
11ossYesAlibaba Cloud Object Storage Service
12pgYesPostgreSQL backend

Terraform uses backends to determine how the state is loaded and how an operation such as apply is executed. The backend configuration can control where the state is stored and how the operations are executed.

Here’s a list of commonly used Terraform backends:

  1. Local:
    • Stores state on the local filesystem.
    • Executes operations locally.
  2. Remote:
    • Uses the Terraform Cloud to store state and optionally execute operations.
    • It’s the default backend for Terraform Cloud workspaces.
  3. Consul:
    • Stores the state in Consul’s key/value store.
    • Executes operations locally.
  4. AzureRM:
    • Stores the state in an Azure Storage Blob.
    • Executes operations locally.
  5. S3:
    • Stores state in an Amazon S3 bucket.
    • It can use DynamoDB for state locking and consistency.
    • Executes operations locally.
  6. Google Cloud Storage (GCS):
    • Stores state in a Google Cloud Storage bucket.
    • Executes operations locally.
  7. Swift:
    • Stores state in OpenStack Swift.
    • Executes operations locally.
  8. Artifactory:
    • Stores state in JFrog Artifactory.
    • Executes operations locally.
  9. Etcd V2 & V3:
    • Store the state in Etcd’s key/value store.
    • Executes operations locally.
  10. Manta:
  • Stores the state in Joyent’s Manta service.
  • Executes operations locally.
  1. OSS:
  • Stores state in Alibaba Cloud Object Storage Service.
  • Executes operations locally.
  1. Pg:
  • Stores state within a configured PostgreSQL database.
  • Executes operations locally.
  1. Kubernetes:
  • Stores state within a Kubernetes Secret.
  • Executes operations locally.

terraform {
  backend "s3" {
    bucket = "your-bucket-name"
    key    = "path/to/terraform.tfstate"
    region = "your-aws-region"
    access_key = "your-access-key"
    secret_key = "your-secret-key"
  }
}Code language: JavaScript (javascript)

Initialize the backend – run the terraform init command to initialize the backend configuration and create the state file in the S3 bucket.


terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
  backend "s3" {
    bucket = "art54654654546546456"
    key    = "aug"
    region = "ap-south-1"
	access_key = ""
    secret_key = ""
  }
}


# Configure the AWS Provider
provider "aws" {
  region = "ap-south-1"
  access_key = ""
  secret_key = ""
}Code language: PHP (php)

Terraform Backend Credentail Pass Through Command line

$ terraform init -backend-config=”access_key=ASSSSSSSSSSSSSY” -backend-config=”secret_key=VddddddddddddddG” -reconfigure

How to Setup Terraform Backend with Azure Blob Container?


terraform {
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = "3.75.0"
    }
	aws = {
      source = "hashicorp/aws"
      version = "5.20.0"
    }
	github = {
      source = "integrations/github"
      version = "5.39.0"
    }
  }
  backend "azurerm" {
    resource_group_name  = "eksuw01-rg"
    storage_account_name = "eksuw01sa"
    container_name       = "rajesh"
    key                  = "prod.terraform.tfstate"
	subscription_id = "b3dbe884-c3dc"
    client_id       = "6046fe74-dfd2-4"
    client_secret   = "3XJ8Q~uvlwVL"
    tenant_id       = "f34c8fc4-16b"
  }
}
provider "azurerm" {
  features {}
  subscription_id = "b3dbe884c"
  client_id       = "6046fe74-d"
  client_secret   = "3XJ8Q~uvlwV"
  tenant_id       = "f34c8fc4-1"
}Code language: JavaScript (javascript)

# aws-main.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }

  backend "s3" {
    bucket         = "my-terraform-state-bucket"
    key            = "aws/lab/terraform.tfstate"
    region         = "ap-south-1"
    dynamodb_table = "terraform-locks"
    encrypt        = true
  }
}

provider "aws" {
  region = "ap-south-1"
}

resource "aws_instance" "demo_vm" {
  ami           = "ami-0f58b397bc5c1f2e8"
  instance_type = "t2.micro"

  tags = {
    Name = "aws-demo-vm"
  }
}
Code language: PHP (php)
# gcp-main.tf

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 5.0"
    }
  }

  backend "gcs" {
    bucket = "my-gcp-terraform-state-bucket"
    prefix = "gcp/lab"
  }
}

provider "google" {
  project = "my-gcp-project-id"
  region  = "asia-south1"
  zone    = "asia-south1-a"
}

resource "google_compute_instance" "demo_vm" {
  name         = "gcp-demo-vm"
  machine_type = "e2-micro"
  zone         = "asia-south1-a"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-12"
    }
  }

  network_interface {
    network = "default"
  }
}
Code language: PHP (php)
# azure-main.tf

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 4.0"
    }
  }

  backend "azurerm" {
    resource_group_name  = "rg-terraform-state"
    storage_account_name = "mystatestorageacct"
    container_name       = "tfstate"
    key                  = "azure/lab/terraform.tfstate"
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "demo_rg" {
  name     = "rg-demo-vm"
  location = "East US"
}

resource "azurerm_virtual_network" "demo_vnet" {
  name                = "demo-vnet"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.demo_rg.location
  resource_group_name = azurerm_resource_group.demo_rg.name
}

resource "azurerm_subnet" "demo_subnet" {
  name                 = "demo-subnet"
  resource_group_name  = azurerm_resource_group.demo_rg.name
  virtual_network_name = azurerm_virtual_network.demo_vnet.name
  address_prefixes     = ["10.0.1.0/24"]
}

resource "azurerm_network_interface" "demo_nic" {
  name                = "demo-nic"
  location            = azurerm_resource_group.demo_rg.location
  resource_group_name = azurerm_resource_group.demo_rg.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.demo_subnet.id
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_linux_virtual_machine" "demo_vm" {
  name                = "azure-demo-vm"
  resource_group_name = azurerm_resource_group.demo_rg.name
  location            = azurerm_resource_group.demo_rg.location
  size                = "Standard_B1s"
  admin_username      = "azureuser"

  network_interface_ids = [
    azurerm_network_interface.demo_nic.id
  ]

  admin_ssh_key {
    username   = "azureuser"
    public_key = file("~/.ssh/id_rsa.pub")
  }

  os_disk {
    caching              = "ReadWrite"
    storage_account_type = "Standard_LRS"
  }

  source_image_reference {
    publisher = "Canonical"
    offer     = "ubuntu-24_04-lts"
    sku       = "server"
    version   = "latest"
  }
}
Code language: PHP (php)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Top 10 AI Live Chat Automation Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, customer expectations for instant, personalized, and 24/7 support have reached new heights. Businesses can no longer rely solely on human agents to manage customer…

Read More

Top 10 eProcurement Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction eProcurement software is a vital tool for businesses seeking to streamline and automate the procurement process, which includes purchasing goods and services from suppliers. In 2026,…

Read More

Top 10 Live Chat Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, Live Chat Tools have become essential for businesses to enhance customer support, boost conversions, and provide real-time communication on websites. With increasing consumer demand…

Read More

Top 10 Lab Management Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction Lab Management Software (LMS) is a crucial tool for streamlining operations in laboratories across industries such as healthcare, research, pharmaceuticals, education, and manufacturing. In 2026, as…

Read More

Top 10 Catalog Management Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction In todayโ€™s competitive business landscape, managing product catalogs efficiently is essential for companies looking to streamline their operations, enhance customer experience, and maintain a consistent brand…

Read More

Top 10 AI PPC Optimization Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, pay-per-click (PPC) advertising remains a cornerstone of digital marketing, but managing campaigns manually is no longer viable in a landscape driven by data and…

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Jason Mitchell
Jason Mitchell
3 months ago

Helpful and easy-to-follow guide on Terraform backend. It clearly explains state management and backend setup in a simple way.

1
0
Would love your thoughts, please comment.x
()
x