Crash course: https://www.youtube.com/watch?v=SLB_c_ayRMo
Concepts
- Provider: platforms the TF code will be based on. (AWS, Docker, etc)
- Resources
1 | provider "aws" { |
terraform init
: initialize and download the api plugins.terraform plan
: prints out details on what will happenterraform apply (--auto-approve)
: apply the planterraform destroy
: destroy the entire infrastructure
Re-run terraform apply won’t create another resource. Terraform files are like infrastructure instructions on what the infrastructure should look like in the end.
The order of the code doesn’t matter
create aws vpc1
2
3
4
5
6
7
8
9
10
11
12
13
14
15resource "aws_vpc" "first-vpc" {
cidr_block = "10.0.1.0/16"
tags = {
Name = "production"
}
}
resource "aws_subnet" "subnet-1" {
vpc_id = aws_vpc.first-vpc.id # variable: reference
cidr_block = "10.0.1.0/24"
tags = {
Name = "prod-subnet"
}
}
terraform.tfstate
file: do not mess around with it. It tracks the current state.
Example
1 | # 1. Create a VPC |