What is Infrastructure as Code?
- Process of automatically manage and provision infrastructure with code
- Eliminates one-off machines/Manual Changes
- Rebuildable/Repeatable
- Deploying IaC in dev, all the way to prod
- Version Control
Build and Operate Infrastructure as Software
Application | Infrastructure |
---|---|
Source Code | JSON |
Interpreter | AWS Service API |
Desired application state | Desired infrastructure state |
What is Terraform?
Allows ops teams to build, change infrastructure safely and efficiently.
- Supports multiple cloud providers
-
Documentation is executable (always up-to-date)
- TF resources allow us to set/change infrastructure attributes:
- Instance Type
- Region
- VPC
- Security Groups
Reusable TF Modules
Here are some reusable TF modules we have at reflektion
- Webology (all the core services)
- Elasticache
- ECS stack
Recycling code in multiple environments, just by updating few tags in the new resources.
How is Terraform apply to Reflektion?
- Create/Update/Rebuild our infrastructure
Workflow
- Create a resource which calls for modules we have written
- Run
terraform plan
- TF locks state file on the backend (S3) to prevent state corruption
- Run
terraform apply
- Creates the AWS resources - security group, dns entries
- Applies
user_data
contents- Post provision setup such as installing additional softwares, cloning Webology, etc.
- Update resource attributes to make additional changes
- Re-run
terraform plan
andterraform apply
Live Demo
- remove manual changes with apply
- update resource to scale up instances
- scale down instances