Giter Club home page Giter Club logo

aws_simple_snat's Introduction

AWS Simple SNAT

This example shows the following things:

  • Create a VPC and subnets using vpc module.
  • Create a NAT instance using this module.
  • Create an instance in the private subnet.
  • Add terraform-key.pem to the both instances.

Getting Started

Prerequisite: Generate key pair terraform-key in Tokyo - ap-northeast-1 through AWS Console, and replace terraform-key.pem with downloaded one.

Provision the stack.

% terraform init
% terraform apply
...

Outputs:

nat_public_ip = 35.73.142.227
private_instance_id = i-01acdcda755b6736c

Test One - Verify the IP being exposed to internet is Nat instance's EIP only, and curl checkip.amazonaws.com to get the EIP via https only.

Make sure you have access to the instance in the private subnet.

% aws ssm start-session --region ap-northeast-1 --target i-01acdcda755b6736c
% curl https://checkip.amazonaws.com
35.73.142.227
% curl http://checkip.amazonaws.com
curl: (7) Failed to connect to checkip.amazonaws.com port 80 after 2053 ms: Connection refused

Test Two - Verify The Nat instance plays role of bastion server In your desktop, try below command to see if the nat public ip is sshable

% ssh -i terraform-key.pem [email protected]
% cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost6 localhost6.localdomain6
172.18.75.185 example-terraform-aws-nat-instance

Once enter the Nat instance, try below ssh to see if the private ip is sshable

% ssh -i /tmp/terraform-key.pem ec2-user@example-terraform-aws-nat-instance

Check the ip of the Private instance. and confirm it only leverages internal ip and not routable via internet

% ifconfig

You can completely destroy the stack.

% terraform destroy

aws_simple_snat's People

Contributors

weizheng78 avatar

Watchers

 avatar  avatar

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.