Files
nexus/wiki/sources/ctp-topic-16-cross-account-terraform-modules.md
2026-04-20 07:08:14 +08:00

47 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "CTP Topic 16 Cross-account Terraform modules"
type: source
tags: [terraform, cross-account, modules, ctp, devops]
source: []
last_updated: 2026-04-20
---
## Source File
- [[raw/Cloud & DevOps/Public-Cloud-Learning-Sessions/03_Terraform/ctp-topic-16-cross-account-terraform-modules.md]]
## Summary
- 核心主题:在多账号 AWS 环境中实现和管理跨账号 Terraform 模块
- 问题域:如何在不授予直接互访权限的情况下,在一个模块中跨多个账号创建资源
- 方法/机制:基于 Shared Account 的中心化部署方案,通过 cross-account.json 标记文件触发 ECS Deploy RunnerAssume Role 访问目标账号
- 结论/价值:实现安全性(集中权限控制)、自动化(自动识别模块类型)、可复用性(代码不硬编码账号角色)
## Key Claims
- Cross-account Modules 通过配置多个 Provider 实现在多个 AWS 账号中同时创建或管理资源
- Shared Account 作为信任源,通过 Assume Role 方式访问目标账号,避免直接授予互访权限
- cross-account.json 标记文件告知 Jenkins 该模块需要调用跨账号部署逻辑
## Key Quotes
> "在多账号 AWS 环境中,经常需要在一个模块内跨多个账号创建资源,但直接赋予账号间互访权限存在巨大的安全风险" — Fibos
> "利用托管 Jenkins 的 Shared Account 作为中转站,实现中心化的跨账号部署" — Fibos
## Key Concepts
- [[Cross-account Modules]]:在一个 Terraform 模块中通过配置多个 Provider实现在多个 AWS 账号中同时创建或管理资源的功能
- [[Shared Account]]:整个 Landing Zone 中的核心管理账号,托管 Jenkins、镜像仓库等公共服务并作为跨账号部署的信任源
- [[ECS Deploy Runner]]:运行在 ECS 上的 Docker 容器,负责执行 Terraform plan 和 apply 命令
- [[Cross-account.json]]:约定俗成的标记文件,放置在模块目录中,用于告知 Jenkins 该模块需要调用跨账号部署逻辑
## Key Entities
- [[Fibos]]:本次会议讲师
- [[Gruntwork Pipeline]]:原有的单账号部署流水线
## Connections
- [[Gruntwork Pipeline Deep Dive]] ← depends_on ← [[CTP Topic 16 Cross-account Terraform modules]]
- [[AWS Multi-account Security Best Practices]] ← informs ← [[CTP Topic 16 Cross-account Terraform modules]]
- [[Terragrunt Advanced Configuration]] ← used_by ← [[CTP Topic 16 Cross-account Terraform modules]]
## Contradictions
- 与直接授予 Workload 账号间互访权限的方案冲突:
- 冲突点:直接授予互访权限存在 Blast Radius 安全风险
- 当前观点:通过 Shared Account 集中控制权限Assume Role 访问
- 对方观点:直接授予账号间互访权限简化配置