Déploiement ParallelCluster d'une API avec Terraform - AWS ParallelCluster

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Déploiement ParallelCluster d'une API avec Terraform

Dans ce didacticiel, vous allez définir un projet Terraform simple pour déployer une ParallelCluster API.

Prérequis

  • Terraform v1.5.7+ est installé.

  • Rôle IAM autorisé à déployer l' ParallelCluster API. veuillez consulter Autorisations nécessaires.

Définir un projet Terraform

  1. Créez un répertoire appelémy-pcluster-api.

    Tous les fichiers que vous créez se trouveront dans ce répertoire.

  2. Créez le fichier provider.tf pour configurer le AWS fournisseur.

    provider "aws" { region = var.region profile = var.profile }
  3. Créez le fichier main.tf pour définir les ressources à l'aide du ParallelCluster module.

    module "parallelcluster_pcluster_api" { source = "aws-tf/parallelcluster/aws//modules/pcluster_api" version = "1.0.0" region = var.region api_stack_name = var.api_stack_name api_version = var.api_version deploy_pcluster_api = true parameters = { EnableIamAdminAccess = "true" } }
  4. Créez le fichier variables.tf pour définir les variables qui peuvent être injectées pour ce projet.

    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." }
  5. Créez le fichier terraform.tfvars pour définir des valeurs arbitraires pour les variables.

    Le fichier ci-dessous déploie une ParallelCluster API 3.10.0 en us-east-1 utilisant le nom de la pile. MyParallelClusterAPI-310 Vous pourrez référencer ce déploiement d' ParallelCluster API à l'aide de son nom de pile.

    region = "us-east-1" api_stack_name = "MyParallelClusterAPI-310" api_version = "3.10.0"
  6. Créez le fichier outputs.tf pour définir les sorties renvoyées par ce projet.

    output "pcluster_api_stack_outputs" { value = module.parallelcluster_pcluster_api.stack_outputs }

    Le répertoire du projet est le suivant :

    my-pcluster-api ├── main.tf - Terraform entrypoint to define the resources using the ParallelCluster module. ├── outputs.tf - Defines the outputs returned by Terraform. ├── providers.tf - Configures the AWS provider. ├── terraform.tfvars - Set the arbitrary values for the variables, i.e. region, PCAPI version, PCAPI stack name └── variables.tf - Defines the variables, e.g. region, PCAPI version, PCAPI stack name.

Déploiement de l’API

Pour déployer l'API, exécutez les commandes Terraform standard dans l'ordre.

  1. Construisez le projet :

    terraform init
  2. Définissez le plan de déploiement :

    terraform plan -out tfplan
  3. Déployez le plan :

    terraform apply tfplan

Autorisations nécessaires

Vous avez besoin des autorisations suivantes pour déployer l' ParallelCluster API avec Terraform :

{ "Version": "2012-10-17", "Statement": [ { "Action": [ "cloudformation:DescribeStacks", "cloudformation:GetTemplate" ], "Resource": "arn:PARTITION:cloudformation:REGION:ACCOUNT:stack/*", "Effect": "Allow", "Sid": "CloudFormationRead" }, { "Action": [ "cloudformation:CreateStack", "cloudformation:DeleteStack", "cloudformation:CreateChangeSet" ], "Resource": "arn:PARTITION:cloudformation:REGION:ACCOUNT:stack/MyParallelClusterAPI*", "Effect": "Allow", "Sid": "CloudFormationWrite" }, { "Action": [ "cloudformation:CreateChangeSet" ], "Resource": [ "arn:PARTITION:cloudformation:REGION:aws:transform/Include", "arn:PARTITION:cloudformation:REGION:aws:transform/Serverless-2016-10-31" ], "Effect": "Allow", "Sid": "CloudFormationTransformWrite" }, { "Action": [ "s3:GetObject" ], "Resource": [ "arn:PARTITION:s3:::*-aws-parallelcluster/parallelcluster/*/api/ParallelCluster.openapi.yaml", "arn:PARTITION:s3:::*-aws-parallelcluster/parallelcluster/*/layers/aws-parallelcluster/lambda-layer.zip" ], "Effect": "Allow", "Sid": "S3ParallelClusterArtifacts" }, { "Action": [ "iam:CreateRole", "iam:DeleteRole", "iam:GetRole", "iam:CreatePolicy", "iam:DeletePolicy", "iam:GetPolicy", "iam:GetRolePolicy", "iam:AttachRolePolicy", "iam:DetachRolePolicy", "iam:PutRolePolicy", "iam:DeleteRolePolicy", "iam:ListPolicyVersions" ], "Resource": [ "arn:PARTITION:iam::ACCOUNT:role/*", "arn:PARTITION:iam::ACCOUNT:policy/*" ], "Effect": "Allow", "Sid": "IAM" }, { "Action": [ "iam:PassRole" ], "Resource": [ "arn:PARTITION:iam::ACCOUNT:role/ParallelClusterLambdaRole-*", "arn:PARTITION:iam::ACCOUNT:role/APIGatewayExecutionRole-*" ], "Effect": "Allow", "Sid": "IAMPassRole" }, { "Action": [ "lambda:CreateFunction", "lambda:DeleteFunction", "lambda:GetFunction", "lambda:PublishLayerVersion", "lambda:DeleteLayerVersion", "lambda:GetLayerVersion", "lambda:TagResource", "lambda:UntagResource" ], "Resource": [ "arn:PARTITION:lambda:REGION:ACCOUNT:layer:PCLayer-*", "arn:PARTITION:lambda:REGION:ACCOUNT:function:*-ParallelClusterFunction-*" ], "Effect": "Allow", "Sid": "Lambda" }, { "Action": [ "logs:CreateLogGroup", "logs:DeleteLogGroup", "logs:DescribeLogGroups", "logs:PutRetentionPolicy", "logs:TagLogGroup", "logs:UntagLogGroup" ], "Resource": [ "arn:PARTITION:logs:REGION:ACCOUNT:log-group:/aws/lambda/*-ParallelClusterFunction-*" ], "Effect": "Allow", "Sid": "Logs" }, { "Action": [ "apigateway:DELETE", "apigateway:GET", "apigateway:PATCH", "apigateway:POST", "apigateway:PUT", "apigateway:UpdateRestApiPolicy" ], "Resource": [ "arn:PARTITION:apigateway:REGION::/restapis", "arn:PARTITION:apigateway:REGION::/restapis/*", "arn:PARTITION:apigateway:REGION::/tags/*" ], "Effect": "Allow", "Sid": "APIGateway" } ] }