This is a presentation about my experience of implementing 'effective' automation with Terraform.
You can check out the contents below in presentation.pdf
.
1. Terraform Basic Concept
In this section, I'm gonna explain the definition of provisioning and IaC, known as Infrastrcture as Code.
Then, let's find out what Terraform is, and how it works.
2. Terraform Module
I want to tell my experience why I studied and applied Terraform Module. You may figure it out if you compare the tree structure before, and after applying Terraform Module. Plus, we can configure a backend using S3 and DynamoDB.
Let's see how Terraform manages its state files.
3. Live Demo
Demo is the best practice to understand all these concepts. Let's go on!
In this Demo, you can configure dev and prod environment by reusing network and ec2 modules.
network module
involves vpc, subnet, internet gateway, nat gateway, EIP, and route tableec2 module
involves key, bastion host, and private ec2 instances
This demo deploys EC2 instances on a single availability zone in the dev environment, and on multiple availability zones in the prod environment.
- Don't forget to delete all these resources after running this demo❗️ It invloves some resources that are charged.
- What you should do is just changing the values of
dev.tfvars
andprod.tfvars
. Resouce modules will be reused by calling them at the root module.
Before running, you should install aws cli(v2) and terraform using homebrew.
- This is how you shorten the 'terraform' command to 'tf'.
# path which terraform # inject path, using '-s' option for symbolic link sudo ln -s ${path}/terraform ${path}/tf
- This demo calls key-pair resource using
data
block, which means key-pair is provisioned already on console.
So, if you want to run this demo,- just create your key-pair on console directly
- and modify
key_name
info at the very top of themodules/ec2/main.tf
file.
# terraform-demo/global
tf init
tf fmt # check and apply a canonical format
tf validate # verify if configuration files are valid
tf plan --var-file
- But if you didn't configure the backend, please annotate the
terraform
block!
# terraform-demo/root/dev
tf init
tf fmt & tf validate # optional step
tf plan --var-file=dev.tfvars
tf apply --var-file=dev.tfvars -auto-approve
# terraform-demo/root/prod
tf init
tf fmt & tf validate # optional step
tf plan --var-file=prod.tfvars
tf apply --var-file=prod.tfvars -auto-approve
# terraform-demo/root/dev
tf destroy -var-file=dev.tfvars
# terraform-demo/root/prod
tf destroy -var-file=prod.tfvars
🖥️ Web : Terraform Docs
📚 Book : Terraform Up&Running by Oreilly
🐹 Support & Advice : AUSG 명예 안아줘요 🌟