All technological notes.
Infrastructure As Code (IaC)
Benefits
HCL (Hashicorp Configuration Language)Resole dependency
.tf files and create a resource graph to determine the sequence of managing resources.tf workflow:
.tfterraform plan to preview what will be appliedterraform apply to implement resource management.
Terraform core contains
providers, not cloud provider API.Terraform registry
Terraform providers
terraform initterraform {} block.# AWS provider
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0"
}
}
}
# custom provider
terraform {
required_providers{
mycloud = {
version = ">= 1.0.0"
source = "mycorp/mycloud" # tf cloud's private registry
}
}
required_version = ">= 0.14"
}
provider "aws" {
region = "us-east-1"
}
provider "aws" {
region = "us-east-1"
}
provider "aws" {
alias = "eu" # using alias
region = "eu-west-1"
}
resource "aws_instance" "myinstance"{
provider = aws.eu
}
module "mymodule" {
source = "./mymodule"
providers = {
aws = aws.eu
}
}
MAJOR.MINOR.PATCH
MAJOR: new breaking changesMINOR: new featuresPATCH: bug fixes onlyProvisioner
Types of provisioner
Local-provisioner
Remote-provisioner
Packer
Cloud init
!ONLY USE Provisioner AS LAST RESORT.