Chapter 2: Core Concepts & Technology Stack
Overview
Understand the core concepts behind a production-grade, multi-environment AWS Infrastructure as Code (IaC) setup built with Terraform and Terragrunt. This chapter explains how the stack fits together (VPC, EKS, RDS), how DRY configuration enables O(1) environment scaling, and the operational foundations you need for repeatable, secure deployments.
2.1 Infrastructure as Code Fundamentals
The Friction
- ✕ Duplication Nightmare: Copy-pasting code across envs ensures drift & bugs.
- ✕ Unlimited Blast Radius: One bad apply destroys Prod because state is shared.
- ✕ Dev Friction: Developers wait days for 'simple' infra changes.
- ✕ Security Vulnerabilities: Open buckets & loose IAM roles are the default.
The R8way Solution
- ✓ DRY Architecture: Write once, deploy everywhere with reusable modules.
- ✓ Account Isolation: Separate states & accounts limit damage to zero.
- ✓ Self-Service Config: Devs change values.yaml, not Terraform code.
- ✓ Secure Defaults: Hardened out of the box.
2.2 Terraform Overview
What is Terraform?
Terraform is an open-source Infrastructure as Code tool created by HashiCorp. It allows you to define infrastructure using a declarative configuration language called HCL (HashiCorp Configuration Language).
Core Terraform Concepts
Resources
Resources are the most important element in Terraform. Each resource block describes one or more infrastructure objects.
Breakdown:
- resource: Keyword declaring a resource
- "aws_vpc": Resource type (provider + resource)
- "main": Local name (used to reference this resource)
- Block content: Configuration arguments
Variables
Variables allow you to parameterize your configurations.
Variable Types:
- string: Text values
- number: Numeric values
- bool: true/false
- list(type): Ordered collection
- map(type): Key-value pairs
- object({...}): Complex structures
Outputs
Outputs expose values from your configuration for use by other configurations or for display.
Modules
Modules are containers for multiple resources that are used together. Every Terraform configuration has at least one module (the root module).
Terraform Workflow
State Management
Terraform State is a critical concept. The state file maps your configuration to real-world resources.
State File Contents:
Why State Matters:
- Tracks resource metadata
- Improves performance (caching)
- Enables collaboration
- Manages dependencies
State Storage:
- Local: terraform.tfstate file (development only)
- Remote: S3, Terraform Cloud, etc. (production)
2.3 Terragrunt Overview
What is Terragrunt?
- Keeping your Terraform code DRY (Don't Repeat Yourself)
- Working with multiple Terraform modules
- Managing remote state
Why Terragrunt?
Problem with Vanilla Terraform:
Solution with Terragrunt:
Core Terragrunt Concepts
1. DRY Configurations
Traditional Terraform (Repeated Code):
Terragrunt (Write Once):
2. Dependencies
Terragrunt can manage dependencies between modules:
3. Mock Outputs
For planning without dependencies:
4. Dynamic Configuration
Use functions and locals:
5. Code Generation
Terragrunt can generate files:
6. Terragrunt Workflow
7. Terragrunt Commands
| Command | Description |
|---|---|
terragrunt plan
|
Run terraform plan |
terragrunt apply
|
Run terraform apply |
terragrunt run-all plan
|
Plan all modules |
terragrunt run-all apply
|
Apply all modules |
terragrunt output
|
Show outputs |
terragrunt destroy
|
Destroy infrastructure |
2.4 AWS Services Overview
VPC (Virtual Private Cloud)
What it
is:
A logically isolated section of the AWS cloud where you can launch resources in a virtual
network you define.
Key Components:
Why we need it:
- Network isolation
- Security boundaries
- Control over IP addressing
- Internet/private connectivity
EKS (Elastic Kubernetes Service)
What it
is:
Managed Kubernetes service that makes it easy to run Kubernetes on AWS without needing to
install and operate your own Kubernetes control plane.
Architecture:
Key Features:
- Automatic Kubernetes version upgrades
- Integrated with AWS services
- High availability
- Security & compliance
- Scalability
Why we need it:
- Run containerized applications
- Microservices architecture
- Auto-scaling
- Self-healing infrastructure
RDS (Relational Database Service)
What it
is:
Managed relational database service supporting multiple database engines (PostgreSQL, MySQL,
etc.).
Architecture:
Managed Features:
- Automated backups
- Software patching
- Monitoring
- Replication
- Scaling
Why we need it:
- Persistent data storage
- Reduced operational overhead
- High availability
- Backup & recovery
- Security (encryption)
2.5 Supporting Technologies
Bash Scripting
Purpose: Automation wrappers around Terragrunt commands.
Example from our boilerplate:
Key Concepts:
- set -e: Exit on error
- $1, $2: Command-line arguments
- if [ condition ]: Conditionals
- for item in list: Loops
YAML Configuration
Purpose: Human-readable configuration format.
Example:
Syntax Rules:
- Indentation matters (2 spaces standard)
- Key: Value pairs
- Lists use - item or [item1, item2]
- Nested structures via indentation
Git Workflows
Purpose: Version control for infrastructure code.
Recommended Workflow:
Best Practices:
- Never commit state files
- Use .gitignore
- Meaningful commit messages
- Pull Request reviews
- CI/CD automation
2.6 How It All Fits Together
The Complete Stack
2.7 Chapter Summary
Executive Summary
-
★IaC
- enables treating infrastructure like software
- provides the engine for infrastructure provisioning
- eliminates code duplication and manages complexity
- (VPC, EKS, RDS) provide the infrastructure building blocks
- ties everything together for smooth operations