TERRAFORM

Create, Change, and Orchestrate AWS Infrastructure with Terraform


  • Create a terraform file for AWS setting like below
variable "region" {}
provider "aws" {
  region = "${var.region}"
}
terraform {
  backend "s3" {
    bucket = "sspucket"
    key    = "root/terraform.tfstate"
    region = "us-east-1"
  }
}
Above is the main file, we are telling to terraform, that out cloud provider is AWS.
  • Create a main.tf file for creating infrastructure.


module "aws_public_vpc" {
  source = "github.com/terraform-community-modules/tf_aws_vpc"
  name = "SSP VPC"
  cidr = "${var.public_cidr}"
  public_subnets = ["172.29.4.0/24", "172.29.5.0/24"]
  enable_nat_gateway = "${var.aws_enable_nat_gateway}"
  enable_dns_support = "${var.aws_enable_dns_support}"
  azs      = ["us-east-1a", "us-east-1b"]
  tags {
    "Environment" = "developers"
  }
}
// Ouputs of netwoking
output "vpc_id" {
 value = "${module.aws_vpc.vpc_id}"
}
Above file is used to create a VPC with Public IP and print the output with all values.

Terraform Commands:



  • terraform get
    Used to download the modules, that we used in main.tf file. For ex:- aws_public_vpc
  • terraform init
    Used to initiate  (Initial configuration of the requested backend "s3")
  • terraform plan
    Will actually tells, what is going to create in AWS.
  • terraform apply
    Will apply the changes finally and create the infrastructure, that is mentioned in the .tf file
    .






Comments

Popular posts from this blog

Install Kubernetes with Kubeadm

AWS-DevOps Overview