Files
nexus/wiki/sources/ctp-topic-48-terraform-vs-terragrunt.md

56 lines
3.0 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 48 Terraform vs Terragrunt"
type: source
tags:
- Terraform
- Terragrunt
- IaC
- DevOps
- CTP
date: 2026-04-14
---
## Source File
- [[Cloud & DevOps/Public-Cloud-Learning-Sessions/03_Terraform/ctp-topic-48-terraform-vs-terragrunt.md]]
## Summary用中文描述
- 核心主题Terraform 与 Terragrunt 的对比选型,涵盖企业级 IaC 实践
- 问题域:多环境配置管理、基础设施代码复用、状态文件管理
- 方法/机制Terraform 作为核心 IaC 工具云厂商无关Terragrunt 作为 Terraform 的 DRY 封装层,处理跨环境变量和远程状态的重复声明
- 结论/价值Terraform 与 Terragrunt 命令和语法高度一致,但 Terragrunt 通过减少硬编码、提升可复用性来优化大规模企业部署;两者可互补使用
## Key Claims用中文描述
- TerraformHashiCorp 出品)通过状态文件将期望状态与现有环境绑定,企业级使用须将状态文件存储在安全可访问的位置
- Terragrunt 是 Terraform 的轻量封装,贯彻 DRY 原则,通过管理 provider 和 remote_state 块减少跨环境的重复声明
- Terraform Enterprise 提供带 workspace 的 CI 平台Gruntwork 提供预建可定制模块Atlantis 实现 Git 驱动的自动化部署
- tfsec 用于静态代码安全分析Terratest 用于基础设施测试自动化
## Key Quotes
> "Terraform ties the desired state to the existing environment using a state file. For enterprise-scale use, storing this file in a safe, accessible location is crucial." — Bob, AWS Solutions Architect
> "Terragrunt offers a way to use information in a repeatable way without hard coding values." — Bob
> "All Terraform commands work with Terragrunt; a Terraform plan becomes a Terragrunt plan." — Bob
## Key Concepts
- [[Infrastructure As Code]]:通过代码定义和版本控制基础设施资源的实践
- [[DRY Principle]]Don't Repeat Yourself — 避免重复配置,通过抽象层复用
- [[State File Management]]Terraform 用状态文件绑定期望状态与实际环境
- [[IaC Testing]]:用 Terratest 等工具对基础设施代码进行自动化测试
## Key Entities
- [[HashiCorp]]Terraform 创立公司,提供多云基础设施编排工具
- [[Gruntwork]]:提供预建可定制的 Terraform 模块和 Terraform 原生 AWS Landing Zone
- [[Atlantis]]:将 Terraform 与 GitHub 集成的开源 CI/CD 工具
- [[Terraform]]:云厂商无关的基础设施即代码工具
- [[Terragrunt]]Terraform 的 DRY 封装层,管理多环境配置
## Connections
- [[Terraform]] ← uses ← [[State File Management]]
- [[Terragrunt]] ← wraps ← [[Terraform]]
- [[Terraform]] ← provided_by ← [[HashiCorp]]
- [[Gruntwork]] ← provides_modules_for ← [[Terraform]]
- [[Atlantis]] ← integrates_with ← [[Terraform]]
- [[Terraform]] ← related_concept ← [[Infrastructure As Code]]
## Contradictions
- 暂无发现与其他 Wiki 页面的直接冲突