- Terraform v0.11.11 + provider.aws v1.58.0
- Putty 0.70
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:
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)
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):
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
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:
Navigate back to your directory and run the "terraform init" command:
terraform init
This will initialise plugin requirements, you cannot proceed without doing this.
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: