

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Terraform を使用して ParallelCluster API をデプロイする
<a name="tutorial-deploy-terraform"></a>

このチュートリアルでは、ParallelCluster API をデプロイするためのシンプルな Terraform プロジェクトを定義します。

**前提条件**
+ Terraform v1.5.7\$1 をインストール済みである。
+ ParallelCluster API をデプロイするアクセス許可を持つ IAM ロール。「[必要なアクセス許可](tutorial-deploy-terraform-permissions.md)」を参照してください。

# Terraform プロジェクトを定義する
<a name="tutorial-deploy-terraform-define"></a>

このチュートリアルでは、Terraform プロジェクトを定義します。

1. `my-pcluster-api` という名前のディレクトリを作成します。

   作成するすべてのファイルは、このディレクトリに入ります。

1. ファイルを作成して`provider.tf`、 AWS プロバイダーを設定します。

   ```
   provider "aws" {
     region  = var.region
     profile = var.profile
   }
   ```

1. ParallelCluster モジュールを使用してリソースを定義するファイル `main.tf` を作成します。

   ```
   module "parallelcluster_pcluster_api" {
     source = "aws-tf/parallelcluster/aws//modules/pcluster_api"
     version = "1.1.0"
   
     region                = var.region
     api_stack_name        = var.api_stack_name
     api_version           = var.api_version
   
     parameters = {
       EnableIamAdminAccess = "true"
     }
   }
   ```

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

1. 変数の任意の値を設定するファイル `terraform.tfvars` を作成します。

   以下のファイルは、スタック名 `us-east-1`を使用して ParallelCluster API 3.11.1 を にデプロイします`MyParallelClusterAPI-3111`。この ParallelCluster API デプロイは、スタック名を使用して参照できます。
**注記**  
次のコード`api_version`の割り当ては、サポートされている任意の AWS ParallelCluster バージョンに置き換えることができます。

   ```
   region = "us-east-1"
   api_stack_name = "MyParallelClusterAPI-3111"
   api_version = "3.11.1"
   ```

1. このプロジェクトで返す出力を定義するファイル `outputs.tf` を作成します。

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

   プロジェクトディレクトリ:

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

# API をデプロイする
<a name="tutorial-deploy-terraform-deploy-api"></a>

API をデプロイするには、標準の Terraform コマンドを順に実行します。

1. プロジェクトをビルドします。

   ```
   terraform init
   ```

1. デプロイプランを定義します。

   ```
   terraform plan -out tfplan
   ```

1. プランをデプロイします。

   ```
   terraform apply tfplan
   ```

# 必要なアクセス許可
<a name="tutorial-deploy-terraform-permissions"></a>

Terraform を使用して ParallelCluster API をデプロイするには、以下のアクセス許可が必要です。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Action": [
                "cloudformation:DescribeStacks",
                "cloudformation:GetTemplate"
            ],
            "Resource": "arn:aws:cloudformation:us-east-1:111122223333:stack/*",
            "Effect": "Allow",
            "Sid": "CloudFormationRead"
        },
        {
            "Action": [
                "cloudformation:CreateStack",
                "cloudformation:DeleteStack",
                "cloudformation:CreateChangeSet"
            ],
            "Resource": "arn:aws:cloudformation:us-east-1:111122223333:stack/MyParallelClusterAPI*",
            "Effect": "Allow",
            "Sid": "CloudFormationWrite"
        },
        {
            "Action": [
                "cloudformation:CreateChangeSet"
            ],
            "Resource": [
                "arn:aws:cloudformation:us-east-1:111122223333:aws:transform/Include",
                "arn:aws:cloudformation:us-east-1:111122223333:aws:transform/Serverless-2016-10-31"
            ],
            "Effect": "Allow",
            "Sid": "CloudFormationTransformWrite"
        },
        {
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:us-east-1:111122223333:*-aws-parallelcluster/parallelcluster/*/api/ParallelCluster.openapi.yaml",
                "arn:aws:s3:us-east-1:111122223333:*-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:aws:iam::111122223333:role/*",
                "arn:aws:iam::111122223333:policy/*"
            ],
            "Effect": "Allow",
            "Sid": "IAM"
        },
        {
            "Action": [
                "iam:PassRole"
            ],
            "Resource": [
                "arn:aws:iam::111122223333:role/ParallelClusterLambdaRole-*",
                "arn:aws:iam::111122223333: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:aws:lambda:us-east-1:111122223333:layer:PCLayer-*",
                "arn:aws:lambda:us-east-1:111122223333:function:*-ParallelClusterFunction-*"
            ],
            "Effect": "Allow",
            "Sid": "Lambda"
        },
        {
            "Action": [
                "logs:CreateLogGroup",
                "logs:DeleteLogGroup",
                "logs:DescribeLogGroups",
                "logs:PutRetentionPolicy",
                "logs:TagLogGroup",
                "logs:UntagLogGroup"
            ],
            "Resource": [
                "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/*-ParallelClusterFunction-*"
            ],
            "Effect": "Allow",
            "Sid": "Logs"
        },
        {
            "Action": [
                "apigateway:DELETE",
                "apigateway:GET",
                "apigateway:PATCH",
                "apigateway:POST",
                "apigateway:PUT",
                "apigateway:UpdateRestApiPolicy"
            ],
            "Resource": [
                "arn:aws:apigateway:us-east-1::/restapis",
                "arn:aws:apigateway:us-east-1::/restapis/*",
                "arn:aws:apigateway:us-east-1::/tags/*"
            ],
            "Effect": "Allow",
            "Sid": "APIGateway"
        }
    ]
}
```

------