Giter Club home page Giter Club logo

terraform-aws-transit-gateway's Introduction

AWS Transit Gateway scenario with Terraform

This project gives an example of the usage of the recently (november 2018) announced AWS Transit Gateway product. That component provides a way to interconnect multiple VPCs in a hub-spoke topology.

The Transit Gateway is meant to superseed the more complex and expensive Transit VPC technology. This is a didactic example to showcase how a Transit VPC should be configured to achieve a non-trivial (full mesh) scenario. I hope it can be helpful.

Architecture

A Transit Gateway relies on Route Tables. By default, a new Route Table is created in the Transit Gateway, which populates with the routing info toward every VPC attached to the gateway (the full mesh scenario) The Terraform code in this project demonstrates a more complex scenario in which traffic is isolated based on the environment. Four VPCs are created, with two subnets each (in separate AZs):

  • VPC-1: in the 'dev' environment
  • VPC-2: in the 'dev' environment
  • VPC-3: in the 'shared' environment
  • VPC-4: in the 'prod' environment

Let's assume the 'shared' environment will host shared components, such as proxy services, tools, ... Here are the rules we want our Transit Gateway to implement:

  • The shared VPC can access dev and prod VPCs.
  • The dev VPCs can access each other, and the shared VPC
  • The prod VPCs can only access the shared VPC

To enable such a scenario, three Route Tables are created in the Transit Gateway, one per environment. Which means both dev VPCs attach to the same Route Table, whereas the shared and prod VPCs each attach to their respective Route Table. Each VPC gets a t2.micro Ubuntu instance to validate the network connectivity over ssh and ICMP (ping). The instance in the 'shared' is assigned a public IP so a VPN connection isn't needed. Adding the necessary Terraform resources to establish a VPN connection could be an extension of this project.

transit-gateway-architecture

The thick green links on the diagram represents the authorized traffic through the gateway.

Prerequisites

  • An AWS account
  • Terraform

Usage

  • Change ACCESS_KEY and SECRET_KEY values in Variables.tf
  • Change the public_key value to a keypair you own
  • Deploy the setup with:
$ terraform init
$ terraform plan
$ terraform apply
  • The public IP of the instance in the 'shared' VPC is printed when deployment ends
  • ssh on this instance
$ ssh -i your_private_key ubuntu@$PUBLIC_IP
  • Check you can ping and ssh any other instance in the other VPCs
  • Also check that, from a dev instance (1 & 2) you cannot reach the prod instance (4) and vice-versa.
  • Delete all resources
$ terraform destroy

terraform-aws-transit-gateway's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.