

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

*Zahoor Chaudhrey 和 Luca Iannario，Amazon Web Services*

## 總結
<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) 應用程式最佳化的基礎設施。*Wavelength 區域*是 AWS 基礎設施部署，可將 AWS 運算和儲存服務嵌入通訊服務供應商 (CSP) 5G 網路。來自 5G 裝置的應用程式流量會到達在 Wavelength 區域中執行的應用程式伺服器，而不會離開電信網路。以下內容有助於透過 Wavelength 進行網路連線：
+ **虛擬私有雲端 (VPCs)** – 中的 VPCs AWS 帳戶 可以延伸到多個可用區域，包括 Wavelength 區域。Amazon Elastic Compute Cloud (Amazon EC2) 執行個體和相關服務會顯示為區域 VPC 的一部分。VPCs是在 [Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) 中建立和管理。
+ **電信業者閘道** – 電信業者閘道可透過 CSP 的網路，從 Wavelength 區域中的子網路連線至 CSP 網路、網際網路或 AWS 區域 。電信業者閘道有兩個用途。它允許來自特定位置 CSP 網路的傳入流量，並允許傳出流量到電信網路和網際網路。

此模式及其相關聯的 Terraform 程式碼可協助您在 Wavelength 區域中啟動資源，例如 Amazon EC2 執行個體、Amazon Elastic Block Store (Amazon EBS) 磁碟區、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 區域
+ 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 AWS Provider 5.32.1 版或更新版本，[已設定](https://hashicorp.github.io/terraform-provider-aws/) (Terraform 文件）
+ Git，[已安裝](https://github.com/git-guides/install-git) (GitHub)
+ 建立 Amazon VPC、Wavelength 和 Amazon EC2 資源[的許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html) 

**限制**

並非所有 都 AWS 區域 支援 Wavelength 區域。如需詳細資訊，請參閱 [Wavelength 文件中的可用 Wavelength 區域](https://docs.aws.amazon.com/wavelength/latest/developerguide/available-wavelength-zones.html)。

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

下圖顯示如何在 Wavelength 區域中建立子網路 AWS 和資源。在 Wavelength 區域中包含子網路的 VPCs 可以連接到電信業者閘道。電信業者閘道可讓您連線至下列資源：
+ 電信業者網路上的 4G/LTE 和 5G 裝置。
+ 已修正特定 Wavelength Zone 合作夥伴的無線存取。如需詳細資訊，請參閱[多重存取 AWS Wavelength](https://docs.aws.amazon.com/wavelength/latest/developerguide/multi-access.html)。
+ 將流量傳出至公有網際網路資源。

![\[電信業者閘道會將 Wavelength 區域中的 AWS 資源連線至 CSP 網路。\]](http://docs.aws.amazon.com/zh_tw/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 (Amazon 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/) 是 HashiCorp 的基礎設施即程式碼 (IaC) 工具，可協助您建立和管理雲端和內部部署資源。

**程式碼儲存庫**

此模式的程式碼可在 GitHub [使用 Terraform 建立 AWS Wavelength 基礎設施](https://github.com/aws-samples/terraform-wavelength-infrastructure)儲存庫中取得。Terraform 程式碼會部署下列基礎設施和資源：
+ VPC
+ Wavelength 區域
+ Wavelength 區域中的 pubic 子網路
+ Wavelength 區域中的電信業者閘道
+ Wavelength 區域中的 Amazon EC2 執行個體

## 最佳實務
<a name="deploy-resources-wavelength-zone-using-terraform-best-practices"></a>
+ 部署之前，請確認您使用的是最新版本的 Terraform 和 AWS CLI。
+ 使用持續整合和持續交付 (CI/CD) 管道來部署 IaC。如需詳細資訊，請參閱 AWS 部落格上 [AWS CI/CD 管道中管理 Terraform 狀態檔案的最佳實務](https://aws.amazon.com/blogs/devops/best-practices-for-managing-terraform-state-files-in-aws-ci-cd-pipeline/)。

## 史詩
<a name="deploy-resources-wavelength-zone-using-terraform-epics"></a>

### 佈建 基礎設施
<a name="provision-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製儲存庫。 | 輸入下列命令，將[使用 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_tw/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_tw/prescriptive-guidance/latest/patterns/deploy-resources-wavelength-zone-using-terraform.html) | DevOps 工程師，Terraform | 

### 驗證和清除
<a name="validate-and-clean-up"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證基礎設施部署。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/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_tw/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 區域中的 Amazon EC2 執行個體。 | 請參閱[疑難排解在 Wavelength 區域中啟動之 EC2 執行個體的 SSH 或 RDP 連線](https://repost.aws/knowledge-center/ec2-wavelength-zone-connection-errors)。 | 
| Wavelength 區域中的容量。 | 請參閱 [Wavelength 區域的配額和考量](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_tw/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)