Terraform
Frequently used terraform snippets
One-liners
Validate configurations: terraform validate
Start terraform config: terraform init
Give format to files within direcoty terrafom fmt
Execute terraform terraform apply --auto-approve
Frecuently used AMI IDs
Ubuntu server 18.04 (HVM) 64bits x86:
ami-0a63f96e85105c6d3
Recipes
Setup AWS instances
Get AWS access key/AWS secret key
execute
aws configureusing credentials from 1.execute
terraform initwhen starting new project at the root of the directory
Get list of AMI IDs matching criteria
variable "image_name" {
description = "The name of the image to use"
default = "ubuntu-*-18.04*"
}
provider "aws" {
region = "us-east-2"
}
data "aws_ami" "images" {
owners = ["amazon"]
most_recent = true
filter {
name = "name"
values = [var.image_name]
}
}
output "ids" {
value = "\nName: ${data.aws_ami.images.name}\nId: ${data.aws_ami.images.id}"
Single ec2 with ubuntu 18.04 x86
Create and attach ebs storage
aws_ebs_volume and aws_instance ideally belong to the same availability_zone
Define storage from ec2 creation
Create a security group and use it afterwards (Allow income from 8080)
Create a security group for ssh access (Experimental)
Stoping/Starting instances with AWS CLI
References
[Terraform up and running (local book)](/media/w/6529BB496A1EC696/Yevgeniy Brikman - Terraform Up and Running (Early Release)-O'Reilly Media (2017).pdf)
https://learn.hashicorp.com/terraform/getting-started/build
http://blog.shippable.com/setup-a-container-cluster-on-aws-with-terraform-part-2-provision-a-cluster
https://towardsdatascience.com/seamlessly-integrated-deep-learning-environment-with-terraform-google-cloud-gitlab-and-docker-faee4b351e94
Last updated
Was this helpful?