Professional Documents
Culture Documents
Terraform Cheat Sheet
Terraform Cheat Sheet
Terraform Cheat Sheet
Basic S3
provider "aws" { resource "aws_s3_bucket" "finance" {
region = "us-east-2" bucket = "towfiqhassan-20220903"
} tags = {
Description = "Towfiq Terraform"
resource "aws_vpc" "myvpc" { }
cidr_block = "10.0.0.0/16" }
tags = {
Name = "VPC-Trial" EC2
} resource "aws_instance" "webserver" {
} ami = "ami-0568773882d492fc8"
instance_type = "t2.micro"
}
Variables List
variable "mylist" {
String type = list
variable "vpcname" {
default = ["10.10.0.0/16", "10.20.0.0/16"]
type = string
}
default = "TH-vpc"
}
for_each = toset(var.mylist)
resource "aws_vpc" "myvpc" { each.value
cidr_block = "10.0.0.0/16"
tags = { each.key – refers to index position of the value (i.e: 0,1,2,3 etc)
Name = var.vpcname
}
}
object
variable "rg_config" {
Map type = object({
variable "mymap" { create_rg = bool
type = map name = string
default = { VPC1 = "10.10.0.0/16“ VPC2 = location = string
"10.20.0.0/16"} })
} }
egress {
from_port = 32768
to_port = 60999
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
}
AWS AZURE
terraform { terraform {
required_version = “~> 1.2.0” required_version = “~> 1.2.0”
required_providers { required_providers {
aws = { azurerm = {
source = "hashicorp/aws" source = "hashicorp/azurerm"
version = "4.37.0" version = "3.29.1"
} }
} }
} }
provider "aws" {
region = "ap-southeast-1"
alias = "SINGAPORE"
}
cidr_block = "10.10.0.0/16"
provider = aws.OHIO
tags = {
Name = "VPC-IN-OHIO"
}
}
cidr_block = "10.20.0.0/16"
provider = aws.SINGAPORE
tags = {
Name = "VPC-IN-SINGAPORE"
}
}
2 Misc
Question: terraform plan, you notice that a resource has a tilde (~) next to it