Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 3. Creating a ROSA cluster using Terraform
3.1. Creating a default Red Hat OpenShift Service on AWS cluster using Terraform Link kopierenLink in die Zwischenablage kopiert!
Create a Red Hat OpenShift Service on AWS cluster quickly by using a Terraform cluster template that is configured with the default cluster options.
The cluster creation process described below uses a Terraform configuration that prepares a Red Hat OpenShift Service on AWS cluster with the following resources:
-
An OIDC provider with a managed
oidc-config
configuration - Prerequisite IAM Operator roles with associated AWS Managed Red Hat OpenShift Service on AWS Policies
- IAM account roles with associated AWS Managed Red Hat OpenShift Service on AWS Policies
- All other AWS resources required to create a Red Hat OpenShift Service on AWS cluster
3.1.1. Overview of Terraform Link kopierenLink in die Zwischenablage kopiert!
Terraform is an infrastructure-as-code tool that provides a way to configure your resources once and replicate those resources as desired. Terraform accomplishes the creation tasks by using declarative language. You declare what you want the final state of the infrastructure resource to be, and Terraform creates these resources to your specifications.
Prerequisites
To use the Red Hat Cloud Services provider inside your Terraform configuration, you must meet the following prerequisites:
- You have installed the ROSA CLI tool.
- You have your offline Red Hat OpenShift Cluster Manager token.
- You have installed Terraform version 1.4.6 or newer.
You have created your AWS account-wide IAM roles.
The specific account-wide IAM roles and policies provide the STS permissions required for Red Hat OpenShift Service on AWS support, installation, control plane, and compute functionality. This includes account-wide Operator policies. See the Additional resources for more information on the AWS account roles.
- You have an AWS account and associated credentials that allow you to create resources. The credentials are configured for the AWS provider. See the Authentication and Configuration section in AWS Terraform provider documentation.
You have, at minimum, the following permissions in your AWS IAM role policy that is operating Terraform. Check for these permissions in the AWS console.
Example 3.1. Minimum AWS permissions for Terraform
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Considerations when using Terraform
In general, using Terraform to manage cloud resources should be done with the expectation that any changes should be done using the Terraform methodology. Use caution when using tools outside of Terraform, such as the AWS console or Red Hat console, to modify cloud resources created by Terraform. Using tools outside Terraform to manage cloud resources that are already managed by Terraform introduces configuration drift from your declared Terraform configuration.
For example, if you upgrade your Terraform-created cluster by using the Red Hat Hybrid Cloud Console, you need to reconcile your Terraform state before applying any forthcoming configuration changes. For more information, see Manage resources in Terraform state in the HashiCorp Developer documentation.
3.1.2. Overview of the default cluster specifications Link kopierenLink in die Zwischenablage kopiert!
You can quickly create a Red Hat OpenShift Service on AWS cluster by using the default installation options.
The following summary describes the default cluster specifications.
Component | Default specifications |
---|---|
Accounts and roles |
|
Cluster settings |
|
Compute node machine pool |
|
Networking configuration |
|
Classless Inter-Domain Routing (CIDR) ranges |
|
Cluster roles and policies |
|
Storage |
|
Cluster update strategy |
|
3.1.3. Creating a default Red Hat OpenShift Service on AWS cluster using Terraform Link kopierenLink in die Zwischenablage kopiert!
The cluster creation process outlined below shows how to use Terraform to create your account-wide IAM roles and a Red Hat OpenShift Service on AWS cluster with a managed OIDC configuration.
3.1.3.1. Preparing your environment for Terraform Link kopierenLink in die Zwischenablage kopiert!
Before you can create your Red Hat OpenShift Service on AWS cluster by using Terraform, you need to export your offline Red Hat OpenShift Cluster Manager token.
Procedure
Optional: Because the Terraform files get created in your current directory during this procedure, you can create a new directory to store these files and navigate into it by running the following command:
mkdir terraform-cluster && cd terraform-cluster
$ mkdir terraform-cluster && cd terraform-cluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Grant permissions to your account by using an offline Red Hat OpenShift Cluster Manager token.
Copy your offline token, and set the token as an environmental variable by running the following command:
export RHCS_TOKEN=<your_offline_token>
$ export RHCS_TOKEN=<your_offline_token>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis environmental variable resets at the end of each session, such as restarting your machine or closing the terminal.
Verification
After you export your token, verify the value by running the following command:
echo $RHCS_TOKEN
$ echo $RHCS_TOKEN
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.1.3.2. Creating your Terraform files locally Link kopierenLink in die Zwischenablage kopiert!
After you set up your offline Red Hat OpenShift Cluster Manager token, you need to create the Terraform files locally to build your cluster. You can create these files by using the following code templates.
Procedure
Create the
main.tf
file by running the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Optional: Create an administrator user during cluster creation by uncommenting the appropriate parameters and editing their values if required.
Create the
variables.tf
file by running the following command:NoteCopy and edit this file before running the command to build your cluster.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
vpc.tf
file by running the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow You are ready to initiate Terraform.
3.1.3.3. Using Terraform to create your Red Hat OpenShift Service on AWS cluster Link kopierenLink in die Zwischenablage kopiert!
After you create the Terraform files, you must initiate Terraform to provide all of the required dependencies. Then apply the Terraform plan.
Do not modify Terraform state files. For more information, see Considerations when using Terraform
Procedure
Set up Terraform to create your resources based on your Terraform files, run the following command:
terraform init
$ terraform init
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Verify that the Terraform you copied is correct by running the following command:
terraform validate
$ terraform validate
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Success! The configuration is valid.
Success! The configuration is valid.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create your cluster with Terraform by running the following command:
terraform apply
$ terraform apply
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The Terraform interface asks two questions to create your cluster, similar to the following:
Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enter
yes
to proceed orno
to cancel when the Terraform interface lists the resources to be created or changed and prompts for confirmation:Example output
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! Toggle word wrap Toggle overflow If you enter
yes
, your Terraform plan starts, creating your AWS account roles, Operator roles, and your Red Hat OpenShift Service on AWS cluster.
Verification
Verify that your cluster was created by running the following command:
rosa list clusters
$ rosa list clusters
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output showing a cluster’s ID, name, and status
ID NAME STATE TOPOLOGY 27c3snjsupa9obua74ba8se5kcj11269 rosa-tf-demo ready Hosted CP
ID NAME STATE TOPOLOGY 27c3snjsupa9obua74ba8se5kcj11269 rosa-tf-demo ready Hosted CP
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that your account roles were created by running the following command:
rosa list account-roles
$ rosa list account-roles
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
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! Toggle word wrap Toggle overflow Verify that your Operator roles were created by running the following command:
rosa list operator-roles
$ rosa list operator-roles
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output showing Terraform-created Operator roles
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! Toggle word wrap Toggle overflow
3.1.3.4. Deleting your Red Hat OpenShift Service on AWS cluster with Terraform Link kopierenLink in die Zwischenablage kopiert!
Use the terraform destroy
command to remove all of the resources that were created with the terraform apply
command.
Do not modify your Terraform .tf
files before destroying your resources. These variables are matched to resources to delete.
Procedure
In the directory where you ran the
terraform apply
command to create your cluster, run the following command to delete the cluster:terraform destroy
$ terraform destroy
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The Terraform interface prompts you for two variables. These should match the answers you provided when creating a cluster:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enter
yes
to start the role and cluster deletion:Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that your cluster was destroyed by running the following command:
rosa list clusters
$ rosa list clusters
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output showing no cluster
I: No clusters available
I: No clusters available
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the account roles were destroyed by running the following command:
rosa list account-roles
$ rosa list account-roles
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output showing no Terraform-created account roles
I: Fetching account roles I: No account roles available
I: Fetching account roles I: No account roles available
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the Operator roles were destroyed by running the following command:
rosa list operator-roles
$ rosa list operator-roles
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output showing no Terraform-created Operator roles
I: Fetching operator roles I: No operator roles available
I: Fetching operator roles I: No operator roles available
Copy to Clipboard Copied! Toggle word wrap Toggle overflow