AWS CloudFront CDN with Terraform - Complete Guide
Deploy AWS CloudFront distributions with Terraform. S3 origin, ALB origin, custom domains, SSL certificates, cache policies, and WAF integration.
Terraform
Deploy AWS ElastiCache Redis with Terraform. Cluster mode, replication groups, subnet groups, encryption, and parameter group configuration.
resource "aws_elasticache_replication_group" "redis" {
replication_group_id = "my-redis"
description = "Redis cluster"
engine = "redis"
node_type = "cache.t4g.micro"
num_cache_clusters = 2
port = 6379
subnet_group_name = aws_elasticache_subnet_group.main.name
security_group_ids = [aws_security_group.redis.id]
at_rest_encryption_enabled = true
transit_encryption_enabled = true
}resource "aws_elasticache_subnet_group" "main" {
name = "${var.project}-redis"
subnet_ids = aws_subnet.private[*].id
}
resource "aws_security_group" "redis" {
name = "${var.project}-redis"
vpc_id = aws_vpc.main.id
ingress {
from_port = 6379
to_port = 6379
protocol = "tcp"
security_groups = [aws_security_group.app.id]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}resource "aws_elasticache_parameter_group" "redis7" {
name = "${var.project}-redis7"
family = "redis7"
parameter {
name = "maxmemory-policy"
value = "allkeys-lru"
}
}
resource "aws_elasticache_replication_group" "redis" {
replication_group_id = "${var.project}-redis"
description = "${var.project} Redis cluster"
engine = "redis"
engine_version = "7.1"
node_type = var.redis_node_type
num_cache_clusters = 2 # Primary + 1 replica
port = 6379
subnet_group_name = aws_elasticache_subnet_group.main.name
security_group_ids = [aws_security_group.redis.id]
parameter_group_name = aws_elasticache_parameter_group.redis7.name
at_rest_encryption_enabled = true
transit_encryption_enabled = true
auth_token = var.redis_auth_token
automatic_failover_enabled = true
multi_az_enabled = true
snapshot_retention_limit = 7
snapshot_window = "03:00-05:00"
maintenance_window = "sun:05:00-sun:07:00"
apply_immediately = false
tags = { Environment = var.environment }
timeouts {
create = "30m"
update = "30m"
delete = "30m"
}
}
output "redis_endpoint" {
value = aws_elasticache_replication_group.redis.primary_endpoint_address
}resource "aws_elasticache_replication_group" "redis_cluster" {
replication_group_id = "${var.project}-redis-cluster"
description = "Redis cluster mode enabled"
engine = "redis"
engine_version = "7.1"
node_type = "cache.r7g.large"
port = 6379
parameter_group_name = "default.redis7.cluster.on"
num_node_groups = 3 # 3 shards
replicas_per_node_group = 1 # 1 replica per shard
subnet_group_name = aws_elasticache_subnet_group.main.name
security_group_ids = [aws_security_group.redis.id]
at_rest_encryption_enabled = true
transit_encryption_enabled = true
automatic_failover_enabled = true
}
output "redis_config_endpoint" {
value = aws_elasticache_replication_group.redis_cluster.configuration_endpoint_address
}| Type | vCPU | Memory | Use Case |
|---|---|---|---|
cache.t4g.micro | 2 | 0.5 GB | Dev/test |
cache.t4g.medium | 2 | 3.09 GB | Small production |
cache.r7g.large | 2 | 13.07 GB | Production |
cache.r7g.xlarge | 4 | 26.32 GB | High memory |
Use replication groups (not standalone clusters) for production Redis. Enable automatic failover, multi-AZ, encryption at rest and in transit, and daily snapshots. Use cache.t4g for dev and cache.r7g for production. Set maxmemory-policy to allkeys-lru to handle memory pressure gracefully.
Deploy AWS CloudFront distributions with Terraform. S3 origin, ALB origin, custom domains, SSL certificates, cache policies, and WAF integration.
Deploy AWS Kinesis Data Streams with Terraform. Stream configuration, shard management, Lambda consumers, Firehose delivery, and encryption settings.
Deploy AWS Lambda functions with Terraform. Complete guide with IAM roles, API Gateway triggers, S3 triggers, layers, environment variables, and VPC...
Deploy AWS MSK (Managed Streaming for Kafka) with Terraform. Cluster configuration, MSK Serverless, encryption, monitoring, and topic management.