Working with Cloud Infrastructure Using Terraform
Working with Cloud Infrastructure Using Terraform
Provisioning AWS Resources Using Terraform
- The AWS provider exposes resources and data sources for services such as VPC, EC2, S3 and IAM. Pin a compatible provider version and use a named profile, role or short-lived credentials.
- Start with a small network design and tag resources consistently. Provider documentation is the source of truth for resource arguments and replacement behaviour.
Creating Virtual Networks, Compute Instances and Storage Resources
- A typical network stack includes a VPC, public and private subnets, route tables, gateways and security groups. Compute instances need a subnet, machine image, instance type and carefully scoped network access.
- Keep costs and cleanup in mind when creating gateways and running instances.
- Storage resources need encryption, access policies, retention and lifecycle choices. Build dependencies through references rather than hard-coded IDs.
Managing Multiple Cloud Providers and Infrastructure Dependencies
- Terraform can manage multiple providers in one root module, but each provider has its own authentication, resource model and API limits. Use aliases for multiple accounts or regions and pass provider configurations to child modules explicitly when needed.
- Avoid coupling unrelated cloud environments into one enormous state. Separate state boundaries can reduce blast radius and make ownership clearer.
1. Worked Terraform Configuration
This example creates a VPC and two subnets from a map, using for_each to avoid duplicating resource blocks. The backend assumes the S3 state bucket already exists and has appropriate access controls, encryption and recovery settings.
For production, add route tables, gateways, network ACL decisions and security groups according to the network design.
terraform {backend "s3" {bucket = "training-terraform-state"key = "training/dev/network.tfstate"region = "us-east-1"encrypt = trueuse_lockfile = true}}
variable "vpc_cidr" {type = stringdefault = "10.20.0.0/16"}
variable "subnets" {type = map(string)default = {public_a = "10.20.1.0/24"private_a = "10.20.2.0/24"}}
resource "aws_vpc" "main" {cidr_block = var.vpc_cidrenable_dns_hostnames = true
tags = {Name = "training-vpc"Environment = "dev"}}
resource "aws_subnet" "this" {for_each = var.subnetsvpc_id = aws_vpc.main.idcidr_block = each.valuemap_public_ip_on_launch = startswith(each.key, "public")
tags = {Name = each.key}}
output "subnet_ids" {value = { for name, subnet in aws_subnet.this : name => subnet.id }}
Project: build a reusable VPC module with public and private subnets, typed inputs and outputs. Configure protected remote state, keep development and production state separate, and practise importing an existing resource and reviewing drift in a disposable environment.
What You Should Be Able to Do
Explain state and remote backends, use modules and meta-arguments, import existing resources, detect drift and build a cloud network with clear environment boundaries.

Figure: Terraform compares desired configuration with state and the remote infrastructure it manages.
You can also explore this interactive lab: https://meek-hummingbird-a076b2.netlify.app
Level Summary
You can now manage more complex infrastructure through state practices, reusable modules, remote backends, environment design, imports and cloud resource composition.
Terraform Tutorial
Harini A









