Lab7: Terraform Backend - OT-TRAINING/TerraformAWS GitHub Wiki

Terraform Backend

In this lab, we will try to use a remote backend to store our tfstate file: Create a S3 bucket manually. Create a resource for Instance Creation and Plan, apply it by using Terraform

Let's Start

Create a backend.tf file mentioning the backend code.

terraform {
   backend "s3" {
     bucket         = "terraform-remote-backend-0505"
     key            = "remotebackend.tfstate"
     region         = "us-east-1"
     dynamodb_table = "s3-tfstate-lock"
   }
}

provider "aws" {
  region = var.region
}

variable "ami" {
  default = "ami-08962a4068733a2b6"
}

variable "instance" {
  default = "t2.micro"
}

variable "region" {
  default = "us-east-2"
}

variable "tags" {
  default = "test"
}

resource "aws_instance" "main" {
  ami           = var.ami
  instance_type = var.instance
  
  tags = {
    Name = var.tags
 }
}