DevOps Classroom Series – 02/Jun/2020

Scenario: Create a EC2 machine in the VPC already written in the template

module "myvpc" {
  source        = "./modules/myvpc"

  vpccidr       = "192.168.0.0/16"
  
}
  • Terraform also provides a way of sharing modules to community using terraform registry
  • Now lets find the module to create vpc and we found this Preview
  • Lets create a new folder with provider.tf and main.tf. Add aws provider to provider.tf and in main.tf add the following
module "vpc" {
  source = "terraform-aws-modules/vpc/aws"
  version = "2.38.0"

  name = "my-vpc"
  cidr = "10.0.0.0/16"

  azs             = ["us-west-2a", "us-west-2b", "us-west-2c"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]


  tags = {
    Terraform = "true"
    Environment = "dev"
  }
}
  • Execute
terraform init 
terraform apply .

Leave a Reply

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

About learningthoughtsadmin