Solution architecture outcome pattern: agent and its MCP servers
Some checks failed
check agents / check (push) Failing after 13s
Some checks failed
check agents / check (push) Failing after 13s
The cp1-solution-architecture-agent and the sa-aws/azure/gcp-cloud MCP servers, a separate stream from the individual and sub-agent patterns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
---
|
||||
name: aws-iac-patterns
|
||||
description: >-
|
||||
Terraform patterns for AWS products that validate against one pinned version
|
||||
of the hashicorp/aws provider: VPC, IAM roles, ECS on Fargate, Lambda, RDS, S3,
|
||||
Secrets Manager and CloudWatch. Use when writing Terraform for an AWS product,
|
||||
before writing the resource.
|
||||
metadata:
|
||||
scope: deployment guidance
|
||||
provider: hashicorp/aws 6.10.0
|
||||
---
|
||||
|
||||
# AWS IaC patterns
|
||||
|
||||
Every pattern here passes `terraform validate` against `hashicorp/aws 6.10.0`. A test runs that on each of them, so an argument you copy from a pattern is in the right block.
|
||||
|
||||
## How to use them
|
||||
|
||||
1. Write `assets/versions.tf` to your working copy as `terraform/versions.tf`, unchanged. It pins the provider version these patterns and the `terraform_schema` tool describe. Declare the `region` variable in `terraform/variables.tf`.
|
||||
2. For each Element in the Target architecture, read the reference for its product with `load_skill_resource` and start from its pattern. Read only the references for products the Target architecture uses.
|
||||
3. Change the pattern to meet the Element's Checks. For a setting the pattern does not show, call `terraform_schema` with `find` set to its name before you write it.
|
||||
|
||||
| Product | Reference |
|
||||
| --- | --- |
|
||||
| VPC | `references/vpc.md` |
|
||||
| IAM role | `references/iam-role.md` |
|
||||
| ECS on Fargate | `references/ecs-fargate.md` |
|
||||
| Lambda | `references/lambda.md` |
|
||||
| RDS PostgreSQL | `references/rds.md` |
|
||||
| S3 bucket | `references/s3.md` |
|
||||
| Secrets Manager | `references/secrets-manager.md` |
|
||||
| CloudWatch alarm | `references/cloudwatch.md` |
|
||||
|
||||
For a product with no reference, use `terraform_schema` to find its resource type and arguments. Never write an argument you haven't confirmed.
|
||||
@@ -0,0 +1,13 @@
|
||||
terraform {
|
||||
required_version = ">= 1.9"
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = "6.10.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "aws" {
|
||||
region = var.region
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
# CloudWatch alarm
|
||||
|
||||
An alarm that notifies an SNS topic.
|
||||
|
||||
```hcl
|
||||
resource "aws_sns_topic" "on_call" {
|
||||
name = "on-call"
|
||||
kms_master_key_id = "alias/aws/sns"
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_metric_alarm" "errors" {
|
||||
alarm_name = "ingest-errors"
|
||||
namespace = "AWS/Lambda"
|
||||
metric_name = "Errors"
|
||||
statistic = "Sum"
|
||||
period = 300
|
||||
evaluation_periods = 1
|
||||
threshold = 1
|
||||
comparison_operator = "GreaterThanOrEqualToThreshold"
|
||||
treat_missing_data = "notBreaching"
|
||||
alarm_actions = [aws_sns_topic.on_call.arn]
|
||||
|
||||
dimensions = {
|
||||
FunctionName = "ingest"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,82 @@
|
||||
# ECS on Fargate
|
||||
|
||||
A service on Fargate in private subnets, with logs and a deployment circuit breaker.
|
||||
|
||||
```hcl
|
||||
variable "image" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "execution_role_arn" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "task_role_arn" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "subnet_ids" {
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
variable "security_group_ids" {
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
resource "aws_ecs_cluster" "main" {
|
||||
name = "workload"
|
||||
|
||||
setting {
|
||||
name = "containerInsights"
|
||||
value = "enabled"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_log_group" "api" {
|
||||
name = "/ecs/api"
|
||||
retention_in_days = 90
|
||||
}
|
||||
|
||||
resource "aws_ecs_task_definition" "api" {
|
||||
family = "api"
|
||||
requires_compatibilities = ["FARGATE"]
|
||||
network_mode = "awsvpc"
|
||||
cpu = "512"
|
||||
memory = "1024"
|
||||
execution_role_arn = var.execution_role_arn
|
||||
task_role_arn = var.task_role_arn
|
||||
container_definitions = jsonencode([{
|
||||
name = "api"
|
||||
image = var.image
|
||||
essential = true
|
||||
portMappings = [{ containerPort = 8080 }]
|
||||
logConfiguration = {
|
||||
logDriver = "awslogs"
|
||||
options = {
|
||||
awslogs-group = aws_cloudwatch_log_group.api.name
|
||||
awslogs-region = var.region
|
||||
awslogs-stream-prefix = "api"
|
||||
}
|
||||
}
|
||||
}])
|
||||
}
|
||||
|
||||
resource "aws_ecs_service" "api" {
|
||||
name = "api"
|
||||
cluster = aws_ecs_cluster.main.id
|
||||
task_definition = aws_ecs_task_definition.api.arn
|
||||
launch_type = "FARGATE"
|
||||
desired_count = 2
|
||||
|
||||
network_configuration {
|
||||
subnets = var.subnet_ids
|
||||
security_groups = var.security_group_ids
|
||||
assign_public_ip = false
|
||||
}
|
||||
|
||||
deployment_circuit_breaker {
|
||||
enable = true
|
||||
rollback = true
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,37 @@
|
||||
# IAM role
|
||||
|
||||
A role a service assumes, with an inline policy of named actions on named resources.
|
||||
|
||||
```hcl
|
||||
variable "bucket_arn" {
|
||||
type = string
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "assume" {
|
||||
statement {
|
||||
actions = ["sts:AssumeRole"]
|
||||
principals {
|
||||
type = "Service"
|
||||
identifiers = ["ecs-tasks.amazonaws.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "read" {
|
||||
statement {
|
||||
actions = ["s3:GetObject"]
|
||||
resources = ["${var.bucket_arn}/*"]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_role" "task" {
|
||||
name = "app-task"
|
||||
assume_role_policy = data.aws_iam_policy_document.assume.json
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy" "read" {
|
||||
name = "read-objects"
|
||||
role = aws_iam_role.task.id
|
||||
policy = data.aws_iam_policy_document.read.json
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,43 @@
|
||||
# Lambda
|
||||
|
||||
A function from a package in S3, with tracing and a dead-letter queue.
|
||||
|
||||
```hcl
|
||||
variable "role_arn" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "package_bucket" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "package_key" {
|
||||
type = string
|
||||
}
|
||||
|
||||
resource "aws_sqs_queue" "dead_letters" {
|
||||
name = "ingest-dlq"
|
||||
message_retention_seconds = 1209600
|
||||
sqs_managed_sse_enabled = true
|
||||
}
|
||||
|
||||
resource "aws_lambda_function" "ingest" {
|
||||
function_name = "ingest"
|
||||
role = var.role_arn
|
||||
runtime = "python3.13"
|
||||
handler = "app.handler"
|
||||
s3_bucket = var.package_bucket
|
||||
s3_key = var.package_key
|
||||
architectures = ["arm64"]
|
||||
timeout = 30
|
||||
memory_size = 512
|
||||
|
||||
dead_letter_config {
|
||||
target_arn = aws_sqs_queue.dead_letters.arn
|
||||
}
|
||||
|
||||
tracing_config {
|
||||
mode = "Active"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,33 @@
|
||||
# RDS PostgreSQL
|
||||
|
||||
Multi-AZ, encrypted, private, with deletion protection and a password managed by AWS.
|
||||
|
||||
```hcl
|
||||
variable "db_subnet_group" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "security_group_ids" {
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
resource "aws_db_instance" "main" {
|
||||
identifier = "workload"
|
||||
engine = "postgres"
|
||||
engine_version = "16"
|
||||
instance_class = "db.m7g.large"
|
||||
allocated_storage = 100
|
||||
storage_type = "gp3"
|
||||
storage_encrypted = true
|
||||
multi_az = true
|
||||
publicly_accessible = false
|
||||
db_subnet_group_name = var.db_subnet_group
|
||||
vpc_security_group_ids = var.security_group_ids
|
||||
username = "app_admin"
|
||||
manage_master_user_password = true
|
||||
backup_retention_period = 14
|
||||
deletion_protection = true
|
||||
skip_final_snapshot = false
|
||||
final_snapshot_identifier = "workload-final"
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,49 @@
|
||||
# S3 bucket
|
||||
|
||||
Public access blocked, encrypted, versioned, with a lifecycle rule.
|
||||
|
||||
```hcl
|
||||
resource "aws_s3_bucket" "main" {
|
||||
bucket = "workload-data-001"
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_public_access_block" "main" {
|
||||
bucket = aws_s3_bucket.main.id
|
||||
block_public_acls = true
|
||||
block_public_policy = true
|
||||
ignore_public_acls = true
|
||||
restrict_public_buckets = true
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_server_side_encryption_configuration" "main" {
|
||||
bucket = aws_s3_bucket.main.id
|
||||
rule {
|
||||
apply_server_side_encryption_by_default {
|
||||
sse_algorithm = "aws:kms"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_versioning" "main" {
|
||||
bucket = aws_s3_bucket.main.id
|
||||
versioning_configuration {
|
||||
status = "Enabled"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_lifecycle_configuration" "main" {
|
||||
bucket = aws_s3_bucket.main.id
|
||||
rule {
|
||||
id = "tier-and-expire"
|
||||
status = "Enabled"
|
||||
filter {}
|
||||
transition {
|
||||
days = 30
|
||||
storage_class = "STANDARD_IA"
|
||||
}
|
||||
noncurrent_version_expiration {
|
||||
noncurrent_days = 90
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,16 @@
|
||||
# Secrets Manager
|
||||
|
||||
A secret encrypted with a customer-managed key. Values never go in Terraform.
|
||||
|
||||
```hcl
|
||||
resource "aws_kms_key" "secrets" {
|
||||
description = "Workload secrets"
|
||||
enable_key_rotation = true
|
||||
}
|
||||
|
||||
resource "aws_secretsmanager_secret" "api_key" {
|
||||
name = "workload/api-key"
|
||||
kms_key_id = aws_kms_key.secrets.arn
|
||||
recovery_window_in_days = 30
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,39 @@
|
||||
# VPC
|
||||
|
||||
Private and public subnets in two Availability Zones. Add NAT, routes and endpoints as the design needs.
|
||||
|
||||
```hcl
|
||||
variable "zones" {
|
||||
type = list(string)
|
||||
}
|
||||
|
||||
resource "aws_vpc" "main" {
|
||||
cidr_block = "10.0.0.0/16"
|
||||
enable_dns_hostnames = true
|
||||
enable_dns_support = true
|
||||
}
|
||||
|
||||
resource "aws_subnet" "private" {
|
||||
count = 2
|
||||
vpc_id = aws_vpc.main.id
|
||||
availability_zone = var.zones[count.index]
|
||||
cidr_block = cidrsubnet(aws_vpc.main.cidr_block, 4, count.index)
|
||||
}
|
||||
|
||||
resource "aws_flow_log" "main" {
|
||||
vpc_id = aws_vpc.main.id
|
||||
traffic_type = "ALL"
|
||||
log_destination_type = "cloud-watch-logs"
|
||||
log_destination = aws_cloudwatch_log_group.flow.arn
|
||||
iam_role_arn = var.flow_log_role_arn
|
||||
}
|
||||
|
||||
variable "flow_log_role_arn" {
|
||||
type = string
|
||||
}
|
||||
|
||||
resource "aws_cloudwatch_log_group" "flow" {
|
||||
name = "/vpc/flow"
|
||||
retention_in_days = 90
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user