第2章 Terraform を使用した ROSA クラスターの作成
2.1. Terraform を使用したデフォルトの ROSA クラスターの作成
デフォルトのクラスターオプションで設定された Terraform クラスターテンプレートを使用して、Red Hat OpenShift Service on AWS (ROSA) クラスターを迅速に作成します。
以下で説明するクラスター作成プロセスでは、次のリソースを使用して ROSA with HCP クラスターを準備する Terraform 設定を使用します。
-
マネージド
oidc-config
設定を使用する OIDC プロバイダー - 関連する AWS Managed ROSA ポリシーを備えた IAM Operator ロールの前提条件
- 関連する AWS Managed ROSA ポリシーを含む IAM アカウントロール
- STS を使用する ROSA クラスターの作成に必要な他のすべての AWS リソース
2.1.1. Terraform の概要
Terraform は、リソースを設定すると必要に応じてそれらのリソースをレプリケートできる infrastructure-as-code ツールです。Terraform は、宣言的言語を使用して作成タスクを実行します。インフラストラクチャーリソースの任意の最終状態を宣言すると、Terraform は仕様に合わせてリソースを作成します。
前提条件
Terraform 設定内で Red Hat Cloud Services プロバイダー を使用するには、次の前提条件を満たす必要があります。
- Red Hat OpenShift Service on AWS (ROSA) コマンドラインインターフェイス (CLI) ツールをインストールしている。
- オフライン Red Hat OpenShift Cluster Manager トークン がある。
- Terraform バージョン 1.4.6 以降をインストールしている。
AWS アカウント全体の IAM ロールを作成している。
特定のアカウント全体の IAM ロールとポリシーが ROSA のサポート、インストール、コントロールプレーン、コンピューティング機能に必要な STS 権限を提供する。これには、アカウント全体の Operator ポリシーが含まれます。AWS アカウントロールの詳細は、関連情報を参照してください。
- リソースを作成できる AWS アカウント と 関連する認証情報 がある。この認証情報は AWS プロバイダー用に設定されているものです。AWS Terraform プロバイダーのドキュメントで、Authentication and Configuration セクションを参照してください。
Terraform を操作する AWS IAM ロールポリシーに、少なくとも以下の権限がある。権限は、AWS コンソールで確認してください。
例2.1 Terraform の最小限の AWS 権限
{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "iam:GetPolicyVersion", "iam:DeletePolicyVersion", "iam:CreatePolicyVersion", "iam:UpdateAssumeRolePolicy", "secretsmanager:DescribeSecret", "iam:ListRoleTags", "secretsmanager:PutSecretValue", "secretsmanager:CreateSecret", "iam:TagRole", "secretsmanager:DeleteSecret", "iam:UpdateOpenIDConnectProviderThumbprint", "iam:DeletePolicy", "iam:CreateRole", "iam:AttachRolePolicy", "iam:ListInstanceProfilesForRole", "secretsmanager:GetSecretValue", "iam:DetachRolePolicy", "iam:ListAttachedRolePolicies", "iam:ListPolicyTags", "iam:ListRolePolicies", "iam:DeleteOpenIDConnectProvider", "iam:DeleteInstanceProfile", "iam:GetRole", "iam:GetPolicy", "iam:ListEntitiesForPolicy", "iam:DeleteRole", "iam:TagPolicy", "iam:CreateOpenIDConnectProvider", "iam:CreatePolicy", "secretsmanager:GetResourcePolicy", "iam:ListPolicyVersions", "iam:UpdateRole", "iam:GetOpenIDConnectProvider", "iam:TagOpenIDConnectProvider", "secretsmanager:TagResource", "sts:AssumeRoleWithWebIdentity", "iam:ListRoles" ], "Resource": [ "arn:aws:secretsmanager:*:<ACCOUNT_ID>:secret:*", "arn:aws:iam::<ACCOUNT_ID>:instance-profile/*", "arn:aws:iam::<ACCOUNT_ID>:role/*", "arn:aws:iam::<ACCOUNT_ID>:oidc-provider/*", "arn:aws:iam::<ACCOUNT_ID>:policy/*" ] }, { "Sid": "VisualEditor1", "Effect": "Allow", "Action": [ "s3:*" ], "Resource": "*" } ] }
{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "iam:GetPolicyVersion", "iam:DeletePolicyVersion", "iam:CreatePolicyVersion", "iam:UpdateAssumeRolePolicy", "secretsmanager:DescribeSecret", "iam:ListRoleTags", "secretsmanager:PutSecretValue", "secretsmanager:CreateSecret", "iam:TagRole", "secretsmanager:DeleteSecret", "iam:UpdateOpenIDConnectProviderThumbprint", "iam:DeletePolicy", "iam:CreateRole", "iam:AttachRolePolicy", "iam:ListInstanceProfilesForRole", "secretsmanager:GetSecretValue", "iam:DetachRolePolicy", "iam:ListAttachedRolePolicies", "iam:ListPolicyTags", "iam:ListRolePolicies", "iam:DeleteOpenIDConnectProvider", "iam:DeleteInstanceProfile", "iam:GetRole", "iam:GetPolicy", "iam:ListEntitiesForPolicy", "iam:DeleteRole", "iam:TagPolicy", "iam:CreateOpenIDConnectProvider", "iam:CreatePolicy", "secretsmanager:GetResourcePolicy", "iam:ListPolicyVersions", "iam:UpdateRole", "iam:GetOpenIDConnectProvider", "iam:TagOpenIDConnectProvider", "secretsmanager:TagResource", "sts:AssumeRoleWithWebIdentity", "iam:ListRoles" ], "Resource": [ "arn:aws:secretsmanager:*:<ACCOUNT_ID>:secret:*", "arn:aws:iam::<ACCOUNT_ID>:instance-profile/*", "arn:aws:iam::<ACCOUNT_ID>:role/*", "arn:aws:iam::<ACCOUNT_ID>:oidc-provider/*", "arn:aws:iam::<ACCOUNT_ID>:policy/*" ] }, { "Sid": "VisualEditor1", "Effect": "Allow", "Action": [ "s3:*" ], "Resource": "*" } ] }
Copy to Clipboard Copied!
Terraform を使用する場合の考慮事項
一般に、Terraform を使用してクラウドリソースを管理する場合は、すべての変更が Terraform 方法論を使用して実行されることを前提として行う必要があります。AWS コンソールや Red Hat コンソールなど、Terraform 外部のツールを使用して Terraform によって作成されたクラウドリソースを変更する場合は注意してください。Terraform によってすでに管理されているクラウドリソースを管理するために Terraform 外部のツールを使用すると、宣言した Terraform 設定から設定のドリフトが発生します。
たとえば、Red Hat Hybrid Cloud Console を使用して Terraform で作成されたクラスターをアップグレードする場合は、今後の設定変更を適用する前に Terraform の状態を調整する必要があります。詳細は、HashiCorp Developer ドキュメントの Manage resources in Terraform state を参照してください。
2.1.2. デフォルトのクラスター仕様の概要
コンポーネント | デフォルトの仕様 |
---|---|
アカウントおよびロール |
|
クラスター設定 |
|
暗号化 |
|
コントロールプレーンノードの設定 |
|
インフラストラクチャーノードの設定 |
|
コンピュートノードマシンプール |
|
ネットワーク設定 |
|
Classless Inter-Domain Routing (CIDR) の範囲 |
|
クラスターのロールおよびポリシー |
|
ストレージ |
|
クラスター更新戦略 |
|
2.1.3. Terraform を使用したデフォルトの ROSA クラスターの作成
以下に概説するクラスター作成プロセスでは、Terraform を使用して、アカウント全体の IAM ロールとマネージド OIDC 設定を使用する ROSA クラスターを作成する方法を示します。
2.1.3.1. Terraform 用の環境の準備
Terraform を使用して Red Hat OpenShift Service on AWS クラスターを作成する前に、オフラインの Red Hat OpenShift Cluster Manager トークン をエクスポートする必要があります。
手順
オプション: この手順の実行中、現在のディレクトリーに Terraform ファイルが作成されます。次のコマンドを実行すると、これらのファイルを保存する新しいディレクトリーを作成してそこに移動できます。
mkdir terraform-cluster && cd terraform-cluster
$ mkdir terraform-cluster && cd terraform-cluster
Copy to Clipboard Copied! - オフラインの Red Hat OpenShift Cluster Manager トークン を使用して、アカウントに権限を付与します。
オフライントークンをコピーし、次のコマンドを実行してトークンを環境変数として設定します。
export RHCS_TOKEN=<your_offline_token>
$ export RHCS_TOKEN=<your_offline_token>
Copy to Clipboard Copied! 注記この環境変数は、マシンの再起動やターミナルの終了など、各セッションの終了時にリセットされます。
検証
トークンをエクスポートしたら、次のコマンドを実行して値を確認します。
echo $RHCS_TOKEN
$ echo $RHCS_TOKEN
Copy to Clipboard Copied!
2.1.3.2. ローカルでの Terraform ファイルの作成
オフラインの Red Hat OpenShift Cluster Manager トークン を設定した後、クラスターを構築するために Terraform ファイルをローカルで作成する必要があります。このファイルは、次のコードテンプレートを使用して作成できます。
手順
次のコマンドを実行して、
main.tf
ファイルを作成します。cat<<-EOF>main.tf # Copyright (c) 2023 Red Hat, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. # terraform { required_providers { aws = { source = "hashicorp/aws" version = ">= 4.20.0" } rhcs = { version = ">= 1.6.3" source = "terraform-redhat/rhcs" } } } Export token using the RHCS_TOKEN environment variable provider "rhcs" {} provider "aws" { region = var.aws_region ignore_tags { key_prefixes = ["kubernetes.io/"] } default_tags { tags = var.default_aws_tags } } data "aws_availability_zones" "available" {} locals { # Extract availability zone names for the specified region, limit it to 3 if multi az or 1 if single region_azs = var.multi_az ? slice([for zone in data.aws_availability_zones.available.names : format("%s", zone)], 0, 3) : slice([for zone in data.aws_availability_zones.available.names : format("%s", zone)], 0, 1) } resource "random_string" "random_name" { length = 6 special = false upper = false } locals { worker_node_replicas = var.multi_az ? 3 : 2 # If cluster_name is not null, use that, otherwise generate a random cluster name cluster_name = coalesce(var.cluster_name, "rosa-\${random_string.random_name.result}") } The network validator requires an additional 60 seconds to validate Terraform clusters. resource "time_sleep" "wait_60_seconds" { count = var.create_vpc ? 1 : 0 depends_on = [module.vpc] create_duration = "60s" } module "rosa-hcp" { source = "terraform-redhat/rosa-hcp/rhcs" version = "1.6.3" cluster_name = local.cluster_name openshift_version = var.openshift_version account_role_prefix = local.cluster_name operator_role_prefix = local.cluster_name replicas = local.worker_node_replicas aws_availability_zones = local.region_azs create_oidc = true private = var.private_cluster aws_subnet_ids = var.create_vpc ? var.private_cluster ? module.vpc[0].private_subnets : concat(module.vpc[0].public_subnets, module.vpc[0].private_subnets) : var.aws_subnet_ids create_account_roles = true create_operator_roles = true Optional: Configure a cluster administrator user \ # # Option 1: Default cluster-admin user Create an administrator user (cluster-admin) and automatically generate a password by uncommenting the following parameter: create_admin_user = true Generated administrator credentials are displayed in terminal output. # Option 2: Specify administrator username and password Create an administrator user and define your own password by uncommenting and editing the values of the following parameters: admin_credentials_username = <username> admin_credentials_password = <password> depends_on = [time_sleep.wait_60_seconds] } EOF
$ cat<<-EOF>main.tf # # Copyright (c) 2023 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # terraform { required_providers { aws = { source = "hashicorp/aws" version = ">= 4.20.0" } rhcs = { version = ">= 1.6.3" source = "terraform-redhat/rhcs" } } } # Export token using the RHCS_TOKEN environment variable provider "rhcs" {} provider "aws" { region = var.aws_region ignore_tags { key_prefixes = ["kubernetes.io/"] } default_tags { tags = var.default_aws_tags } } data "aws_availability_zones" "available" {} locals { # Extract availability zone names for the specified region, limit it to 3 if multi az or 1 if single region_azs = var.multi_az ? slice([for zone in data.aws_availability_zones.available.names : format("%s", zone)], 0, 3) : slice([for zone in data.aws_availability_zones.available.names : format("%s", zone)], 0, 1) } resource "random_string" "random_name" { length = 6 special = false upper = false } locals { worker_node_replicas = var.multi_az ? 3 : 2 # If cluster_name is not null, use that, otherwise generate a random cluster name cluster_name = coalesce(var.cluster_name, "rosa-\${random_string.random_name.result}") } # The network validator requires an additional 60 seconds to validate Terraform clusters. resource "time_sleep" "wait_60_seconds" { count = var.create_vpc ? 1 : 0 depends_on = [module.vpc] create_duration = "60s" } module "rosa-hcp" { source = "terraform-redhat/rosa-hcp/rhcs" version = "1.6.3" cluster_name = local.cluster_name openshift_version = var.openshift_version account_role_prefix = local.cluster_name operator_role_prefix = local.cluster_name replicas = local.worker_node_replicas aws_availability_zones = local.region_azs create_oidc = true private = var.private_cluster aws_subnet_ids = var.create_vpc ? var.private_cluster ? module.vpc[0].private_subnets : concat(module.vpc[0].public_subnets, module.vpc[0].private_subnets) : var.aws_subnet_ids create_account_roles = true create_operator_roles = true # Optional: Configure a cluster administrator user \
1 # # Option 1: Default cluster-admin user # Create an administrator user (cluster-admin) and automatically # generate a password by uncommenting the following parameter: # create_admin_user = true # Generated administrator credentials are displayed in terminal output. # # Option 2: Specify administrator username and password # Create an administrator user and define your own password # by uncommenting and editing the values of the following parameters: # admin_credentials_username = <username> # admin_credentials_password = <password> depends_on = [time_sleep.wait_60_seconds] } EOF
Copy to Clipboard Copied! - 1
- オプション: 適切なパラメーターのコメントを解除し、必要に応じて値を編集して、クラスターの作成中に管理者ユーザーを作成します。
次のコマンドを実行して、
variables.tf
ファイルを作成します。注記クラスターを構築するコマンドを実行する 前 に、このファイルをコピーして編集します。
cat<<-EOF>variables.tf # Copyright (c) 2023 Red Hat, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. # variable "openshift_version" { type = string default = "4.14.20" description = "Desired version of OpenShift for the cluster, for example '4.14.20'. If version is greater than the currently running version, an upgrade will be scheduled." } variable "create_vpc" { type = bool description = "If you would like to create a new VPC, set this value to 'true'. If you do not want to create a new VPC, set this value to 'false'." } ROSA Cluster info variable "cluster_name" { default = null type = string description = "The name of the ROSA cluster to create" } variable "additional_tags" { default = { Terraform = "true" Environment = "dev" } description = "Additional AWS resource tags" type = map(string) } variable "multi_az" { type = bool description = "Multi AZ Cluster for High Availability" default = true } variable "worker_node_replicas" { default = 3 description = "Number of worker nodes to provision. Single zone clusters need at least 2 nodes, multizone clusters need at least 3 nodes" type = number } variable "aws_subnet_ids" { type = list(any) description = "A list of either the public or public + private subnet IDs to use for the cluster blocks to use for the cluster" default = ["subnet-01234567890abcdef", "subnet-01234567890abcdef", "subnet-01234567890abcdef"] } variable "private_cluster" { type = bool description = "If you want to create a private cluster, set this value to 'true'. If you want a publicly available cluster, set this value to 'false'." } #VPC Info variable "vpc_name" { type = string description = "VPC Name" default = "tf-qs-vpc" } variable "vpc_cidr_block" { type = string description = "value of the CIDR block to use for the VPC" default = "10.0.0.0/16" } variable "private_subnet_cidrs" { type = list(any) description = "The CIDR blocks to use for the private subnets" default = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] } variable "public_subnet_cidrs" { type = list(any) description = "The CIDR blocks to use for the public subnets" default = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] } variable "single_nat_gateway" { type = bool description = "Single NAT or per NAT for subnet" default = false } #AWS Info variable "aws_region" { type = string default = "us-east-2" } variable "default_aws_tags" { type = map(string) description = "Default tags for AWS" default = {} } EOF
$ cat<<-EOF>variables.tf # # Copyright (c) 2023 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # variable "openshift_version" { type = string default = "4.14.20" description = "Desired version of OpenShift for the cluster, for example '4.14.20'. If version is greater than the currently running version, an upgrade will be scheduled." } variable "create_vpc" { type = bool description = "If you would like to create a new VPC, set this value to 'true'. If you do not want to create a new VPC, set this value to 'false'." } # ROSA Cluster info variable "cluster_name" { default = null type = string description = "The name of the ROSA cluster to create" } variable "additional_tags" { default = { Terraform = "true" Environment = "dev" } description = "Additional AWS resource tags" type = map(string) } variable "multi_az" { type = bool description = "Multi AZ Cluster for High Availability" default = true } variable "worker_node_replicas" { default = 3 description = "Number of worker nodes to provision. Single zone clusters need at least 2 nodes, multizone clusters need at least 3 nodes" type = number } variable "aws_subnet_ids" { type = list(any) description = "A list of either the public or public + private subnet IDs to use for the cluster blocks to use for the cluster" default = ["subnet-01234567890abcdef", "subnet-01234567890abcdef", "subnet-01234567890abcdef"] } variable "private_cluster" { type = bool description = "If you want to create a private cluster, set this value to 'true'. If you want a publicly available cluster, set this value to 'false'." } #VPC Info variable "vpc_name" { type = string description = "VPC Name" default = "tf-qs-vpc" } variable "vpc_cidr_block" { type = string description = "value of the CIDR block to use for the VPC" default = "10.0.0.0/16" } variable "private_subnet_cidrs" { type = list(any) description = "The CIDR blocks to use for the private subnets" default = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] } variable "public_subnet_cidrs" { type = list(any) description = "The CIDR blocks to use for the public subnets" default = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"] } variable "single_nat_gateway" { type = bool description = "Single NAT or per NAT for subnet" default = false } #AWS Info variable "aws_region" { type = string default = "us-east-2" } variable "default_aws_tags" { type = map(string) description = "Default tags for AWS" default = {} } EOF
Copy to Clipboard Copied! 以下のコマンドを実行して
vpc.tf
ファイルを作成します。cat<<-EOF>vpc.tf # Copyright (c) 2023 Red Hat, Inc. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. # module "vpc" { source = "terraform-aws-modules/vpc/aws" version = "5.1.2" count = var.create_vpc ? 1 : 0 name = var.vpc_name cidr = var.vpc_cidr_block azs = local.region_azs private_subnets = var.multi_az ? var.private_subnet_cidrs : [var.private_subnet_cidrs[0]] public_subnets = var.multi_az ? var.public_subnet_cidrs : [var.public_subnet_cidrs[0]] enable_nat_gateway = true single_nat_gateway = var.single_nat_gateway enable_dns_hostnames = true enable_dns_support = true tags = var.additional_tags } EOF
$ cat<<-EOF>vpc.tf # # Copyright (c) 2023 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # module "vpc" { source = "terraform-aws-modules/vpc/aws" version = "5.1.2" count = var.create_vpc ? 1 : 0 name = var.vpc_name cidr = var.vpc_cidr_block azs = local.region_azs private_subnets = var.multi_az ? var.private_subnet_cidrs : [var.private_subnet_cidrs[0]] public_subnets = var.multi_az ? var.public_subnet_cidrs : [var.public_subnet_cidrs[0]] enable_nat_gateway = true single_nat_gateway = var.single_nat_gateway enable_dns_hostnames = true enable_dns_support = true tags = var.additional_tags } EOF
Copy to Clipboard Copied! これで Terraform を起動する準備ができました。
2.1.3.3. Terraform を使用した ROSA クラスターの作成
Terraform ファイルを作成した後、Terraform を起動して、必要な依存関係をすべて提供する必要があります。その後、Terraform プランを適用します。
Terraform の状態ファイルは変更しないでください。詳細は、Terraform 使用時の考慮事項 を参照してください。
手順
Terraform ファイルに基づいてリソースを作成するように Terraform を設定し、次のコマンドを実行します。
terraform init
$ terraform init
Copy to Clipboard Copied! オプション: 次のコマンドを実行して、コピーした Terraform が正しいことを確認します。
terraform validate
$ terraform validate
Copy to Clipboard Copied! 出力例
Success! The configuration is valid.
Success! The configuration is valid.
Copy to Clipboard Copied! 次のコマンドを実行して、Terraform を使用してクラスターを作成します。
terraform apply
$ terraform apply
Copy to Clipboard Copied! Terraform インターフェイスでは、クラスターを作成するために次のような 2 つの質問が表示されます。
出力例
var.create_vpc If you would like to create a new VPC, set this value to 'true'. If you do not want to create a new VPC, set this value to 'false'. Enter a value: var.private_cluster If you want to create a private cluster, set this value to 'true'. If you want a publicly available cluster, set this value to 'false'. Enter a value:
var.create_vpc If you would like to create a new VPC, set this value to 'true'. If you do not want to create a new VPC, set this value to 'false'. Enter a value: var.private_cluster If you want to create a private cluster, set this value to 'true'. If you want a publicly available cluster, set this value to 'false'. Enter a value:
Copy to Clipboard Copied! Terraform インターフェイスに作成または変更するリソースがリストされ、確認を求めるプロンプトが表示されたら、続行するには
yes
を、キャンセルするにはno
を入力します。出力例
Plan: 63 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.
Plan: 63 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.
Copy to Clipboard Copied! yes
と入力すると、Terraform プランが開始され、AWS アカウントロール、Operator ロール、ROSA Classic クラスターが作成されます。
検証
次のコマンドを実行して、クラスターが作成されたことを確認します。
rosa list clusters
$ rosa list clusters
Copy to Clipboard Copied! クラスターの ID、名前、ステータスを示す出力例
ID NAME STATE TOPOLOGY 27c3snjsupa9obua74ba8se5kcj11269 rosa-tf-demo ready Classic (STS)
ID NAME STATE TOPOLOGY 27c3snjsupa9obua74ba8se5kcj11269 rosa-tf-demo ready Classic (STS)
Copy to Clipboard Copied! 次のコマンドを実行して、アカウントロールが作成されたことを確認します。
rosa list account-roles
$ rosa list account-roles
Copy to Clipboard Copied! 出力例
I: Fetching account roles ROLE NAME ROLE TYPE ROLE ARN OPENSHIFT VERSION AWS Managed ROSA-demo-Installer-Role Installer arn:aws:iam::<ID>:role/ROSA-demo-Installer-Role 4.14 No ROSA-demo-Support-Role Support arn:aws:iam::<ID>:role/ROSA-demo-Support-Role 4.14 No ROSA-demo-Worker-Role Worker arn:aws:iam::<ID>:role/ROSA-demo-Worker-Role 4.14 No
I: Fetching account roles ROLE NAME ROLE TYPE ROLE ARN OPENSHIFT VERSION AWS Managed ROSA-demo-Installer-Role Installer arn:aws:iam::<ID>:role/ROSA-demo-Installer-Role 4.14 No ROSA-demo-Support-Role Support arn:aws:iam::<ID>:role/ROSA-demo-Support-Role 4.14 No ROSA-demo-Worker-Role Worker arn:aws:iam::<ID>:role/ROSA-demo-Worker-Role 4.14 No
Copy to Clipboard Copied! 次のコマンドを実行して、Operator ロールが作成されたことを確認します。
rosa list operator-roles
$ rosa list operator-roles
Copy to Clipboard Copied! Terraform で作成された Operator ロールを示す出力例
I: Fetching operator roles ROLE PREFIX AMOUNT IN BUNDLE rosa-demo 8
I: Fetching operator roles ROLE PREFIX AMOUNT IN BUNDLE rosa-demo 8
Copy to Clipboard Copied!
2.1.3.4. Terraform を使用した ROSA クラスターの削除
terraform destroy
コマンドを使用して、terraform apply
コマンドで作成したすべてのリソースを削除します。
リソースを破棄する前に、Terraform の .tf
ファイルを変更しないでください。これらの変数は削除対象のリソースと照合されます。
手順
terraform apply
コマンドを実行してクラスターを作成したディレクトリーで、次のコマンドを実行してクラスターを削除します。terraform destroy
$ terraform destroy
Copy to Clipboard Copied! Terraform インターフェイスでは、2 つの変数の入力を求められます。これらは、クラスターの作成時に指定した回答と一致する必要があります。
var.create_vpc If you would like to create a new VPC, set this value to 'true.' If you do not want to create a new VPC, set this value to 'false.' Enter a value: var.private_cluster If you want to create a private cluster, set this value to 'true.' If you want a publicly available cluster, set this value to 'false.' Enter a value:
var.create_vpc If you would like to create a new VPC, set this value to 'true.' If you do not want to create a new VPC, set this value to 'false.' Enter a value: var.private_cluster If you want to create a private cluster, set this value to 'true.' If you want a publicly available cluster, set this value to 'false.' Enter a value:
Copy to Clipboard Copied! yes
と入力して、ロールとクラスターの削除を開始します。出力例
Plan: 0 to add, 0 to change, 63 to destroy. Do you really want to destroy all resources? Terraform will destroy all your managed infrastructure, as shown above. There is no undo. Only 'yes' will be accepted to confirm. Enter a value: yes
Plan: 0 to add, 0 to change, 63 to destroy. Do you really want to destroy all resources? Terraform will destroy all your managed infrastructure, as shown above. There is no undo. Only 'yes' will be accepted to confirm. Enter a value: yes
Copy to Clipboard Copied!
検証
次のコマンドを実行して、クラスターが破棄されたことを確認します。
rosa list clusters
$ rosa list clusters
Copy to Clipboard Copied! クラスターがないことを示す出力例
I: No clusters available
I: No clusters available
Copy to Clipboard Copied! 次のコマンドを実行して、アカウントロールが破棄されたことを確認します。
rosa list account-roles
$ rosa list account-roles
Copy to Clipboard Copied! Terraform で作成されたアカウントロールがないことを示す出力例
I: Fetching account roles I: No account roles available
I: Fetching account roles I: No account roles available
Copy to Clipboard Copied! 次のコマンドを実行して、Operator ロールが破棄されたことを確認します。
rosa list operator-roles
$ rosa list operator-roles
Copy to Clipboard Copied! Terraform で作成された Operator ロールがないことを示す出力例
I: Fetching operator roles I: No operator roles available
I: Fetching operator roles I: No operator roles available
Copy to Clipboard Copied!