Skip to content

Commit

Permalink
apply suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
leiicamundi committed May 17, 2024
1 parent a321ac5 commit 7b68383
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 39 deletions.
22 changes: 13 additions & 9 deletions .github/actions/rosa-create-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
33 changes: 30 additions & 3 deletions .github/actions/rosa-create-cluster/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions .github/actions/rosa-delete-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
32 changes: 29 additions & 3 deletions .github/actions/rosa-delete-cluster/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
32 changes: 19 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.**

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7b68383

Please sign in to comment.