Sync: add infrastructure as code notes
This commit is contained in:
78
wiki/entities/AWS-Lambda.md
Normal file
78
wiki/entities/AWS-Lambda.md
Normal file
@@ -0,0 +1,78 @@
|
||||
---
|
||||
title: "AWS Lambda"
|
||||
type: entity
|
||||
tags:
|
||||
- AWS
|
||||
- Serverless
|
||||
- Compute
|
||||
- Lambda
|
||||
sources:
|
||||
- public-cloud-learning-sessions-opentext-serverless-computing-20240903-160139-mee
|
||||
last_updated: 2026-04-14
|
||||
---
|
||||
|
||||
## Aliases
|
||||
- Lambda
|
||||
- AWS Lambda
|
||||
|
||||
## Definition
|
||||
|
||||
AWS Lambda 是 AWS 的无服务器(Serverless)计算服务——开发者只需编写业务逻辑函数(Handler),AWS 负责所有底层运维:负载均衡、自动扩展、安全补丁和容量管理。Lambda 函数由事件(event)触发,事件即云资源状态的任何变化。
|
||||
|
||||
## Core Properties
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| 触发模式 | 同步调用、异步调用、事件源映射 |
|
||||
| 权限模型 | 执行角色(Execution Role)+ 资源策略(Resource-Based Policy) |
|
||||
| 代码管理 | 版本(Version)、别名(Alias)、Layers(共享公共依赖) |
|
||||
| 架构支持 | x86 和 ARM64(ARM64 提供更优性价比) |
|
||||
| 监控 | CloudWatch 指标(请求数、错误数、延迟、节流) |
|
||||
| 调试工具 | Amazon Q(集成 AI 辅助调试) |
|
||||
| 性能调优 | Lambda Power Tuning(比较不同配置的性能和成本) |
|
||||
|
||||
## Lambda Handler 模式
|
||||
|
||||
Lambda 函数接收三个核心参数:
|
||||
|
||||
1. **Handler** — 入口函数,事件触发时执行
|
||||
2. **Event Object** — 触发事件的数据结构(API Gateway 请求、S3 对象变更等)
|
||||
3. **Context Object** — 运行时信息(超时设置、内存限制、日志句柄等)
|
||||
|
||||
## Invocation Patterns
|
||||
|
||||
- **同步调用(Synchronous)**:调用方等待响应,如 API Gateway → Lambda
|
||||
- **异步调用(Asynchronous)**:Lambda 自动处理重试(最多 2 次),如 S3 事件 → Lambda
|
||||
- **事件源映射(Event Source Mapping)**:Lambda 轮询流式服务(Kinesis、DynamoDB Stream、SQS)批量处理记录
|
||||
|
||||
## Permissions Model
|
||||
|
||||
Lambda 权限模型基于 IAM 的最小权限原则:
|
||||
|
||||
| 权限类型 | 作用对象 | 说明 |
|
||||
|---------|---------|------|
|
||||
| Execution Role | Lambda 函数 | 定义函数能调用哪些 AWS 资源和服务 |
|
||||
| Resource-Based Policy | 其他 AWS 账号/服务 | 定义谁能/什么能触发该 Lambda 函数 |
|
||||
|
||||
## Lambda Layers
|
||||
|
||||
Lambda Layers 允许跨多个 Lambda 函数共享公共代码和依赖:
|
||||
- 运行时环境(如 Python boto3 库)
|
||||
- 自定义运行时
|
||||
- 配置和脚本
|
||||
|
||||
Layers 避免了每个函数重复打包相同依赖,减少部署包大小和更新成本。
|
||||
|
||||
## Connections
|
||||
- [[Serverless-Computing]] ← is_core_service_of ← [[AWS-Lambda]]
|
||||
- [[AWS-Lambda]] ← triggered_by ← [[Amazon-EventBridge]]
|
||||
- [[AWS-Lambda]] ← exposed_via ← [[Amazon-API-Gateway]]
|
||||
- [[AWS-Lambda]] ← orchestrated_by ← [[AWS-Step-Functions]]
|
||||
- [[AWS-Lambda]] ← monitored_by ← [[CloudWatch]]
|
||||
- [[SAM-Serverless-Application-Model]] ← deploys ← [[AWS-Lambda]]
|
||||
|
||||
## Related Entities
|
||||
- [[Amazon-API-Gateway]] — Lambda 的 API 暴露层
|
||||
- [[AWS-Step-Functions]] — Lambda 的工作流编排层
|
||||
- [[Amazon-EventBridge]] — Lambda 的事件驱动触发源
|
||||
- [[CloudWatch]] — Lambda 的监控和日志层
|
||||
56
wiki/entities/AWS-Step-Functions.md
Normal file
56
wiki/entities/AWS-Step-Functions.md
Normal file
@@ -0,0 +1,56 @@
|
||||
---
|
||||
title: "AWS Step Functions"
|
||||
type: entity
|
||||
tags:
|
||||
- AWS
|
||||
- Serverless
|
||||
- Workflow
|
||||
- Orchestration
|
||||
sources:
|
||||
- public-cloud-learning-sessions-opentext-serverless-computing-20240903-160139-mee
|
||||
last_updated: 2026-04-14
|
||||
---
|
||||
|
||||
## Aliases
|
||||
- Step Functions
|
||||
- AWS Step Functions
|
||||
- Amazon Step Functions
|
||||
|
||||
## Definition
|
||||
|
||||
AWS Step Functions 是 AWS 的无服务器工作流编排服务,基于状态机(State Machine)协调多个 Lambda 函数和 AWS 服务的执行顺序和错误处理逻辑,使开发者无需编写复杂的编排代码即可构建可靠的多步骤业务流程。
|
||||
|
||||
## Core Properties
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| 核心抽象 | 状态机(Standard 和 Express 两种) |
|
||||
| Standard 工作流 | 长时运行,最长 1 年,支持精确执行历史 |
|
||||
| Express 工作流 | 高频场景,最长 5 分钟,支持极高吞吐量 |
|
||||
| 状态类型 | Task、Choice、Wait、Pass、Parallel、Map、End、Throw |
|
||||
| 错误处理 | 内置 Retry、Catch 和 Error 字段 |
|
||||
| 可视化 | 自动生成工作流图形,直观展示执行路径 |
|
||||
|
||||
## Workflow Flavors
|
||||
|
||||
| 类型 | 适用场景 | 执行时长 | 计费模式 |
|
||||
|------|---------|---------|---------|
|
||||
| Standard | 长时业务流程、审批流、数据处理管道 | 最长 1 年 | 按状态转换计费 |
|
||||
| Express | 高频事件处理、IoT 数据流水线、实时流处理 | 最长 5 分钟 | 按执行次数+GB/s计费 |
|
||||
|
||||
## State Types
|
||||
|
||||
Step Functions 提供丰富的状态类型构建复杂工作流:
|
||||
|
||||
- **Task**:执行单个原子工作单元(如调用 Lambda、DynamoDB 操作)
|
||||
- **Choice**:条件分支,基于数据动态路由执行路径
|
||||
- **Wait**:等待指定时间(用于轮询、重试间隔)
|
||||
- **Pass**:直接传递输入到输出(数据转换)
|
||||
- **Parallel**:并行执行多个分支,汇合结果
|
||||
- **Map**:迭代处理数组中的每个元素
|
||||
- **End/Try-Throw**:终止和错误处理
|
||||
|
||||
## Connections
|
||||
- [[AWS-Step-Functions]] ← orchestrates ← [[AWS-Lambda]]
|
||||
- [[AWS-Step-Functions]] ← is_a ← [[Serverless-Computing]]
|
||||
- [[AWS-Step-Functions]] ← triggers ← [[Amazon-EventBridge]]
|
||||
60
wiki/entities/Amazon-API-Gateway.md
Normal file
60
wiki/entities/Amazon-API-Gateway.md
Normal file
@@ -0,0 +1,60 @@
|
||||
---
|
||||
title: "Amazon API Gateway"
|
||||
type: entity
|
||||
tags:
|
||||
- AWS
|
||||
- Serverless
|
||||
- API
|
||||
- Networking
|
||||
sources:
|
||||
- public-cloud-learning-sessions-opentext-serverless-computing-20240903-160139-mee
|
||||
last_updated: 2026-04-14
|
||||
---
|
||||
|
||||
## Aliases
|
||||
- API Gateway
|
||||
- Amazon API Gateway
|
||||
- AWS API Gateway
|
||||
|
||||
## Definition
|
||||
|
||||
Amazon API Gateway 是 AWS 的全托管 API 管理服务,用于创建、发布、维护和监控安全的企业级 REST、HTTP 和 WebSocket API。API Gateway 作为 Lambda 函数和其他后端服务的统一入口,提供流量管理、授权和访问控制、监控等企业级能力。
|
||||
|
||||
## Core Properties
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| API 类型 | REST API、HTTP API、WebSocket API |
|
||||
| 部署选项 | Edge-Optimized、Regional、Private |
|
||||
| 认证方式 | IAM 角色、Lambda Authorizer、Cognito、API Key |
|
||||
| 协议 | HTTPS(TLS 终止由 AWS 管理) |
|
||||
| 限流 | 按账户/按 API/按客户多级限流 |
|
||||
| 缓存 | 可选 API 缓存,提升响应速度 |
|
||||
| 监控 | CloudWatch 集成,提供延迟、错误率等指标 |
|
||||
|
||||
## Deployment Options
|
||||
|
||||
| 选项 | 说明 | 适用场景 |
|
||||
|------|------|---------|
|
||||
| Edge-Optimized | 通过 CloudFront CDN 全球分发,低延迟 | 面向全球用户的公共 API |
|
||||
| Regional | 部署在单一区域,自带高可用 | 面向同区域用户、VPC 内的 API |
|
||||
| Private | 仅可通过 VPC 内部端点访问 | 企业内部 API、微服务间通信 |
|
||||
|
||||
## Typical Architecture
|
||||
|
||||
```
|
||||
客户端 → API Gateway → Lambda Function → DynamoDB/SQS/etc.
|
||||
```
|
||||
|
||||
API Gateway 负责:
|
||||
1. TLS 终止(安全)
|
||||
2. 请求验证(格式、参数)
|
||||
3. 限流和配额管理
|
||||
4. 授权和身份验证
|
||||
5. 请求路由到后端 Lambda
|
||||
6. 响应转换和格式统一
|
||||
|
||||
## Connections
|
||||
- [[Amazon-API-Gateway]] ← exposes ← [[AWS-Lambda]]
|
||||
- [[Amazon-API-Gateway]] ← provides ← [[Serverless-Computing]]
|
||||
- [[Amazon-API-Gateway]] ← monitored_by ← [[CloudWatch]]
|
||||
95
wiki/entities/Atlantis.md
Normal file
95
wiki/entities/Atlantis.md
Normal file
@@ -0,0 +1,95 @@
|
||||
---
|
||||
title: "Atlantis"
|
||||
type: entity
|
||||
tags:
|
||||
- devops
|
||||
- iac
|
||||
- terraform
|
||||
- gitops
|
||||
- cicd
|
||||
created: 2026-04-26
|
||||
---
|
||||
|
||||
# Atlantis
|
||||
|
||||
## Definition
|
||||
|
||||
Atlantis 是一个开源的**Terraform CI/CD 工具**,通过与 GitHub/GitLab 深度集成,将 Terraform 的 plan 和 apply 操作转移到 Pull Request(PR)评论层面,实现基础设施即代码的协作式自动化部署。
|
||||
|
||||
## Core Model: PR-Driven IaC
|
||||
|
||||
Atlantis 的核心理念:**每个 Pull Request 都是一次 Terraform 操作**。
|
||||
|
||||
```
|
||||
Developer Atlantis AWS Accounts
|
||||
│ │ │
|
||||
│ 1. Open PR │ │
|
||||
│───────────────────────>│ │
|
||||
│ │ 2. !atlantis plan │
|
||||
│ │───────────────────────>│
|
||||
│ │<───────────────────────│ 3. terraform plan
|
||||
│ 4. Post plan result │ │
|
||||
│<───────────────────────│ │
|
||||
│ 5. Review & Approve │ │
|
||||
│───────────────────────>│ │
|
||||
│ │ 6. !atlantis apply │
|
||||
│ │───────────────────────>│
|
||||
│ │<───────────────────────│ 7. terraform apply
|
||||
│ 8. Merge PR │ │
|
||||
│───────────────────────>│ │
|
||||
```
|
||||
|
||||
**来源**: [[ctp-topic-32-using-atlantis-cicd-for-infrastructure-deployments]]
|
||||
|
||||
## Key Features
|
||||
|
||||
| 特性 | 说明 |
|
||||
|------|------|
|
||||
| **PR 评论触发** | 无需独立 CI 账号,开发者在 PR 上评论即可 |
|
||||
| **并行 plan/apply** | 多模块并发执行,提升部署效率 |
|
||||
| **锁定机制** | 防止多 PR 同时操作同一模块产生冲突 |
|
||||
| **跨账户访问** | 通过 IAM 角色实现多 AWS 账户部署 |
|
||||
| **零额外基础设施** | 只需一台 EC2 共享账户实例 |
|
||||
|
||||
**来源**: [[ctp-topic-32-using-atlantis-cicd-for-infrastructure-deployments]]
|
||||
|
||||
## Comparison: Atlantis vs Jenkins
|
||||
|
||||
| 维度 | Atlantis | Jenkins |
|
||||
|------|----------|---------|
|
||||
| 触发方式 | PR 评论 | SCM 轮询/定时 |
|
||||
| 初始化速度 | 快速(按需) | 慢(Jenkins 预配置) |
|
||||
| 代码克隆 | 单次 | 多次 |
|
||||
| 测试执行 | 并行 | 顺序 |
|
||||
| 架构复杂度 | 简单 | 复杂(持续叠加功能) |
|
||||
| Terraform 专用 | ✅ 是 | ❌ 通用(需配置) |
|
||||
| PR 协作 | ✅ 原生 | ❌ 无 |
|
||||
|
||||
**来源**: [[ctp-topic-32-using-atlantis-cicd-for-infrastructure-deployments]]
|
||||
|
||||
## Micro Focus Usage
|
||||
|
||||
Micro Focus 在 Labs Landing Zone 中使用 Atlantis 替代 Jenkins 进行 Terraform IaC 部署:
|
||||
- 每个 Landing Zone 共享账户部署单台 EC2 实例
|
||||
- GitHub Enterprise Webhook 接收 PR 事件
|
||||
- 服务账号负责评论/合并/关闭 PR
|
||||
- Atlantis 在 merge 前即应用变更
|
||||
|
||||
**局限性**: Atlantis 当前不支持 EKS 部署,需通过 Jenkins + Terragrunt 模块替代。
|
||||
|
||||
**来源**: [[ctp-topic-32-using-atlantis-cicd-for-infrastructure-deployments]], [[ctp-topic-39-implementing-eks-in-the-aws-lab-landing-zone]]
|
||||
|
||||
## Related Entities
|
||||
|
||||
- [[Terraform]] — Atlantis 操作的核心 IaC 工具
|
||||
- [[Gruntwork]] — Terragrunt 的开发者(Atlantis 生态伙伴)
|
||||
|
||||
## Related Concepts
|
||||
|
||||
- [[GitOps]] — Atlantis 是 GitOps 在 Terraform 领域的实现工具
|
||||
- [[CI/CD Pipeline]] — Atlantis 提供 CI/CD 能力
|
||||
|
||||
## Related Sources
|
||||
|
||||
- [[ctp-topic-32-using-atlantis-cicd-for-infrastructure-deployments]]
|
||||
- [[ctp-topic-39-implementing-eks-in-the-aws-lab-landing-zone]]
|
||||
@@ -1,30 +1,32 @@
|
||||
---
|
||||
title: "Gruntwork"
|
||||
type: entity
|
||||
sources: [ctp-topic-17-active-directory-services-in-gruntwork-aws-lzs]
|
||||
last_updated: 2026-04-14
|
||||
tags: [AWS, IaC, DevOps, Terraform]
|
||||
sources: [ctp-topic-9-ci-cd-with-gruntwork, ctp-topic-48-terraform-vs-terragrunt, learning-sessions-ecs-deployment-using-iac-20230808-183322-meeting-recording]
|
||||
last_updated: 2026-05-05
|
||||
---
|
||||
|
||||
# Gruntwork
|
||||
|
||||
## Overview
|
||||
Gruntwork 是 Micro Focus Cloud Transformation Programme (CTP) 中采用的 AWS Landing Zones 基础设施框架提供方。Gruntwork Landing Zones 提供预配置的、基于最佳实践的 AWS 基础架构模板,帮助企业快速构建符合安全和合规要求的 AWS 多账户架构。
|
||||
Gruntwork 是一家专注于 AWS 基础设施即代码(IaC)的公司,提供预构建、可定制的 Terraform 模块库,帮助团队快速构建生产级云基础设施。
|
||||
|
||||
## Aliases
|
||||
- Gruntwork AWS Landing Zones
|
||||
- Gruntwork LZ
|
||||
## Products
|
||||
- **Gruntwork Landing Zone Architecture**:基于 Terraform/Terragrunt 的 AWS Landing Zone 参考架构,涵盖账户结构、网络、安全、运维等基础设施层
|
||||
- **Gruntwork Infrastructure Live**:生产级 Terraform 模块库,支持多账户、多区域部署
|
||||
- **Pipelines**:Gruntwork 推荐的 CI/CD 流水线方案,集成 GitHub Actions/Jenkins
|
||||
|
||||
## Key Capabilities
|
||||
- **多环境支持**:区分 R&D Labs 和 SAS(Staging/Production)两种环境类型,分别对应不同的 AD 域名架构
|
||||
- **预制 AMI**:SRE 团队维护内置域加入脚本的标准化机器镜像
|
||||
- **IaC 集成**:与 Terraform/TerraGrunt 深度集成,支持 `user_data` 触发自动化域加入流程
|
||||
- **AD 集成**:提供标准化的 Active Directory 服务集成方案,包括 DNS 管理和安全动态更新
|
||||
## Key Modules
|
||||
- **ECS 模块**:Docker 容器部署模块,CTP/SRE 团队在此基础上构建了自己的 ECS 模块(实现 Listener 集中管理)
|
||||
- **EKS 模块**:Kubernetes 集群部署模块
|
||||
- **Landing Zone 模块**:AWS 组织、账户、OU 架构
|
||||
|
||||
## Related Entities
|
||||
- [[SRE Team]]:构建和维护 Gruntwork LZ 中预制 AMI 的团队
|
||||
- [[Gruntwork AWS Landing Zones Overview]]:Gruntwork LZ 的整体架构概述
|
||||
- [[ctp-topic-17-active-directory-services-in-gruntwork-aws-lzs]]:AD 服务集成的核心参考文档
|
||||
## Gruntwork in CTP Context
|
||||
- [[ctp-topic-9-ci-cd-with-gruntwork]]:CTP Topic 9 深入 Gruntwork CI/CD 实践
|
||||
- [[ctp-topic-48-terraform-vs-terragrunt]]:Terraform 与 Terragrunt 对比,Gruntwork 作为辅助工具推荐
|
||||
- [[learning-sessions-ecs-deployment-using-iac-20230808-183322-meeting-recording]]:CTP 团队在 Gruntwork 仓库基础上开发 ECS 模块
|
||||
|
||||
## References
|
||||
- [[ctp-topic-17-active-directory-services-in-gruntwork-aws-lzs]]
|
||||
- [[ctp-topic-14-octane-hub-on-aws-real-life-experience-moving-production-services-i]]
|
||||
- [[ctp-topic-9-ci-cd-with-gruntwork]]
|
||||
- [[ctp-topic-1-gruntwork-landing-zone-architecture]]
|
||||
## Connections
|
||||
- [[HashiCorp]] ← provider_of ← [[Terraform]] ← uses ← [[Gruntwork]]
|
||||
- [[Atlantis]] ← alternative_to ← [[Gruntwork-Pipelines]]
|
||||
- [[Gruntwork]] ← builds_on ← [[Infrastructure-as-Code]]
|
||||
|
||||
59
wiki/entities/HashiCorp.md
Normal file
59
wiki/entities/HashiCorp.md
Normal file
@@ -0,0 +1,59 @@
|
||||
---
|
||||
title: "HashiCorp"
|
||||
type: entity
|
||||
tags:
|
||||
- devops
|
||||
- iac
|
||||
- infrastructure
|
||||
- tools
|
||||
created: 2026-04-26
|
||||
---
|
||||
|
||||
# HashiCorp
|
||||
|
||||
## Definition
|
||||
|
||||
HashiCorp 是全球领先的**云基础设施自动化**软件公司,总部位于旧金山,创立于 2012 年。HashiCorp 提供一套完整的基础设施生命周期管理工具,覆盖配置管理、机密管理、服务网格和网络自动化等领域。
|
||||
|
||||
## Core Products
|
||||
|
||||
| 产品 | 用途 | 类别 |
|
||||
|------|------|------|
|
||||
| **Terraform** | 云厂商无关的基础设施即代码 | IaC |
|
||||
| **Vault** | 机密管理与加密即服务 | 安全 |
|
||||
| **Nomad** | 容器和工作负载调度器 | 编排 |
|
||||
| **Consul** | 服务网格与服务发现 | 网络 |
|
||||
| **Packer** | 机器镜像构建自动化 | 镜像 |
|
||||
| **Vagrant** | 开发环境管理 | 开发环境 |
|
||||
|
||||
## Terraform
|
||||
|
||||
HashiCorp 最知名的产品。Terraform 是用 Golang 编写的云无关 IaC 工具,通过声明式 HCL(HashiCorp Configuration Language)管理跨多云和混合云环境的基础设施资源。
|
||||
|
||||
**关键特性:**
|
||||
- 云厂商无关(AWS/Azure/GCP/On-prem)
|
||||
- `terraform plan` 预览变更
|
||||
- 状态文件管理实际资源与期望状态的绑定
|
||||
- 丰富的 Provider 生态系统和 Module 市场
|
||||
|
||||
**来源**: [[ctp-topic-48-terraform-vs-terragrunt]]
|
||||
|
||||
## Business Model
|
||||
|
||||
- **开源**:所有产品的开源版本
|
||||
- **Enterprise**:企业级功能(SSO、RBAC、审计日志、Sentinel 策略)
|
||||
- **HCP(HashiCorp Cloud Platform)**:SaaS 托管版本
|
||||
|
||||
## Related Entities
|
||||
|
||||
- [[Terraform]] — HashiCorp 出品的核心 IaC 产品
|
||||
- [[Terragrunt]] — 第三方 Terraform 封装工具(贯彻 DRY 原则)
|
||||
|
||||
## Related Concepts
|
||||
|
||||
- [[Infrastructure-as-Code]] — HashiCorp 产品的核心方法论
|
||||
- [[Multi-Cloud Strategy]] — Terraform 云无关定位的战略价值
|
||||
|
||||
## Related Sources
|
||||
|
||||
- [[ctp-topic-48-terraform-vs-terragrunt]]
|
||||
86
wiki/entities/SAM-Serverless-Application-Model.md
Normal file
86
wiki/entities/SAM-Serverless-Application-Model.md
Normal file
@@ -0,0 +1,86 @@
|
||||
---
|
||||
title: "SAM Serverless Application Model"
|
||||
type: entity
|
||||
tags:
|
||||
- AWS
|
||||
- Serverless
|
||||
- IaC
|
||||
- CloudFormation
|
||||
sources:
|
||||
- public-cloud-learning-sessions-opentext-serverless-computing-20240903-160139-mee
|
||||
last_updated: 2026-04-14
|
||||
---
|
||||
|
||||
## Aliases
|
||||
- SAM
|
||||
- AWS SAM
|
||||
- Serverless Application Model
|
||||
|
||||
## Definition
|
||||
|
||||
AWS SAM(Serverless Application Model)是 AWS 官方的开源 IaC 工具,基于 AWS CloudFormation 构建,专门简化无服务器应用(Lambda、API Gateway、Step Functions 等)的定义、部署和管理。SAM 提供简化的 YAML 语法,降低 CloudFormation 模板的复杂度,同时支持本地开发和测试。
|
||||
|
||||
## Core Properties
|
||||
|
||||
| 属性 | 值 |
|
||||
|------|-----|
|
||||
| 基础 | AWS CloudFormation |
|
||||
| 配置格式 | YAML(简化语法) |
|
||||
| CLI | AWS SAM CLI,支持本地调用和测试 |
|
||||
| 本地测试 | SAM Local — 本地启动 API Gateway + Lambda |
|
||||
| 部署 | `sam deploy`、`sam build`、`sam package` |
|
||||
| 应用发布 | AWS Serverless Application Repository(应用市场) |
|
||||
|
||||
## SAM vs CloudFormation
|
||||
|
||||
| 特性 | SAM | CloudFormation |
|
||||
|------|-----|----------------|
|
||||
| 语法 | 简化 YAML | JSON/YAML |
|
||||
| 资源类型 | 仅 Serverless 资源 | 全部 AWS 资源 |
|
||||
| 本地测试 | SAM Local | 不支持 |
|
||||
| 打包上传 | `sam package` | `aws cloudformation package` |
|
||||
| 模板继承 | `!Sub`、`!Ref` | 原生支持 |
|
||||
|
||||
## Typical SAM Template
|
||||
|
||||
```yaml
|
||||
AWSTemplateFormatVersion: '2010-09-09'
|
||||
Transform: AWS::Serverless-2016-10-31
|
||||
Resources:
|
||||
MyFunction:
|
||||
Type: AWS::Serverless::Function
|
||||
Properties:
|
||||
Handler: app.handler
|
||||
Runtime: python3.12
|
||||
Events:
|
||||
ApiEvent:
|
||||
Type: Api
|
||||
Properties:
|
||||
Path: /hello
|
||||
Method: get
|
||||
MyApi:
|
||||
Type: AWS::Serverless::Api
|
||||
Properties:
|
||||
StageName: prod
|
||||
DefinitionBody:
|
||||
# OpenAPI spec
|
||||
```
|
||||
|
||||
## SAM CLI 常用命令
|
||||
|
||||
| 命令 | 作用 |
|
||||
|------|------|
|
||||
| `sam init` | 初始化新 SAM 项目 |
|
||||
| `sam build` | 构建应用(处理依赖、Layer) |
|
||||
| `sam local invoke` | 本地调用 Lambda 函数 |
|
||||
| `sam local start-api` | 本地启动完整 API(API Gateway + Lambda) |
|
||||
| `sam deploy` | 交互式部署到 AWS |
|
||||
| `sam package` | 打包模板和代码到 S3 |
|
||||
| `sam validate` | 验证模板语法 |
|
||||
|
||||
## Connections
|
||||
- [[SAM-Serverless-Application-Model]] ← builds_on ← [[CloudFormation]]
|
||||
- [[SAM-Serverless-Application-Model]] ← deploys ← [[AWS-Lambda]]
|
||||
- [[SAM-Serverless-Application-Model]] ← deploys ← [[Amazon-API-Gateway]]
|
||||
- [[SAM-Serverless-Application-Model]] ← deploys ← [[AWS-Step-Functions]]
|
||||
- [[SAM-Serverless-Application-Model]] ← is_tool_of ← [[Serverless-Computing]]
|
||||
@@ -102,6 +102,36 @@ Agentic AI 在 Terraform 工作流中扮演审查者角色:
|
||||
> acl = "private" # Block public access
|
||||
> ```
|
||||
|
||||
## State File Management
|
||||
|
||||
Terraform 通过**状态文件 (state file)** 将声明式配置中定义的**期望状态**与云环境的**实际资源状态**进行绑定。关键特性:
|
||||
- **状态锁定**:防止并发执行导致状态不一致
|
||||
- **远程状态**:企业级场景需将状态文件存储在 S3(+ DynamoDB 锁)等远程后端,支持团队协作
|
||||
- **差异对比**:`terraform plan` 预览实际变更内容再执行,是 Terraform 的核心优势
|
||||
|
||||
**来源**: [[ctp-topic-48-terraform-vs-terragrunt]]
|
||||
|
||||
## Terragrunt Wrapper
|
||||
|
||||
Terragrunt 是 Terraform 的轻量封装,继承所有 Terraform 命令(HCL 语法完全兼容)。两者关系:
|
||||
- `terragrunt plan` = `terraform plan`
|
||||
- Terragrunt 通过 `remote_state` 和 `include` 块实现跨环境配置的 DRY 管理
|
||||
|
||||
**来源**: [[ctp-topic-48-terraform-vs-terragrunt]]
|
||||
|
||||
## Ecosystem Tools
|
||||
|
||||
| 工具 | 类型 | 用途 |
|
||||
|------|------|------|
|
||||
| [[Terragrunt]] | 封装 | 多环境 DRY 配置 |
|
||||
| [[Atlantis]] | CI/CD | Git PR 驱动的 plan/apply |
|
||||
| Terraform Enterprise | 平台 | 企业 CI + workspaces |
|
||||
| [[Gruntwork]] | 模块库 | 预建可复用 IaC 模块 |
|
||||
| Terratest | 测试 | IaC 集成测试(Golang) |
|
||||
| tfsec | 安全 | Terraform 静态安全分析 |
|
||||
|
||||
**来源**: [[ctp-topic-48-terraform-vs-terragrunt]], [[ctp-topic-56-automated-infrastructure-testing]]
|
||||
|
||||
## Related Concepts
|
||||
|
||||
- [[Infrastructure-as-Code]] — Terraform 是 IaC 的实现工具
|
||||
|
||||
100
wiki/entities/Terragrunt.md
Normal file
100
wiki/entities/Terragrunt.md
Normal file
@@ -0,0 +1,100 @@
|
||||
---
|
||||
title: "Terragrunt"
|
||||
type: entity
|
||||
tags:
|
||||
- devops
|
||||
- iac
|
||||
- terraform
|
||||
- automation
|
||||
created: 2026-04-26
|
||||
---
|
||||
|
||||
# Terragrunt
|
||||
|
||||
## Definition
|
||||
|
||||
Terragrunt 是由 Gruntwork 开发的**Terraform 轻量封装工具**,核心目标是贯彻 DRY(Don't Repeat Yourself)原则,简化多环境、多账户 Terraform 配置的管理。
|
||||
|
||||
## Core Value
|
||||
|
||||
Terragrunt 对 Terraform 的核心改进在于**减少重复配置**:
|
||||
|
||||
| 问题 | Terraform 方案 | Terragrunt 方案 |
|
||||
|------|---------------|----------------|
|
||||
| provider 块重复 | 每个环境独立声明 | `terragrunt.hcl` 统一管理 |
|
||||
| remote_state 块重复 | 多处硬编码 | 模板化复用 |
|
||||
| 模块引用方式 | 固定分支引用 | 版本锁定引用 |
|
||||
| 多环境同步 | 手动复制配置 | `include` 块继承 |
|
||||
|
||||
**来源**: [[ctp-topic-48-terraform-vs-terragrunt]]
|
||||
|
||||
## Compatibility
|
||||
|
||||
Terragrunt **完全兼容** Terraform 的所有命令和 HCL 语法:
|
||||
- `terragrunt plan` → 底层调用 `terraform plan`
|
||||
- `terragrunt apply` → 底层调用 `terraform apply`
|
||||
- 所有 Terraform HCL 块和属性完全兼容
|
||||
|
||||
这意味着 Terragrunt **不是** Terraform 的替代品,而是增强层。
|
||||
|
||||
**来源**: [[ctp-topic-48-terraform-vs-terragrunt]]
|
||||
|
||||
## Key Features
|
||||
|
||||
### DRY Remote State
|
||||
通过 `remote_state` 块集中管理状态文件位置:
|
||||
```hcl
|
||||
remote_state {
|
||||
backend = "s3"
|
||||
config = {
|
||||
bucket = "my-terraform-state"
|
||||
key = "${path_relative_to_include()}/terraform.tfstate"
|
||||
region = "eu-west-1"
|
||||
encrypt = true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Provider Management
|
||||
跨环境统一 provider 配置,避免在每个模块中重复声明。
|
||||
|
||||
### Include & Inheritance
|
||||
通过 `include` 块实现配置的继承与覆盖:
|
||||
```hcl
|
||||
include {
|
||||
path = find_in_parent_folders("root.hcl")
|
||||
}
|
||||
```
|
||||
|
||||
## Use Case: Micro Focus Labs Landing Zone
|
||||
|
||||
Micro Focus Labs Landing Zone 使用 Terragrunt 管理多账户配置,所有资源通过 Terraform/Terragrunt 管理,Jenkins 流水线扫描 GitHub 仓库变更触发 plan/apply。
|
||||
|
||||
**来源**: [[ctp-topic-3-deploy-and-maintain-infrastructure]], [[ctp-topic-25-labs-landing-zone-overview-itom-teams]]
|
||||
|
||||
## Ecosystem Position
|
||||
|
||||
```
|
||||
Terraform Ecosystem
|
||||
├── Terraform (HashiCorp) — 核心 IaC 引擎
|
||||
├── Terragrunt (Gruntwork) — DRY 封装层 ←
|
||||
├── Terraform Enterprise (HashiCorp) — 企业 CI 平台
|
||||
└── Gruntwork Library (Gruntwork) — 预建模块库
|
||||
```
|
||||
|
||||
## Related Entities
|
||||
|
||||
- [[Terraform]] — Terragrunt 包装的核心引擎
|
||||
- [[HashiCorp]] — Terraform 创立公司
|
||||
- [[Gruntwork]] — Terragrunt 开发公司
|
||||
|
||||
## Related Concepts
|
||||
|
||||
- [[Infrastructure-as-Code]] — Terragrunt 的应用领域
|
||||
- [[DRY Principle]] — Terragrunt 的设计哲学
|
||||
|
||||
## Related Sources
|
||||
|
||||
- [[ctp-topic-48-terraform-vs-terragrunt]]
|
||||
- [[ctp-topic-3-deploy-and-maintain-infrastructure]]
|
||||
- [[ctp-topic-15-working-with-renovatebot]](Renovate Bot 扫描 Terragrunt 配置)
|
||||
Reference in New Issue
Block a user