Deploy Amazon VPC using Terraform

Posted: January 5, 2018 in Amazon Web Services (AWS), AWS, Linux, terraform

In previous post   we deployed EC2 instance, now we’ll add directives to template.cf file to deploy VPC/subnet

Creating VPC

Add following lines to template.tf

#VPC

resource "aws_vpc" "my_vpc" {
cidr_block="10.0.0.0/16"

tags {

Name="my-vpc"
}
}

This will create VPC named “my_vpc with 10.0.0.0/16 IP address block

Creating subnet

Add following lines below VPC code:

resource "aws_subnet" "my-subnet" {
vpc_id="${aws_vpc.my_vpc.id}"
cidr_block="10.0.1.0/24"

tags {

Name="public-subnet"
}
}

Code above will add subnet to VPC “my_vpc” named “my-subnet”

vpc_id=”${aws_vpc.my_vpc.id}” is reference to “my_vpc” VPC

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s