Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.
Creación de una AMI personalizada con Terraform
Al usarla AWS ParallelCluster, solo pagas por los AWS recursos que se crean al crear o actualizar AWS ParallelCluster imágenes y clústeres. Para obtener más información, consulte AWS servicios utilizados por AWS ParallelCluster.
Requisitos previos
-
Terraform v1.5.7+ está instalada.
-
AWS ParallelCluster APILa versión 3.8.0+ está implementada en su cuenta. Consulte Crear un clúster con Terraform.
-
Función de IAM con los permisos para invocar la API. ParallelCluster Consulte Permisos necesarios.
Defina un proyecto de Terraform
En este tutorial, definirá un proyecto sencillo de Terraform para implementar una AMI ParallelCluster personalizada.
Cree un directorio llamado
my-amis
.Todos los archivos que cree estarán dentro de este directorio.
Cree el archivo
terraform.tf
para importar el ParallelCluster proveedor.terraform { required_version = ">= 1.5.7" required_providers { aws-parallelcluster = { source = "aws-tf/aws-parallelcluster" version = "1.0.0" } } }
Cree el archivo
providers.tf
para configurar los AWS proveedores ParallelCluster y.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 }
Cree el archivo
main.tf
para definir los recursos mediante el ParallelCluster módulo.Para revisar las propiedades de la imagen que puede establecer en el
image_configuration
elemento, consulteCree archivos de configuración de imágenes.Para revisar las opciones que puede configurar para la creación de imágenes, por ejemplo
rollback_on_failure
,image_id
y consultepcluster 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 }
Cree el archivo
variables.tf
para definir las variables que se pueden insertar para este proyecto.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." }
Cree el archivo
terraform.tfvars
para establecer valores arbitrarios para las variables.Con el siguiente archivo, implementa la AMI personalizada
us-east-1
basada en la arquitectura Amazon Linux 2 para x86_64, utilizando la ParallelCluster API 3.10.0 existente que ya está implementada con el nombre de la pila.us-east-1
MyParallelClusterAPI-310
region = "us-east-1" api_stack_name = "MyParallelClusterAPI-310" api_version = "3.10.0" os = "alinux2" architecture = "x86_64"
Cree el archivo para definir los resultados
outputs.tf
devueltos por este proyecto.output "parent_image" { value = data.aws-parallelcluster_list_official_images.parent_image.official_images[0] } output "custom_image" { value = aws-parallelcluster_image.demo01 }
El directorio del proyecto es:
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.
Implemente la AMI
Para implementar la AMI, ejecute los comandos estándar de Terraform en orden.
Cree el proyecto:
terraform init
Defina el plan de despliegue:
terraform plan -out tfplan
Implemente el plan:
terraform apply tfplan
Permisos necesarios
Necesita los siguientes permisos para implementar una AMI personalizada con Terraform:
-
asuma la función de ParallelCluster API, que se encarga de interactuar con la ParallelCluster API
-
describa la AWS CloudFormation pila de la ParallelCluster API para verificar su existencia y recuperar sus parámetros y resultados
{ "Version": "2012-10-17", "Statement": [ { "Action": "sts:AssumeRole", "Resource": "arn:
PARTITION
:iam::ACCOUNT
:role/PCAPIUserRole-*", "Effect": "Allow", "Sid": "AssumePCAPIUserRole" }, { "Action": [ "cloudformation:DescribeStacks" ], "Resource": "arn:PARTITION
:cloudformation:REGION
:ACCOUNT
:stack/*", "Effect": "Allow", "Sid": "CloudFormation" } ] }