Collaborative IaC using Terraform

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prabesh Thapa

Prabesh Thapa

48 Followers

DevOps / SRE Engineer. Blog: 99devops.com System admin turned SRE. I love Linux.