

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

# 定義 Terraform 專案
<a name="tutorial-deploy-terraform-define"></a>

在本教學課程中，您將定義 Terraform 專案。

1. 建立名為 的目錄`my-pcluster-api`。

   您建立的所有檔案都將在此目錄中。

1. 建立 檔案`provider.tf`以設定 AWS 提供者。

   ```
   provider "aws" {
     region  = var.region
     profile = var.profile
   }
   ```

1. 建立 檔案`main.tf`以使用 ParallelCluster 模組定義資源。

   ```
   module "parallelcluster_pcluster_api" {
     source = "aws-tf/parallelcluster/aws//modules/pcluster_api"
     version = "1.1.0"
   
     region                = var.region
     api_stack_name        = var.api_stack_name
     api_version           = var.api_version
   
     parameters = {
       EnableIamAdminAccess = "true"
     }
   }
   ```

1. 建立 檔案`variables.tf`以定義可為此專案注入的變數。

   ```
   variable "region" {
     description = "The region the ParallelCluster API is deployed in."
     type        = string
     default     = "us-east-1"
   }
   
   variable "profile" {
     type        = string
     description = "The AWS profile used to deploy the clusters."
     default     = null
   }
   
   variable "api_stack_name" {
     type        = string
     description = "The name of the CloudFormation stack used to deploy the ParallelCluster API."
     default     = "ParallelCluster"
   }
   
   variable "api_version" {
     type        = string
     description = "The version of the ParallelCluster API."
   }
   ```

1. 建立 檔案`terraform.tfvars`以設定變數的任意值。

   以下 檔案`us-east-1`會使用堆疊名稱 在 中部署 ParallelCluster API 3.11.1`MyParallelClusterAPI-3111`。您將可以使用其堆疊名稱來參考此 ParallelCluster API 部署。
**注意**  
下列程式碼中的`api_version`指派可以取代為任何支援的 AWS ParallelCluster 版本。

   ```
   region = "us-east-1"
   api_stack_name = "MyParallelClusterAPI-3111"
   api_version = "3.11.1"
   ```

1. 建立 檔案`outputs.tf`以定義此專案傳回的輸出。

   ```
   output "pcluster_api_stack_outputs" {
     value = module.parallelcluster_pcluster_api.stack_outputs
   }
   ```

   專案目錄為：

   ```
   my-pcluster-api
   ├── main.tf - Terraform entrypoint to define the resources using the ParallelCluster module.
   ├── outputs.tf - Defines the outputs returned by Terraform.
   ├── providers.tf - Configures the AWS provider.
   ├── terraform.tfvars - Set the arbitrary values for the variables, i.e. region, PCAPI version, PCAPI stack name
   └── variables.tf - Defines the variables, e.g. region, PCAPI version, PCAPI stack name.
   ```