

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 Terraform 在 AWS Wavelength 区域中部署资源
<a name="deploy-resources-wavelength-zone-using-terraform"></a>

*Zahoor Chaudhrey 和 Luca Iannario，Amazon Web Services*

## Summary
<a name="deploy-resources-wavelength-zone-using-terraform-summary"></a>

[AWS Wavelength](https://docs.aws.amazon.com/wavelength/latest/developerguide/what-is-wavelength.html) 可帮助您构建专为多接入边缘计算（MEC）应用程序优化的基础设施。W@@ *avelength Zones* 是在通信服务提供商 (CSP) 的 5G 网络中嵌入 AWS 计算和存储服务的 AWS 基础设施部署。来自 5G 设备的应用程序流量无需离开电信网络即可到达在 Wavelength Zones 中运行的应用程序服务器。以下内容有助于通过 Wavelength 实现网络连接：
+ **虚拟私有云 (VPCs)** — VPCs AWS 账户 可以扩展到跨多个可用区，包括 Wavelength 区域。亚马逊弹性计算云 (Amazon EC2) 实例和相关服务作为您的区域 VPC 的一部分出现。 VPCs 在[亚马逊 Virtual Private Cloud（亚马逊 VPC）](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html)中创建和管理。
+ **运营商网关** — 运营商网关支持从 Wavelength 区域的子网连接到 CSP 网络、互联网或 AWS 区域 通过 CSP 的网络。运营商网关有两个作用。它允许来自特定位置的 CSP 网络的入站流量，并允许将出站流量发送到电信网络和互联网。

此模式及其关联的 Terraform 代码可帮助您在波长区域中启动资源，例如亚马逊 EC2 实例、亚马逊弹性区块存储 (Amazon EBS) Block Store 卷 VPCs、子网和运营商网关。

## 先决条件和限制
<a name="deploy-resources-wavelength-zone-using-terraform-prereqs"></a>

**先决条件**
+ 活跃的 AWS 账户
+ 一个集成式开发环境（IDE）
+ [选择加入](https://docs.aws.amazon.com/wavelength/latest/developerguide/get-started-wavelength.html#enable-zone-group)目标 Wavelength Zone
+ AWS Command Line Interface (AWS CLI)，[已安装](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)并[配置](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
+ Terraform 版本 1.8.4 或更高版本，[已安装](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli)（Terraform 文档）
+ Terraform P AWS rovider 版本 5.32.1 或更高版本，[已配置](https://hashicorp.github.io/terraform-provider-aws/)（Terraform 文档）
+ Git，[已安装](https://github.com/git-guides/install-git) (GitHub)
+ 创建亚马逊 VPC、Wavelength 和亚马逊资源的@@ [权限](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html) EC2 

**限制**

并非所有区域都 AWS 区域 支持 Wavelength Zones。有关更多信息，请参阅 Wavelength 文档中的[可用 Wavelength Zones](https://docs.aws.amazon.com/wavelength/latest/developerguide/available-wavelength-zones.html)。

## 架构
<a name="deploy-resources-wavelength-zone-using-terraform-architecture"></a>

下图显示了如何在 Wavelength 区域中创建子网和 AWS 资源。 VPCs 在 Wavelength 区域中包含子网的可以连接到运营商网关。运营商网关允许您连接到以下资源：
+ 电信运营商网络上的 4G/LTE 和 5G 设备。
+ 针对精选 Wavelength Zone 合作伙伴的固定无线接入。有关更多信息，请参阅[多路访问 AWS Wavelength](https://docs.aws.amazon.com/wavelength/latest/developerguide/multi-access.html)。
+ 公有互联网资源的出站流量。

![\[运营商网关将 Wavelength Zone 中的 AWS 资源连接到 CSP 网络。\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/8c507de1-208c-4563-bb58-52388ab2fa6d/images/a4cc0699-0cbc-4f15-ab14-3ae569ced7f4.png)


## 工具
<a name="deploy-resources-wavelength-zone-using-terraform-tools"></a>

**AWS 服务**
+ [Amazon Virtual Private Cloud（亚马逊 VPC）](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html)可帮助您将 AWS 资源启动到您定义的虚拟网络中。该虚拟网络类似于您在数据中心中运行的传统网络，并具有使用 AWS的可扩展基础设施的优势。
+ [AWS Wavelength](https://docs.aws.amazon.com/wavelength/latest/developerguide/what-is-wavelength.html)将 AWS 云 基础设施扩展到电信提供商的 5G 网络。这可以帮助您为移动设备和最终用户构建具有超低延迟的应用程序。

**其他工具**
+ [Terraform](https://www.terraform.io/) 是一款基础设施即代码 (IaC) 工具 HashiCorp ，可帮助您创建和管理云和本地资源。

**代码存储库**

此模式的代码可在[使用 Terraform GitHub 创建 AWS Wavelength 基础架构存储库](https://github.com/aws-samples/terraform-wavelength-infrastructure)中找到。Terraform 代码部署了以下基础设施和资源：
+ 一个 VPC
+ Wavelength Zone
+ Wavelength Zone 中的公有子网
+ Wavelength Zone 中的运营商网关
+ Wavelength 区域中的亚马逊 EC2 实例

## 最佳实践
<a name="deploy-resources-wavelength-zone-using-terraform-best-practices"></a>
+ 部署前，请确认您使用的是最新版本的 Terraform 和 AWS CLI。
+ 使用持续集成和持续交付（CI/CD）管道部署 IaC。有关更多信息，请参阅博客上的 C [AWS I/CD Pipeline 中管理 Terraform 状态文件的最佳实践](https://aws.amazon.com/blogs/devops/best-practices-for-managing-terraform-state-files-in-aws-ci-cd-pipeline/)。 AWS 

## 操作说明
<a name="deploy-resources-wavelength-zone-using-terraform-epics"></a>

### 预调配基础设施
<a name="provision-the-infrastructure"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 克隆存储库。 | 输入以下命令，将 “[使用 Terraform 创建 AWS Wavelength 基础架构](https://github.com/aws-samples/terraform-wavelength-infrastructure)” 存储库克隆到您的环境中。`git clone git@github.com:aws-samples/terraform-wavelength-infrastructure.git` | DevOps 工程师 | 
| 更新变量。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-resources-wavelength-zone-using-terraform.html) | DevOps 工程师，Terraform | 
| 初始化配置。 | 输入以下命令，以初始化工作目录。<pre>terraform init</pre> | DevOps 工程师，Terraform | 
| 预览 Terraform 计划。 | 输入以下命令，将目标状态与 AWS 环境的当前状态进行比较。此命令会生成将要配置的资源的预览。<pre>terraform plan</pre> | DevOps 工程师，Terraform | 
| 验证并部署。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-resources-wavelength-zone-using-terraform.html) | DevOps 工程师，Terraform | 

### 验证并清理
<a name="validate-and-clean-up"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 验证基础设施部署。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-resources-wavelength-zone-using-terraform.html) | AWS DevOps， DevOps 工程师 | 
| （可选）清理 基础架构。 | 如果您需要删除 Terraform 预调配的所有资源，请执行以下操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-resources-wavelength-zone-using-terraform.html) | DevOps 工程师，Terraform | 

## 问题排查
<a name="deploy-resources-wavelength-zone-using-terraform-troubleshooting"></a>


| 问题 | 解决方案 | 
| --- | --- | 
| 与中的 Amazon EC2 实例的连接 AWS 区域。 | 请参阅[排查 Linux 实例的连接问题](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html)或[排查 Windows 实例的连接问题](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/troubleshooting-windows-instances.html)。 | 
| 连接 Wavelength 区域中的亚马逊 EC2 实例。 | 参见[排除我在 Wavelength 区域启动的 EC2 实例的 SSH 或 RDP 连接](https://repost.aws/knowledge-center/ec2-wavelength-zone-connection-errors)问题。 | 
| Wavelength Zone 中的容量。 | 请参阅 [Wavelength Zone 的配额和注意事项](https://docs.aws.amazon.com/wavelength/latest/developerguide/wavelength-quotas.html)。 | 
| 从运营商网络到 AWS 区域的移动或运营商连接。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/deploy-resources-wavelength-zone-using-terraform.html) | 

## 相关资源
<a name="deploy-resources-wavelength-zone-using-terraform-resources"></a>
+ [什么是 AWS Wavelength？](https://docs.aws.amazon.com/wavelength/latest/developerguide/what-is-wavelength.html)
+ [如何 AWS Wavelength 运作](https://docs.aws.amazon.com/wavelength/latest/developerguide/how-wavelengths-work.html)
+ [韧性在 AWS Wavelength](https://docs.aws.amazon.com/wavelength/latest/developerguide/disaster-recovery-resiliency.html)