DevOps Classroomnotes 29/Mar/2023

Multi user

  • Lets create a simple terraform template to create vpc Refer Here for the changes
  • Execute this from two different machines.
  • Consider both of them are working for same purpose
  • User 1:
    Preview
  • User 2:
    Preview
  • Execution Create two different resources, which is not desired
    Preview
  • As of now state is stored locally i.e. when user1 executes it is stored in user1 system and same for user2
    Preview
  • To solve this problem we need to store the state in some common place
    Preview
  • The location of state file in terraform is defined by backend.

Terraform Backends

  • Backend defines where the state has to be stored
  • Refer Here for offical docs and Refer Here for configuring backend
  • There are two types of backends
    • local-backend:
      • This is default backend
    • remote-backend
  • Refer Here for available backends
  • As common state for terraform for multiple users will have concurrency problem, Terraform backends need locking and unlocking
  • S3 bucket can be used as terraform backend, S3 buckend doesnot support locking, if you need locking add dynamo db details

Remote Backends with S3

  • Refer Here for official docs
  • Create an s3 bucket
    Preview
  • Create a dynamo DB table with any name and partition key LockID
    Preview
  • Refer Here for the changes done to add s3 backend
  • Perform init on both user machines
    Preview
  • Now lets user1 apply the changes
    Preview
  • Now while user1 is still applying let user 2 also apply
    Preview
  • Let user1 finish applying and create the resources
    Preview
  • Now let user2 try applying
    Preview
    Preview
  • Exercise: Configure Azurerm backend Refer Here which has inbuilt locking facility

Next Steps

  • Provisioning
  • Immutable Infrastructure

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner