From f3ef750f39b94e7aa73e116a140b3fd551c037d0 Mon Sep 17 00:00:00 2001 From: David Foster Date: Mon, 23 Sep 2024 16:56:40 -0700 Subject: [PATCH] Workflows for testing Terraform changes (#45) --- .github/workflows/change-test.yml | 70 ++++++++++++++++ .github/workflows/smoke-test.yml | 131 ++++++++++++++++++++++++++++++ .gitignore | 2 + 3 files changed, 203 insertions(+) create mode 100644 .github/workflows/change-test.yml create mode 100644 .github/workflows/smoke-test.yml diff --git a/.github/workflows/change-test.yml b/.github/workflows/change-test.yml new file mode 100644 index 0000000..a9cf1d1 --- /dev/null +++ b/.github/workflows/change-test.yml @@ -0,0 +1,70 @@ +name: Infrastructure Change Test +on: + pull_request: + branches: + - 'main' + paths: + - "infrastructure.tf" + - 'infrastructure/**' +jobs: + change-test: + runs-on: ubuntu-latest + name: Create and teardown cluster infrastructure + env: + OCI_CLI_USER: ${{ secrets.OCI_CLI_USER }} + OCI_CLI_TENANCY: ${{ secrets.OCI_CLI_TENANCY }} + OCI_CLI_FINGERPRINT: ${{ secrets.OCI_CLI_FINGERPRINT }} + OCI_CLI_KEY_CONTENT: ${{ secrets.OCI_CLI_KEY_CONTENT }} + OCI_CLI_REGION: ${{ secrets.OCI_CLI_REGION }} + OPENSHIFT_IMAGE_SOURCE_URI: ${{ secrets.OPENSHIFT_IMAGE_SOURCE_URI }} + COMPARTMENT_OCID: ${{ secrets.COMPARTMENT_OCID }} + ZONE_DNS_SUFFIX: ${{ secrets.ZONE_DNS_SUFFIX }} + CLUSTER_NAME: change-test + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set NOW env variable + run: echo "NOW=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV + + - name: Create Terraform ZIP + run: | + if [ -f infrastructure.tf ]; then + zip infrastructure.zip infrastructure.tf + elif [ -d infrastructure ]; then + zip -j infrastructure.zip infrastructure/data.tf infrastructure/locals.tf infrastructure/main.tf infrastructure/output.tf infrastructure/schema.yaml infrastructure/variables.tf + else + echo "Could not find infrastructure.tf or infrastructure directory" + exit 1 + fi + + - name: Create RMS Stack + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: create-stack + with: + command: 'resource-manager stack create --compartment-id ${{ env.COMPARTMENT_OCID }} --display-name ${{ github.job }}-${{ env.NOW }} --config-source infrastructure.zip --variables "{\"compartment_ocid\": \"${{ env.COMPARTMENT_OCID }}\", \"cluster_name\": \"${{ env.CLUSTER_NAME }}-${{ env.NOW }}\", \"openshift_image_source_uri\": \"${{ env.OPENSHIFT_IMAGE_SOURCE_URI }}\", \"region\": \"${{ env.OCI_CLI_REGION }}\", \"tenancy_ocid\": \"${{ env.OCI_CLI_TENANCY }}\", \"zone_dns\": \"${{ env.CLUSTER_NAME }}--${{ env.NOW }}${{ env.ZONE_DNS_SUFFIX }}\"}"' + query: 'data.id' + + - name: RMS Stack Plan Job + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: stack-plan-job + with: + command: 'resource-manager job create-plan-job --wait-for-state SUCCEEDED --stack-id ${{ steps.create-stack.outputs.raw_output }}' + + - name: RMS Stack Apply Job + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: stack-apply-job + with: + command: 'resource-manager job create-apply-job --wait-for-state SUCCEEDED --max-wait-seconds 2400 --execution-plan-strategy AUTO_APPROVED --stack-id ${{ steps.create-stack.outputs.raw_output }}' + + - name: RMS Stack Destroy Job + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: stack-destroy-job + with: + command: 'resource-manager job create-destroy-job --wait-for-state SUCCEEDED --max-wait-seconds 2400 --execution-plan-strategy AUTO_APPROVED --stack-id ${{ steps.create-stack.outputs.raw_output }}' + + - name: Destroy RMS Stack + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: destroy-stack + with: + command: 'resource-manager stack delete --force --stack-id ${{ steps.create-stack.outputs.raw_output }}' diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml new file mode 100644 index 0000000..9062dc9 --- /dev/null +++ b/.github/workflows/smoke-test.yml @@ -0,0 +1,131 @@ +name: Infrastructure Smoke Test +on: + schedule: + - cron: "20 5 */2 * *" +jobs: + smoke-test-bm-single-ad: + runs-on: ubuntu-latest + name: Create BM cluster infrastructure + env: + OCI_CLI_USER: ${{ secrets.OCI_CLI_USER }} + OCI_CLI_TENANCY: ${{ secrets.OCI_CLI_TENANCY }} + OCI_CLI_FINGERPRINT: ${{ secrets.OCI_CLI_FINGERPRINT }} + OCI_CLI_KEY_CONTENT: ${{ secrets.OCI_CLI_KEY_CONTENT }} + OCI_CLI_REGION: ${{ secrets.OCI_CLI_REGION }} + OPENSHIFT_IMAGE_SOURCE_URI: ${{ secrets.OPENSHIFT_IMAGE_SOURCE_URI }} + COMPARTMENT_OCID: ${{ secrets.COMPARTMENT_OCID }} + ZONE_DNS_SUFFIX: ${{ secrets.ZONE_DNS_SUFFIX }} + CLUSTER_NAME: smoke-test-bm + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set NOW env variable + run: echo "NOW=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV + + - name: Create Terraform ZIP + run: | + if [ -f infrastructure.tf ]; then + zip infrastructure.zip infrastructure.tf + elif [ -d infrastructure ]; then + zip -j infrastructure.zip infrastructure/data.tf infrastructure/locals.tf infrastructure/main.tf infrastructure/output.tf infrastructure/schema.yaml infrastructure/variables.tf + else + echo "Could not find infrastructure.tf or infrastructure directory" + exit 1 + fi + + - name: Create RMS Stack + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: create-stack + with: + command: 'resource-manager stack create --compartment-id ${{ env.COMPARTMENT_OCID }} --display-name ${{ github.job }}-${{ env.NOW }} --config-source infrastructure.zip --variables "{\"compartment_ocid\": \"${{ env.COMPARTMENT_OCID }}\", \"cluster_name\": \"${{ env.CLUSTER_NAME }}-${{ env.NOW }}\", \"control_plane_shape\": \"BM.Standard3.64\", \"control_plane_ocpu\": \"64\", \"control_plane_memory\": \"1024\", \"compute_shape\": \"BM.Standard3.64\", \"compute_ocpu\": \"64\", \"compute_memory\": \"1024\", \"openshift_image_source_uri\": \"${{ env.OPENSHIFT_IMAGE_SOURCE_URI }}\", \"region\": \"${{ env.OCI_CLI_REGION }}\", \"tenancy_ocid\": \"${{ env.OCI_CLI_TENANCY }}\", \"zone_dns\": \"${{ env.CLUSTER_NAME }}-${{ env.NOW }}${{ env.ZONE_DNS_SUFFIX }}\"}"' + query: 'data.id' + + - name: RMS Stack Plan Job + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: stack-plan-job + with: + command: 'resource-manager job create-plan-job --wait-for-state SUCCEEDED --stack-id ${{ steps.create-stack.outputs.raw_output }}' + + - name: RMS Stack Apply Job + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: stack-apply-job + with: + command: 'resource-manager job create-apply-job --wait-for-state SUCCEEDED --max-wait-seconds 2400 --execution-plan-strategy AUTO_APPROVED --stack-id ${{ steps.create-stack.outputs.raw_output }}' + + - name: Teardown BM Infrastructure + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: teardown-bm-infra + with: + command: 'resource-manager job create-destroy-job --wait-for-state SUCCEEDED --max-wait-seconds 2400 --execution-plan-strategy AUTO_APPROVED --stack-id ${{ steps.create-stack.outputs.raw_output }}' + + - name: Destroy RMS Stack + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: destroy-stack + with: + command: 'resource-manager stack delete --force --stack-id ${{ steps.create-stack.outputs.raw_output }}' + + + smoke-test-vm-multi-ad: + needs: [smoke-test-bm-single-ad] + runs-on: ubuntu-latest + name: Create VM cluster infrastructure in multi-ad region + env: + OCI_CLI_USER: ${{ secrets.OCI_CLI_USER }} + OCI_CLI_TENANCY: ${{ secrets.OCI_CLI_TENANCY }} + OCI_CLI_FINGERPRINT: ${{ secrets.OCI_CLI_FINGERPRINT }} + OCI_CLI_KEY_CONTENT: ${{ secrets.OCI_CLI_KEY_CONTENT }} + OCI_CLI_REGION: ${{ secrets.OCI_CLI_REGION }} + OPENSHIFT_IMAGE_SOURCE_URI: ${{ secrets.OPENSHIFT_IMAGE_SOURCE_URI }} + COMPARTMENT_OCID: ${{ secrets.COMPARTMENT_OCID }} + ZONE_DNS_SUFFIX: ${{ secrets.ZONE_DNS_SUFFIX }} + CLUSTER_NAME: smoke-test-vm-multi-ad + MUTLI_AD_REGION: eu-frankfurt-1 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set NOW env variable + run: echo "NOW=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV + + - name: Create Terraform ZIP + run: | + if [ -f infrastructure.tf ]; then + zip infrastructure.zip infrastructure.tf + elif [ -d infrastructure ]; then + zip -j infrastructure.zip infrastructure/data.tf infrastructure/locals.tf infrastructure/main.tf infrastructure/output.tf infrastructure/schema.yaml infrastructure/variables.tf + else + echo "Could not find infrastructure.tf or infrastructure directory" + exit 1 + fi + + - name: Create RMS Stack + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: create-stack + with: + command: 'resource-manager stack create --compartment-id ${{ env.COMPARTMENT_OCID }} --display-name ${{ github.job }}-${{ env.NOW }} --config-source infrastructure.zip --variables "{\"compartment_ocid\": \"${{ env.COMPARTMENT_OCID }}\", \"cluster_name\": \"${{ env.CLUSTER_NAME }}-${{ env.NOW }}\", \"openshift_image_source_uri\": \"${{ env.OPENSHIFT_IMAGE_SOURCE_URI }}\", \"region\": \"${{ env.MUTLI_AD_REGION }}\", \"tenancy_ocid\": \"${{ env.OCI_CLI_TENANCY }}\", \"zone_dns\": \"${{ env.CLUSTER_NAME }}-${{ env.NOW }}${{ env.ZONE_DNS_SUFFIX }}\"}"' + query: 'data.id' + + - name: RMS Stack Plan Job + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: stack-plan-job + with: + command: 'resource-manager job create-plan-job --wait-for-state SUCCEEDED --stack-id ${{ steps.create-stack.outputs.raw_output }}' + + - name: RMS Stack Apply Job + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: stack-apply-job + with: + command: 'resource-manager job create-apply-job --wait-for-state SUCCEEDED --max-wait-seconds 2400 --execution-plan-strategy AUTO_APPROVED --stack-id ${{ steps.create-stack.outputs.raw_output }}' + + - name: Teardown VM Multi AD Infrastructure + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: teardown-vm-multi-ad-infra + with: + command: 'resource-manager job create-destroy-job --wait-for-state SUCCEEDED --max-wait-seconds 2400 --execution-plan-strategy AUTO_APPROVED --stack-id ${{ steps.create-stack.outputs.raw_output }}' + + - name: Destroy RMS Stack + uses: oracle-actions/run-oci-cli-command@v1.3.2 + id: destroy-stack + with: + command: 'resource-manager stack delete --force --stack-id ${{ steps.create-stack.outputs.raw_output }}' \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4da6d0b..bc66ab6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .idea/ .DS_Store +.dev +.secrets ### Terraform ### # Local .terraform directories