Collaborative IaC using Terraform

Prabesh
1 min readNov 25, 2020

--

Terraform is taking over the market and since it is cloud-agnostic, you can use the same language paradigm to provision infrastructure in any cloud environment.

This is really good when you are provisioning in your local machine, but what happens when you want to let multiple developers work on the same code? One way is sharing your state file but this is not recommended as terraform state holds some critical information like passwords, IPs.

So how do we solve this?

This can be done using a terraform remote state.

Remote state:

Using a remote state you can store your state configuration file on the cloud and the same state files can be used by different developers to provision infrastructure.

In order to define the terraform remote state your need to create a file named “backend.tf”, this will hold all the backend information and configuration of your terraform.

# To hold state file locks

terraform {# Use latest terraform version and always pin versionsrequired_version = "=0.13.4"backend "s3" {# To store state filesbucket = "terraform-live"key = "terraform.tfstate"region = "us-west-2"# To hold state file locksdynamodb_table = "terraform-live-locks"encrypt = true}}

Once you have it ready, you need yo created a s3 bucket named “terraform-live" and DynamoDB table named “terraform-live-locks" with key “LockID” which would hold the locks when you run terraform operations.

After this, run terraform init and you are ready to go.

--

--

Prabesh
Prabesh

Written by Prabesh

Senior Site Reliability Engineer & Backend Engineer | Docker Captain 🐳 | https://www.linkedin.com/in/prabeshthapa

No responses yet