Coder Social home page Coder Social logo

ec2-with-terraform's Introduction

banner

Technology Used:

  • Terraform v0.11.11 + provider.aws v1.58.0
  • Putty 0.70

System Requirements:

I am working from a windows machine with 10.0.17763 N/A Build 17763. I also have the linux subsystem installed and running with terraform added to the path for use with both bash and powershell.

For the purposes of this demo, I will use SSH (putty) to administer an EC2 instance where terraform will be installed - no need to rely on local hardware.

Terraform download:

Putty download:

EC2 Creation and setup:

Login to the AWS console with the appropriate user account (not the root account):

login_aws

Select EC2 from the management console:

select_ec2

Launch a new instance:

launch_instance

Select an appropriate AMI:

select_ami

Choose an instance type:

choose_instance

Review setup and launch the instance:

review_launch

Create, or re-use an already created key pair (do not store in a public visible repo or location!):

key_pair

Select acknowledge, and launch the instance:

acknowledge_launch

Review launch status until the instance is ready:

review_launch

Select and connect to the instance:

select_and_connect

Select the option to connect using a standalone SSH client (putty):

ssh

Download Putty:

putty

Enter the host name of the instance (this will be the instance username already provided when selecting the AMI, and the public DNS of your EC2 instance)

public_dns dns

Select connection, SSH, Auth and Browse and find the private key already created. (notes on how to create a private key for putty:https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html):

private_key1

private_key2

Open the session to the instance:

open_session

Once logged in, run the "sudo yum update" command:

update

Run the following commands to setup terraform on the instance:

cd ~
mkdir terraform
cd terraform
wget https://releases.hashicorp.com/terraform/0.11.11/terraform_0.11.11_linux_amd64.zip
unzip terraform_0.11.11_linux_amd64.zip

Adding terraform to the path in linux:

echo @"export PATH=\$PATH:$(pwd)" >> ~/.bash_profile

To get it working:

source ~/.bash_profile

Next, we need to create a .tf configuration file:

Open VIM or NANO text editor inside your instance, whichever you prefer. Add the followng basic configuration to create your instance on AWS according to your timezone/preferences/etc. :

Command:

nano ec2.tf

Input:

provider "aws" {
	access_key = "ACCESS_KEY_HERE"
	secret_key = "SECRET_KEY_HERE"
	region = "us-east-1"
}

resource "aws_instance" "example" {
	ami = "ami-2757f631"
	instance_type = "t2.micro"
}

When finished, save the file and exit:

nano

Navigate back to your directory and run the "terraform init" command:

terraform init

This will initialise plugin requirements, you cannot proceed without doing this.

initialised

Next, we will want to compile the plan, then create the instance using the newly added ec2.tf configuration file:

terraform plan
terraform apply
yes

You should see your instance being created:

aws_instance.example: Still creating... (10s elapsed)
aws_instance.example: Still creating... (20s elapsed)

You should see that the setup has completed with success:

complete

ec2-with-terraform's People

Contributors

bransfieldjack avatar

Stargazers

Marcin Mrugacz avatar

Watchers

James Cloos 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.