daveryde / terraform-aws-starter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Terraform - AWS VPC, Internet Gateway, Route Table, Subnet, Security Group, Network Interface, Elastic IP, and EC2 Instance

A complete basic terraform configuration file that will create the required cloud infrastructure resources to support an EC2 t2.micro instance running Amazon Linux 2 AMI which renders a simple html page upon visiting the assigned elastic IP.

The minimum AWS cloud infrastructure requirements for this are listed as follows:

  • Create VPC
  • Create Internet Gateway
  • Create Custom Route Table
  • Create Subnet
  • Associate Subnet with Route Table
  • Create Security Group to allow ports 22, 80, 443
  • Create Network Interface with IP in created Subnet range
  • Assign Elastic IP to the Network Interface
  • Create Amazon Linux 2 AMI EC2 instance configured to cloud resources

Additional ideas to implement include:

  • Terraform variables
  • Terraform outputs
  • Terraform and provider versioning (best practices)
  • Elastic Load Balancer
  • Elastic Container Services
  • Fargate Instances

Specification

  1. Learn terraform to create cloud resources to support AWS server instances
  2. Successfully implement terraform to create required clould resources and server instance

Getting Started

To get a local copy up and running follow these steps.

Installation

  1. Clone the repo
git clone https://github.com/daveryde/terraform-aws-starter.git
  1. In main.tf, fill in your own region, AWS access, and secret keys to create resources using your AWS account
provider "aws" {
    region = "<region>"
    access_key = "<access_key>"
    secret_key = "<secret_key>"
}
  1. In the project directory, use terraform to create the resources in your AWS account:
terraform apply
  1. Copy and paste your assigned elastic IP output from the terminal into a browser to view the html page generated once all cloud resources have been created to support this server instance.
Apply complete! Resources: 9 added, 0 changed, 0 destroyed.

Outputs:

instance_id = "i-026fe87e3a9c7306c"
instance_public_ip = "18.116.190.239"   <-- example public IP output

Terraform Resources

About


Languages

Language:HCL 100.0%