# 使用 Terraform 的大型基础设施

来源: <https://github.com/antonbabenko/terraform-best-practices/tree/master/examples/large-terraform>

此示例包含的代码作为为大型基础设施构建 Terraform 配置的示例，该基础设施使用：

* 2个AWS账户
* 2个地区
* 2 个独立的环境（`prod` 和 `stage` 什么都不共享）。 每个环境都位于一个单独的 AWS 账户中，并跨越 2 个区域之间的资源
* 每个环境都使用来自 [Terraform Registry](https://registry.terraform.io/) 的不同版本的现成基础设施模块 (`alb`)
* 每个环境都使用相同版本的内部模块`modules/network`，因为它来自本地目录

{% hint style="info" %}
在此处描述的大型项目中，使用 Terragrunt 的好处变得非常明显。请参阅[Code Structures examples with Terragrunt](/zh/examples/terragrunt.md)。
{% endhint %}

{% hint style="success" %}

* 非常适合基础设施在逻辑上分离的项目（单独的 AWS 账户）
* 适合不需要修改 AWS 账户之间共享的资源（一个环境 = 一个 AWS 账户 = 一个状态文件）
* 适合不需要编排环境之间的变化
* 适合基础设施资源因环境而异且无法一概而论时（例如，在一个环境或某些地区缺少某些资源）
  {% endhint %}

{% hint style="warning" %}
随着项目的增长，让这些环境彼此保持最新状态将变得更加困难。 考虑使用基础设施模块（现成的或内部的）来完成可重复的任务。
{% endhint %}

##


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.terraform-best-practices.com/zh/examples/terraform/large-size-infrastructure-with-terraform.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
