[email protected] # whoami
[email protected] # uname -a
[email protected] # terraform plan -out=introduction
Infrastructure as code (IaC) is the process of managing and provisioning computer data centers through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools.
A good starting article about IaC from thorntech
Operations:
💰 Buisness 💰:
Exact specification on the language can be found in the Hashicorps repository
// vars:
“${var.aws_account_number}” //(0.11)
var.aws_account_number // (0.12)
// lists:
“${var.aws_account_number[count.index]}”
// maps:
“${var.aws_account_number[‘client1’]}”
// looping (0.11): creating ++like loops
resource instance {
count = 3
name = “instance-${count.index}”
}
// looping (0.12): templating
%{ for instance in aws_instance.example ~}
server ${instance.id}
%{ endfor }
//if
resource aws_vpc vpc {
count = “${var.create_vpc}”
// In HCL true/false is mapped to 1 and 0
}
//if-else
// comprassions and boolean logic: == != > < >= <=
resource aws_vpc vpc {
subnet = “${
var.env == “production” ?
var.prod_subnet : var.dev_subnet
}”
}
resource aws_ec2_instance manager {
name = “swarm-manager”
}
resource aws_ec2_instance workers {
counte = 3
name = “swarm-worker-${count.index}”
}
module docker_swarm swarm {
manager_ip = “${aws_ec2_instance.manager.ipv4}”
workers_ips = “${aws_ec2_instance.workers.*.ipv4}”
}
// module file
resource s3_bucket data {
name = “${var.name}”
}
output policy_ref {
value = “${s3_bucket.policy.json}”
}
//main.tf
module bucket {
name = “my-bucket”
}
resource aws_s3_bucket copy {
name = “copy-of-my-bucket”
policy = “${module.bucket.policy_ref.value}”
}
All interpolations can be found in the docs.
online @ https://mlodzikowski.pl/presentations/terraform
repo with snippets @ https://github.com/mkjmdski/terraform-examples