Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Definisci un progetto Terraform
In questo tutorial, definirai un semplice progetto Terraform per implementarne uno personalizzato. ParallelCluster AMI
Crea una directory chiamata.
my-amis
Tutti i file che creerai si troveranno all'interno di questa directory.
Crea il file
terraform.tf
per importare il ParallelCluster provider.terraform { required_version = ">= 1.5.7" required_providers { aws-parallelcluster = { source = "aws-tf/aws-parallelcluster" version = "~> 1.0" } } }
Crea il file
providers.tf
per configurare i AWS provider ParallelCluster e.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 }
Crea il file
main.tf
per definire le risorse utilizzando il ParallelCluster modulo.Per esaminare le proprietà dell'immagine che è possibile impostare all'interno dell'
image_configuration
elemento, vedereCrea file di configurazione delle immagini.Per esaminare le opzioni che è possibile impostare per la creazione di immagini, ad esempio
image_id
erollback_on_failure
, vederepcluster 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 }
Create il file
variables.tf
per definire le variabili che possono essere inserite per questo progetto.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." }
Crea il file
terraform.tfvars
per impostare i tuoi valori arbitrari per le variabili.Con il file seguente, distribuisci il custom AMI in
us-east-1
basato sull'architettura Amazon Linux 2 per x86_64, utilizzando la versione ParallelCluster API 3.11.1 esistente che è già distribuita con il nome dello stack.us-east-1
MyParallelClusterAPI-3111
region = "us-east-1" api_stack_name = "MyParallelClusterAPI-3111" api_version = "3.11.1" os = "alinux2" architecture = "x86_64"
Crea il file per definire gli output restituiti
outputs.tf
da questo progetto.output "parent_image" { value = data.aws-parallelcluster_list_official_images.parent_image.official_images[0] } output "custom_image" { value = aws-parallelcluster_image.demo01 }
La cartella del progetto è:
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.