

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Terraform 프로젝트 정의
<a name="tutorial-create-ami-terraform-define"></a>

이 자습서에서는 ParallelCluster 사용자 지정 AMI를 배포하기 위한 간단한 Terraform 프로젝트를 정의합니다.

1. 이름이 `my-amis`인 디렉터리를 생성합니다.

   생성하는 모든 파일은 이 디렉터리 내에 있습니다.

1. `terraform.tf` 파일을 생성하여 ParallelCluster 공급자를 가져옵니다.

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

1. `providers.tf` 파일을 생성하여 ParallelCluster 및 AWS 공급자를 구성합니다.

   ```
   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. `main.tf` 파일을 생성하여 ParallelCluster 모듈을 사용하여 리소스를 정의합니다.

   `image_configuration` 요소 내에서 설정할 수 있는 이미지 속성을 검토하려면 [빌드 이미지 구성 파일](image-builder-configuration-file-v3.md) 섹션을 참조하세요.

   이미지 생성을 위해 설정할 수 있는 옵션, 예를 들어 `image_id` 및 `rollback_on_failure`를 검토하려면 [`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. `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."
   }
   
   variable "os" {
     type        = string
     description = "The OS of the ParallelCluster image."
   }
   
   variable "architecture" {
     type        = string
     description = "The architecture of the ParallelCluster image."
   }
   ```

1. 파일을 생성`terraform.tfvars`하여 변수에 대한 임의 값을 설정합니다.

   아래 파일을 사용하면 스택 이름이 인에 이미 배포된 기존 ParallelCluster API 3.11.1을 사용하여 x86\$164 아키텍처용 Amazon Linux 2를 `us-east-1` 기반으로 사용자 지정 AMI`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. `outputs.tf` 파일을 생성하여 이 프로젝트에서 반환되는 출력을 정의합니다.

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

   프로젝트 디렉터리:

   ```
   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.
   ```