Trying Terraform for first time

Shi
CI/CD/DevOps
Published in
2 min readMay 21, 2020

A few weeks into the WFH practice, I finally found another fun (other than teaching my daughter Python); the national library is offering a lot of ebooks where I can easily checkout to Adobe Digital Edition;

see my collection at the moment, wow! yeah, humans are greedy.

Now I understand Terraform is all about infra-as-code; basically you could provision a virtual machine or container with just a few lines of YAML. The additional benefit is that with Terraform, you add another layer of abstraction, and it is a lot easier to deploy your infra across different cloud. Never put all your eggs in the same basket, right?

talk is cheap and here is my code:

provider "aws" {
region = "us-east-2"
}
resource "aws_instance" "example" {
ami = "ami-00000e806f84305b1"
instance_type = "t2.micro"
tags = {
Name = "terra-rookie-EC2"
}
}

then

>terraform init
>terraform plan
>terraform apply

bingo! first EC2 spin up by Terraform!

Gotchas:

— make sure there is only one .tf file in your working folder— make sure you used the right aws region (EC2 image id is different across regions) — make sure your aws cli IAM role has the proper privilege to create EC2— make sure you used a valid image id— how do you list out all the available image id?
>aws ec2 describe-images — region us-east-2

--

--

Shi
CI/CD/DevOps

I am a coder/engineer/application security specialist. I like to play around with language and tools; I have strong interest in efficiency improvement.