기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
Terraform 프로젝트 정의
이 자습서에서는 ParallelCluster 사용자 지정 AMI를 배포하기 위한 간단한 Terraform 프로젝트를 정의합니다.
이름이
my-amis인 디렉터리를 생성합니다.생성하는 모든 파일은 이 디렉터리 내에 있습니다.
terraform.tf파일을 생성하여 ParallelCluster 공급자를 가져옵니다.terraform { required_version = ">= 1.5.7" required_providers { aws-parallelcluster = { source = "aws-tf/aws-parallelcluster" version = "~> 1.0" } } }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 }main.tf파일을 생성하여 ParallelCluster 모듈을 사용하여 리소스를 정의합니다.image_configuration요소 내에서 설정할 수 있는 이미지 속성을 검토하려면 빌드 이미지 구성 파일 섹션을 참조하세요.이미지 생성을 위해 설정할 수 있는 옵션, 예를 들어
image_id및rollback_on_failure를 검토하려면 pcluster build-image 섹션을 참조하세요.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 }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." }파일을 생성
terraform.tfvars하여 변수에 대한 임의 값을 설정합니다.아래 파일을 사용하면 스택 이름이 인에 이미 배포된 기존 ParallelCluster API 3.11.1을 사용하여 x86_64 아키텍처용 Amazon Linux 2를
us-east-1기반으로 사용자 지정 AMIus-east-1를에 배포합니다MyParallelClusterAPI-3111.region = "us-east-1" api_stack_name = "MyParallelClusterAPI-3111" api_version = "3.11.1" os = "alinux2" architecture = "x86_64"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.