Wat.tf
@nocoot
Source: https://www.terraform.io/
“Infrastructure as code” is NOT code
(Opinions are my own)
Adding 3 buckets
resource "aws_s3_bucket" "sand" {
bucket = "sand"
acl = "private"
region = "us-east-1"
tags = "${var.tags}"
# ...
# 30 more lines here
# ...
}
resource "aws_s3_bucket" "mud" {
bucket = "mud"
acl = "private"
region = "us-east-1"
tags = "${var.tags}"
# ...
# same 30 lines here
# ...
}
resource "aws_s3_bucket" "dirt" {
bucket = "dirt"
acl = "private"
region = "us-east-1"
tags = "${var.tags}"
# ...
# same 30 lines here too
# ...
}
Applying DRY
variable "buckets" {
type = "list"
default = ["sand", "mud", "dirt"]
}
resource "aws_s3_bucket" "bucket" {
count = "${length(var.buckets)}"
bucket = "${var.buckets[count.index]}"
acl = "private"
region = "us-east-1"
tags = "${var.tags}"
# ...
# 30 more lines here
# ...
}
Destroying a single (?) bucket
variable "buckets" {
type = "list"
default = ["sand", "mud", "dirt"]
}
resource "aws_s3_bucket" "bucket" {
count = "${length(var.buckets)}"
bucket = "${var.buckets[count.index]}"
acl = "private"
region = "us-east-1"
tags = "${var.tags}"
# ...
# 30 more lines here
# ...
}
Self-hosted DB Module
# Elastic Network Interface(s)
# Elastic Block Service devices
# User Data Template
# Launch Configuration
# Auto Scaling Group
# Route 53 Record (to ENI)
# Output: Route 53 Record
Using the DB module (?)
module "db" {
source = "./db"
}
resource "aws_instance" "app" {
ami = "ami-01234567890123456"
instance_type = "m4.large"
user_data = "...${module.db.address}..."
}
Terraform Dependency Graph
Module is NOT a class
or a struct, or a union
“Infrastructure as code” is NOT code
Source: https://www.lifehack.org/577201/stages-grief-the-less-painful-way-cope-with-loss
“Infrastructure as code” is NOT code
Thank You!
@nocoot

Wat.tf - Nati Cohen - DevOpsDays Tel Aviv 2018