islamelkadi/terraform-aws-sqs
GitHub: islamelkadi/terraform-aws-sqs
一个生产就绪的 AWS SQS Terraform 模块,内置多框架合规支持和环境自适应安全控制。
Stars: 0 | Forks: 0
# Terraform AWS SQS 模块
[](https://github.com/islamelkadi/terraform-aws-sqs/actions/workflows/terraform-security.yaml)
[](https://github.com/islamelkadi/terraform-aws-sqs/actions/workflows/terraform-lint.yaml)
[](https://github.com/islamelkadi/terraform-aws-sqs/actions/workflows/terraform-docs.yaml)
创建支持加密、死信队列 (Dead Letter Queue) 和 FIFO 功能的 AWS SQS 队列。
## 目录
- [前置条件](#prerequisites)
- [安全](#security)
- [功能特性](#features)
- [用法](#usage)
- [需求](#requirements)
- [MCP 服务器](#mcp-servers)
## 前置条件
此模块专为 macOS 设计。您的机器上必须已安装以下软件:
- Python 3 和 pip
- [Kiro](https://kiro.dev) 和 Kiro CLI
- [Homebrew](https://brew.sh)
要安装其余的开发工具,请运行:
```
make bootstrap
```
这将安装/升级:tfenv、Terraform (通过 tfenv)、tflint、terraform-docs、checkov 和 pre-commit。
## 安全
### 安全控制
此模块实施安全控制以符合以下标准:
- AWS Foundational Security Best Practices (FSBP)
- CIS AWS Foundations Benchmark
- NIST 800-53 Rev 5
- NIST 800-171 Rev 2
- PCI DSS v4.0
### 已实施的控制
- [x] **加密**:使用客户托管密钥进行 KMS 静态加密
- [x] **传输中加密**:所有消息操作使用 TLS 1.2+
- [x] **死信队列**:支持失败消息处理
- [x] **消息保留**:可配置的保留期
- [x] **访问控制**:用于队列访问管理的 IAM 策略
- [x] **安全控制覆盖**:带有审计理由的可扩展覆盖系统
### 安全最佳实践
**生产环境队列:**
- 使用 KMS 客户托管密钥进行加密
- 配置死信队列以处理错误
- 设置适当的消息保留期
- 使用 IAM 策略限制队列访问
- 在 CloudWatch 中监控队列指标
**开发环境队列:**
- 仍建议使用 KMS 加密
- 可接受较短的保留期
有关完整的安全标准和实施细节,请参阅 [AWS Security Standards](../../../.kiro/steering/aws/aws-security-standards.md)。
### 基于环境的安全控制
安全控制通过 [terraform-aws-metadata](https://github.com/islamelkadi/terraform-aws-metadata?tab=readme-ov-file#security-profiles) 模块的安全配置文件根据环境自动应用:
| Control | Dev | Staging | Prod |
|---------|-----|---------|------|
| KMS encryption | Optional | Required | Required |
| Encryption in transit (TLS 1.2+) | Required | Required | Required |
| Dead letter queue | Optional | Recommended | Required |
| Access control (IAM) | Enforced | Enforced | Enforced |
有关安全配置文件以及控制如何随环境变化的完整详细信息,请参阅 [Security Profiles](https://github.com/islamelkadi/terraform-aws-metadata?tab=readme-ov-file#security-profiles) 文档。
### 安全扫描抑制
此模块抑制了某些 Checkov 安全检查,这些检查不适用于示例/演示代码或代表可选功能。以下检查在 `.checkov.yaml` 中被抑制:
**模块源版本控制 (CKV_TF_1, CKV_TF_2)**
- 被抑制是因为我们使用语义版本标签 (`?ref=v1.0.0`) 而不是提交哈希,以提高可维护性和可读性
- 语义版本控制是稳定版本的有效且广泛接受的版本控制策略
**KMS IAM 策略 (CKV_AWS_111, CKV_AWS_356, CKV_AWS_109)**
- 在示例代码中被抑制,因为 KMS 模块使用灵活的 IAM 策略用于演示目的
- 生产部署应根据特定的安全要求定制 KMS 策略并应用最小权限原则
## 用法
### 基本示例
```
module "queue" {
source = "github.com/islamelkadi/terraform-aws-sqs"
namespace = "example"
environment = "prod"
name = "corporate-actions-dlq"
region = "us-east-1"
# KMS encryption
kms_key_arn = module.kms.key_arn
# Message retention (4 days)
message_retention_seconds = 345600
}
```
### 带死信队列
```
module "dlq" {
source = "github.com/islamelkadi/terraform-aws-sqs"
namespace = "example"
environment = "prod"
name = "corporate-actions-dlq"
region = "us-east-1"
kms_key_arn = module.kms.key_arn
}
module "main_queue" {
source = "github.com/islamelkadi/terraform-aws-sqs"
namespace = "example"
environment = "prod"
name = "corporate-actions"
region = "us-east-1"
kms_key_arn = module.kms.key_arn
# DLQ configuration
dead_letter_target_arn = module.dlq.queue_arn
max_receive_count = 3
}
```
## MCP 服务器
此模块包含两个 [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 服务器,配置于 `.kiro/settings/mcp.json` 中,用于 Kiro:
| Server | Package | Description |
|--------|---------|-------------|
| `aws-docs` | `awslabs.aws-documentation-mcp-server@latest` | 提供对 AWS 文档的访问,用于服务功能、API 参考和最佳实践的上下文查找。 |
| `terraform` | `awslabs.terraform-mcp-server@latest` | 支持直接从 IDE 执行 Terraform 操作(init、validate、plan、fmt、tflint),并为常用工作流提供自动批准的命令。 |
两个服务器都通过 `uvx` 运行,除了 [bootstrap](#prerequisites) 步骤外,无需额外安装。
## 需求
| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 1.14.3 |
| [aws](#requirement\_aws) | >= 6.34 |
## Providers
| Name | Version |
|------|---------|
| [aws](#provider\_aws) | >= 6.34 |
## 模块
| Name | Source | Version |
|------|--------|---------|
| [metadata](#module\_metadata) | github.com/islamelkadi/terraform-aws-metadata | v1.1.0 |
## 资源
| Name | Type |
|------|------|
| [aws_sqs_queue.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue) | resource |
| [aws_sqs_queue_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue_policy) | resource |
## 输入变量
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [attributes](#input\_attributes) | 用于命名的额外属性 | `list(string)` | `[]` | no |
| [content\_based\_deduplication](#input\_content\_based\_deduplication) | 为 FIFO 队列启用基于内容的去重 | `bool` | `false` | no |
| [dead\_letter\_target\_arn](#input\_dead\_letter\_target\_arn) | Amazon SQS 在 maxReceiveCount 后将消息移至的死信队列的 ARN | `string` | `null` | no |
| [deduplication\_scope](#input\_deduplication\_scope) | 指定消息去重是在消息组级别还是队列级别进行 | `string` | `"queue"` | no |
| [delimiter](#input\_delimiter) | 用于名称组件之间的分隔符 | `string` | `"-"` | no |
| [environment](#input\_environment) | 环境名称 (dev, staging, prod) | `string` | n/a | yes |
| [fifo\_queue](#input\_fifo\_queue) | 此队列是否为 FIFO 队列 | `bool` | `false` | no |
| [fifo\_throughput\_limit](#input\_fifo\_throughput\_limit) | 指定 FIFO 队列吞吐量配额是应用于整个队列还是每个消息组 | `string` | `"perQueue"` | no |
| [kms\_data\_key\_reuse\_period\_seconds](#input\_kms\_data\_key\_reuse\_period\_seconds) | Amazon SQS 可以重用数据密钥的时间长度(以秒为单位) | `number` | `300` | no |
| [kms\_key\_arn](#input\_kms\_key\_arn) | 用于静态加密的 KMS 密钥的 ARN | `string` | `null` | no |
| [max\_receive\_count](#input\_max\_receive\_count) | 消息在发送到 DLQ 之前可以被接收的最大次数 | `number` | `3` | no |
| [message\_retention\_seconds](#input\_message\_retention\_seconds) | Amazon SQS 保留消息的秒数 (60-1209600) | `number` | `345600` | no |
| [name](#input\_name) | SQS 队列的名称 | `string` | n/a | yes |
| [namespace](#input\_namespace) | 命名空间(组织/团队名称) | `string` | n/a | yes |
| [queue\_policy](#input\_queue\_policy) | 队列的 JSON 策略文档 | `string` | `null` | no |
| [receive\_wait\_time\_seconds](#input\_receive\_wait\_time\_seconds) | ReceiveMessage 调用等待消息到达的时间(长轮询) | `number` | `0` | no |
| [region](#input\_region) | 将创建资源的 AWS 区域 | `string` | n/a | yes |
| [security\_control\_overrides](#input\_security\_control\_overrides) | 通过记录的理由覆盖特定的安全控制 |
object({
disable_kms_requirement = optional(bool, false)
justification = optional(string, "")
}) | {
"disable_kms_requirement": false,
"justification": ""
} | no |
| [security\_controls](#input\_security\_controls) | 来自 metadata 模块的安全控制配置 | object({
encryption = object({
require_kms_customer_managed = bool
require_encryption_at_rest = bool
require_encryption_in_transit = bool
enable_kms_key_rotation = bool
})
}) | `null` | no |
| [tags](#input\_tags) | 应用到资源的额外标签 | `map(string)` | `{}` | no |
| [visibility\_timeout\_seconds](#input\_visibility\_timeout\_seconds) | 队列的可见性超时时间(以秒为单位) | `number` | `30` | no |
## 输出
| Name | Description |
|------|-------------|
| [queue\_arn](#output\_queue\_arn) | SQS 队列的 ARN |
| [queue\_id](#output\_queue\_id) | SQS 队列的 URL |
| [queue\_name](#output\_queue\_name) | SQS 队列的名称 |
| [queue\_url](#output\_queue\_url) | SQS 队列的 URL |
| [tags](#output\_tags) | 应用到 SQS 队列的标签 |
标签:ATTACK-Python-Client, AWS FSBP, AWS SQS, CIS Benchmark, Cloud Computing, EC2, ECS, FIFO 队列, IaC, KMS 加密, NIST 800-53, PCI DSS, Python, Terraform, TFLint, 企业级, 安全合规, 无后门, 模块, 死信队列, 消息队列, 特权提升, 生产就绪, 端到端加密, 网络代理, 自动化部署, 逆向工具, 预提交检查