From 7b68383f3375aac21f190a961d579b26242ac8d8 Mon Sep 17 00:00:00 2001 From: leiicamundi <153937047+leiicamundi@users.noreply.github.com> Date: Fri, 17 May 2024 17:00:37 +0200 Subject: [PATCH] apply suggestions from review --- .github/actions/rosa-create-cluster/README.md | 22 ++++++++----- .../actions/rosa-create-cluster/action.yml | 33 +++++++++++++++++-- .github/actions/rosa-delete-cluster/README.md | 12 ++++--- .../actions/rosa-delete-cluster/action.yml | 32 ++++++++++++++++-- .github/workflows/tests.yml | 32 ++++++++++-------- README.md | 12 +++---- 6 files changed, 104 insertions(+), 39 deletions(-) diff --git a/.github/actions/rosa-create-cluster/README.md b/.github/actions/rosa-create-cluster/README.md index b95b816..a03bc4f 100644 --- a/.github/actions/rosa-create-cluster/README.md +++ b/.github/actions/rosa-create-cluster/README.md @@ -9,16 +9,20 @@ This GitHub Action automates the deployment of a ROSA (Red Hat OpenShift Service | `rh-token` | Red Hat Hybrid Cloud Console Token | true | | | `cluster-name` | Name of the ROSA cluster to deploy | true | | | `admin-password` | Admin password for the ROSA cluster | true | | -| `admin-username` | Admin username for the ROSA cluster | true | `cluster-admin` | +| `admin-username` | Admin username for the ROSA cluster | false | `cluster-admin` | | `aws-region` | AWS region where the ROSA cluster will be deployed | true | | -| `rosa-cli-version` | Version of the ROSA CLI to use | true | `latest` | -| `awscli-version` | Version of the AWS CLI to use | true | `1.32.105` | -| `openshift-version` | Version of the OpenShift to install | true | `4.15.11` | -| `replicas` | Number of replicas for the ROSA cluster | true | `2` | +| `rosa-cli-version` | Version of the ROSA CLI to use | false | `latest` | +| `awscli-version` | Version of the AWS CLI to use | false | `1.32.105` | +| `openshift-version` | Version of the OpenShift to install | false | `4.15.11` | +| `replicas` | Number of replicas for the ROSA cluster | false | `2` | | `s3-backend-bucket` | Name of the S3 bucket to store Terraform state | true | | -| `tf-modules-revision`| Git revision of the Terraform modules to use | true | `main` | -| `tf-modules-path` | Path where the Terraform ROSA modules will be cloned | true | `./.action-tf-modules/rosa/` | -| `login` | Authenticate the current kube context on the created cluster | true | `true` | +| `tf-modules-revision`| Git revision of the Terraform modules to use | false | `main` | +| `tf-modules-path` | Path where the Terraform ROSA modules will be cloned | false | `./.action-tf-modules/rosa/` | +| `login` | Authenticate the current kube context on the created cluster | false | `true` | +| `tf-cli-config-credentials-hostname` | The hostname of a HCP Terraform/Terraform Enterprise instance to place within the credentials block of the Terraform CLI configuration file. Defaults to `app.terraform.io`. | false | `app.terraform.io` | +| `tf-cli-config-credentials-token` | The API token for a HCP Terraform/Terraform Enterprise instance to place within the credentials block of the Terraform CLI configuration file. | false | | +| `tf-terraform-version` | The version of Terraform CLI to install. Defaults to `latest`. | false | `latest` | +| `tf-terraform-wrapper` | Whether or not to install a wrapper to wrap subsequent calls of the `terraform` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`. | false | `true` | ## Outputs @@ -36,7 +40,7 @@ Create a file in your repository's `.github/workflows` directory, for example `d name: Deploy ROSA HCP Cluster on: - push: + pull_request: jobs: deploy: diff --git a/.github/actions/rosa-create-cluster/action.yml b/.github/actions/rosa-create-cluster/action.yml index 83f237e..a649e08 100644 --- a/.github/actions/rosa-create-cluster/action.yml +++ b/.github/actions/rosa-create-cluster/action.yml @@ -30,7 +30,7 @@ inputs: description: 'Version of the aws cli to use' required: true # renovate: datasource=github-releases depName=aws/aws-cli - default: "1.32.105" + default: "2.15.52" openshift-version: description: 'Version of the OpenShift to install' required: true @@ -56,6 +56,23 @@ inputs: default: "true" required: true + # inherited from https://github.com/hashicorp/setup-terraform/blob/main/action.yml + tf-cli-config-credentials-hostname: + description: 'The hostname of a HCP Terraform/Terraform Enterprise instance to place within the credentials block of the Terraform CLI configuration file. Defaults to `app.terraform.io`.' + default: 'app.terraform.io' + required: false + tf-cli-config-credentials-token: + description: 'The API token for a HCP Terraform/Terraform Enterprise instance to place within the credentials block of the Terraform CLI configuration file.' + required: false + tf-terraform-version: + description: 'The version of Terraform CLI to install. Instead of full version string you can also specify constraint string starting with "<" (for example `<1.13.0`) to install the latest version satisfying the constraint. A value of `latest` will install the latest version of Terraform CLI. Defaults to `latest`.' + default: 'latest' + required: false + tf-terraform-wrapper: + description: 'Whether or not to install a wrapper to wrap subsequent calls of the `terraform` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.' + default: 'true' + required: false + outputs: openshift-server-api: description: 'The server API URL of the deployed ROSA cluster' @@ -78,11 +95,17 @@ runs: curl -O "https://mirror.openshift.com/pub/openshift-v4/clients/rosa/${{ inputs.rosa-cli-version }}/rosa-linux.tar.gz" tar -xvf rosa-linux.tar.gz sudo mv rosa /usr/local/bin/rosa + chmod +x /usr/local/bin/rosa rm -f rosa-linux.tar.gz rosa version - name: Install Terraform uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # v3 + with: + cli_config_credentials_hostname: ${{ inputs.tf-cli-config-credentials-hostname }} + cli_config_credentials_token: ${{ inputs.tf-cli-config-credentials-token }} + terraform_version: ${{ inputs.tf-terraform-version }} + terraform_wrapper: ${{ inputs.tf-terraform-wrapper }} - name: Install CLI tools from OpenShift Mirror uses: redhat-actions/openshift-tools-installer@2de9a80cf012ad0601021515481d433b91ef8fd5 # v1 @@ -102,10 +125,14 @@ runs: rosa verify permissions --region="${{ inputs.aws-region }}" rosa create account-roles --mode auto - - name: Install aws-cli + - name: Install aws-cli v2 shell: bash run: | - python3 -m pip install "awscli==${{ inputs.awscli-version }}" + cd /tmp/awscli + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${{ inputs.awscli-version }}.zip" -o "awscliv2.zip" + unzip awscliv2.zip + sudo ./aws/install + cd - && rm -Rf /tmp/awscli - name: Check if S3 bucket exists id: create-s3-bucket diff --git a/.github/actions/rosa-delete-cluster/README.md b/.github/actions/rosa-delete-cluster/README.md index f32f971..f659fdb 100644 --- a/.github/actions/rosa-delete-cluster/README.md +++ b/.github/actions/rosa-delete-cluster/README.md @@ -10,9 +10,13 @@ This GitHub Action automates the deletion of a ROSA (Red Hat OpenShift Service o | `cluster-name` | Name of the ROSA cluster to delete | true | | | `aws-region` | AWS region where the ROSA cluster is deployed | true | | | `s3-backend-bucket` | Name of the S3 bucket where the Terraform state is stored| true | | -| `awscli-version` | Version of the aws cli to use | true | `1.32.105` | -| `tf-modules-revision`| Git revision of the tf modules to use | true | `main` | -| `tf-modules-path` | Path where the tf rosa modules will be cloned | true | `./.action-tf-modules/rosa/` | +| `awscli-version` | Version of the aws cli to use | false | `1.32.105` | +| `tf-modules-revision`| Git revision of the tf modules to use | false | `main` | +| `tf-modules-path` | Path where the tf rosa modules will be cloned | false | `./.action-tf-modules/rosa/` | +| `tf-cli-config-credentials-hostname` | The hostname of a HCP Terraform/Terraform Enterprise instance to place within the credentials block of the Terraform CLI configuration file. Defaults to `app.terraform.io`. | false | `app.terraform.io` | +| `tf-cli-config-credentials-token` | The API token for a HCP Terraform/Terraform Enterprise instance to place within the credentials block of the Terraform CLI configuration file. | false | | +| `tf-terraform-version` | The version of Terraform CLI to install. Defaults to `latest`. | false | `latest` | +| `tf-terraform-wrapper` | Whether or not to install a wrapper to wrap subsequent calls of the `terraform` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`. | false | `true` | ## Usage @@ -22,7 +26,7 @@ Create a file in your repository's `.github/workflows` directory, for example `d name: Delete ROSA HCP Cluster on: - workflow_dispatch: + pull_request: jobs: delete: diff --git a/.github/actions/rosa-delete-cluster/action.yml b/.github/actions/rosa-delete-cluster/action.yml index fe1536b..0828105 100644 --- a/.github/actions/rosa-delete-cluster/action.yml +++ b/.github/actions/rosa-delete-cluster/action.yml @@ -21,7 +21,7 @@ inputs: description: 'Version of the aws cli to use' required: true # renovate: datasource=github-releases depName=aws/aws-cli - default: "1.32.105" + default: "2.15.52" tf-modules-revision: description: 'Git revision of the tf modules to use' default: 'main' @@ -31,16 +31,42 @@ inputs: default: './.action-tf-modules/rosa/' required: true + # inherited from https://github.com/hashicorp/setup-terraform/blob/main/action.yml + tf-cli-config-credentials-hostname: + description: 'The hostname of a HCP Terraform/Terraform Enterprise instance to place within the credentials block of the Terraform CLI configuration file. Defaults to `app.terraform.io`.' + default: 'app.terraform.io' + required: false + tf-cli-config-credentials-token: + description: 'The API token for a HCP Terraform/Terraform Enterprise instance to place within the credentials block of the Terraform CLI configuration file.' + required: false + tf-terraform-version: + description: 'The version of Terraform CLI to install. Instead of full version string you can also specify constraint string starting with "<" (for example `<1.13.0`) to install the latest version satisfying the constraint. A value of `latest` will install the latest version of Terraform CLI. Defaults to `latest`.' + default: 'latest' + required: false + tf-terraform-wrapper: + description: 'Whether or not to install a wrapper to wrap subsequent calls of the `terraform` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.' + default: 'true' + required: false + runs: using: 'composite' steps: - name: Install Terraform uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # v3 + with: + cli_config_credentials_hostname: ${{ inputs.tf-cli-config-credentials-hostname }} + cli_config_credentials_token: ${{ inputs.tf-cli-config-credentials-token }} + terraform_version: ${{ inputs.tf-terraform-version }} + terraform_wrapper: ${{ inputs.tf-terraform-wrapper }} - - name: Install aws-cli + - name: Install aws-cli v2 shell: bash run: | - python3 -m pip install "awscli==${{ inputs.awscli-version }}" + cd /tmp/awscli + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${{ inputs.awscli-version }}.zip" -o "awscliv2.zip" + unzip awscliv2.zip + sudo ./aws/install + cd - && rm -Rf /tmp/awscli - name: Set Terraform variables shell: bash diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 24ddc20..29797c0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,7 +2,21 @@ name: Cluster creation and destruction test on: + schedule: + - cron: '0 1 * * 1' # At 01:00 on Monday. + workflow_dispatch: + inputs: + cluster_name: + description: "Cluster name." + required: false + type: string + delete_cluster: + description: "Whether to delete the cluster." + required: false + type: boolean + default: true + pull_request: # the paths should be synced with ../labeler.yml paths: @@ -35,24 +49,16 @@ jobs: ref: ${{ github.head_ref }} fetch-depth: 0 - - name: Get OCP Cluster Name and Delete Flag + - name: Get OCP Cluster Name id: commit_info run: | - commit_message=$(git log -1 --pretty=format:"%B") - if echo "$commit_message" | grep -qE 'ocp_cluster_name=([^\s]+)'; then - cluster_name=$(echo "$commit_message" | grep -oP 'ocp_cluster_name=\K[^\s]+') - else - cluster_name=$(git rev-parse --short HEAD) - fi - - if echo "$commit_message" | grep -q 'delete_ocp_cluster=false'; then - delete_cluster="false" + if [[ -n "${{ inputs.cluster_name }}" ]]; then + cluster_name="${{ inputs.cluster_name }}" else - delete_cluster="true" + cluster_name=$(git rev-parse --short HEAD) fi echo "cluster_name=$cluster_name" >> "$GITHUB_OUTPUT" - echo "delete_cluster=$delete_cluster" >> "$GITHUB_OUTPUT" - name: Import Secrets id: secrets @@ -99,7 +105,7 @@ jobs: - name: Delete Cluster timeout-minutes: 125 - if: always() && steps.commit_info.outputs.delete_cluster == 'true' + if: always() && !(inputs.delete_cluster == false) uses: ./.github/actions/rosa-delete-cluster with: rh-token: ${{ steps.secrets.outputs.RH_OPENSHIFT_TOKEN }} diff --git a/README.md b/README.md index 0338605..047d3b1 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,6 @@ This module automates the creation of a ROSA HCP cluster with an opinionated con For more detailed usage and configuration options, please refer to the module's inputs and outputs documentation below. -## Usage - ## Requirements To gather all specifics versions of this project, we use: @@ -64,10 +62,10 @@ rosa verify permissions --region="$AWS_REGION" rosa create account-roles --mode auto ``` 5. Enable HCP ROSA on [AWS MarkePlace](https://docs.openshift.com/rosa/cloud_experts_tutorials/cloud-experts-rosa-hcp-activation-and-account-linking-tutorial.html) - 5.1 Navigate to the ROSA console : https://console.aws.amazon.com/rosa - 5.2 Choose Get started. - 5.3 On the Verify ROSA prerequisites page, select I agree to share my contact information with Red Hat. - 5.4 Choose Enable ROSA + * Navigate to the ROSA console : https://console.aws.amazon.com/rosa + * Choose Get started. + * On the Verify ROSA prerequisites page, select I agree to share my contact information with Red Hat. + * Choose Enable ROSA Please note that **Only a single AWS account that will be used for service billing can be associated with a Red Hat account.** @@ -124,7 +122,7 @@ Create a file in your repository's `.github/workflows` directory, for example `d name: Deploy ROSA HCP Cluster on: - push: + pull_request: jobs: deploy: