

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Tentukan proyek Terraform
<a name="tutorial-create-ami-terraform-define"></a>

Dalam tutorial ini, Anda akan menentukan proyek Terraform sederhana untuk menerapkan AMI khusus ParallelCluster .

1. Buat direktori yang disebut`my-amis`. 

   Semua file yang Anda buat akan berada di dalam direktori ini.

1. Buat file `terraform.tf` untuk mengimpor ParallelCluster penyedia.

   ```
   terraform {
     required_version = ">= 1.5.7"
     required_providers {
       aws-parallelcluster = {
         source  = "aws-tf/aws-parallelcluster"
         version = "~> 1.0"
       }
     }
   }
   ```

1. Buat file `providers.tf` untuk mengkonfigurasi ParallelCluster dan AWS penyedia.

   ```
   provider "aws" {
     region  = var.region
     profile = var.profile
   }
   
   provider "aws-parallelcluster" {
     region         = var.region
     profile        = var.profile
     api_stack_name = var.api_stack_name
     use_user_role  = true
   }
   ```

1. Buat file `main.tf` untuk menentukan sumber daya menggunakan ParallelCluster modul.

   Untuk meninjau properti gambar yang dapat Anda atur dalam `image_configuration` elemen, lihat[Membangun file konfigurasi gambar](image-builder-configuration-file-v3.md).

   Untuk meninjau opsi yang dapat Anda atur untuk pembuatan gambar, misalnya `image_id` dan`rollback_on_failure`, lihat[`pcluster build-image`](pcluster.build-image-v3.md). 

   ```
   data "aws-parallelcluster_list_official_images" "parent_image" {
     region = var.region
     os = var.os
     architecture = var.architecture
   }
   
   resource "aws-parallelcluster_image" "demo01" {
     image_id            = "demo01"
     image_configuration = yamlencode({
       "Build":{
         "InstanceType": "c5.2xlarge",
         "ParentImage": data.aws-parallelcluster_list_official_images.parent_image.official_images[0].amiId,
         "UpdateOsPackages": {"Enabled": false}
       }
     })
     rollback_on_failure = false
   }
   ```

1. Buat file `variables.tf` untuk menentukan variabel yang dapat disuntikkan untuk proyek ini.

   ```
   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."
   }
   
   variable "os" {
     type        = string
     description = "The OS of the ParallelCluster image."
   }
   
   variable "architecture" {
     type        = string
     description = "The architecture of the ParallelCluster image."
   }
   ```

1. Buat file `terraform.tfvars` untuk mengatur nilai arbitrer Anda untuk variabel. 

   Dengan file di bawah ini, gunakan AMI kustom `us-east-1` berdasarkan Amazon Linux 2 untuk arsitektur x86\$164, menggunakan ParallelCluster API 3.11.1 yang ada yang sudah diterapkan dengan nama tumpukan. `us-east-1` `MyParallelClusterAPI-3111`

   ```
   region = "us-east-1"
   api_stack_name = "MyParallelClusterAPI-3111"
   api_version = "3.11.1"
   
   os = "alinux2"
   architecture = "x86_64"
   ```

1. Buat file `outputs.tf` untuk menentukan output yang dikembalikan oleh proyek ini.

   ```
   output "parent_image" {
     value = data.aws-parallelcluster_list_official_images.parent_image.official_images[0]
   }
   
   output "custom_image" {
     value = aws-parallelcluster_image.demo01
   }
   ```

   Direktori proyek adalah:

   ```
   my-amis
   ├── main.tf - Terraform entrypoint where the ParallelCluster module is configured.
   ├── outputs.tf - Defines the cluster as a Terraform output.
   ├── providers.tf - Configures the providers: ParallelCluster and AWS.
   ├── terraform.tf - Import the ParallelCluster provider.
   ├── terraform.tfvars - Defines values for variables, e.g. region, PCAPI stack name.
   └── variables.tf - Defines the variables, e.g. region, PCAPI stack name.
   ```