From 13b8c0140bf3d26a5ebd7ecb1deb97ca79c43105 Mon Sep 17 00:00:00 2001 From: Ben Larabie Date: Thu, 12 Sep 2024 09:35:35 -0400 Subject: [PATCH] Moving create vpn config to script --- .../workflows/helmfile_production_apply.yaml | 14 +------------- .github/workflows/helmfile_production_plan.yaml | 14 +------------- .github/workflows/helmfile_staging_apply.yaml | 13 +------------ .../helmfile_staging_apply_specific_app.yaml | 13 +------------ .github/workflows/helmfile_staging_plan.yaml | 13 +------------ .github/workflows/merge_to_main_production.yaml | 14 +------------- .github/workflows/merge_to_main_staging.yaml | 14 +------------- scripts/createVPNConfig.sh | 17 +++++++++++++++++ 8 files changed, 24 insertions(+), 88 deletions(-) create mode 100755 scripts/createVPNConfig.sh diff --git a/.github/workflows/helmfile_production_apply.yaml b/.github/workflows/helmfile_production_apply.yaml index b090f3d83..4eecbf2bc 100644 --- a/.github/workflows/helmfile_production_apply.yaml +++ b/.github/workflows/helmfile_production_apply.yaml @@ -58,19 +58,7 @@ jobs: - name: Retrieve VPN Config run: | - git clone https://github.com/cds-snc/notification-terraform.git /var/tmp/notification-terraform - cd /var/tmp/notification-terraform/env/production/eks - export INFRASTRUCTURE_VERSION=$(cat ../../../.github/workflows/infrastructure_version.txt) - ENDPOINT_ID=$(terragrunt output --raw gha_vpn_id) - CERT=$(terragrunt output --raw gha_vpn_certificate) - KEY=$(terragrunt output --raw gha_vpn_key) - aws ec2 export-client-vpn-client-configuration --client-vpn-endpoint-id $ENDPOINT_ID --output text > /var/tmp/production.ovpn - echo " - $CERT - " >> /var/tmp/production.ovpn - echo " - $KEY - " >> /var/tmp/production.ovpn + scripts/createVPNConfig.sh production 2> /dev/null - name: Connect to VPN uses: "kota65535/github-openvpn-connect-action@cd2ed8a90cc7b060dc4e001143e811b5f7ea0af5" # v3.1.0 diff --git a/.github/workflows/helmfile_production_plan.yaml b/.github/workflows/helmfile_production_plan.yaml index e4a4f1c0b..3c50b211b 100644 --- a/.github/workflows/helmfile_production_plan.yaml +++ b/.github/workflows/helmfile_production_plan.yaml @@ -59,19 +59,7 @@ jobs: - name: Retrieve VPN Config run: | - git clone https://github.com/cds-snc/notification-terraform.git /var/tmp/notification-terraform - cd /var/tmp/notification-terraform/env/production/eks - export INFRASTRUCTURE_VERSION=$(cat ../../../.github/workflows/infrastructure_version.txt) - ENDPOINT_ID=$(terragrunt output --raw gha_vpn_id) - CERT=$(terragrunt output --raw gha_vpn_certificate) - KEY=$(terragrunt output --raw gha_vpn_key) - aws ec2 export-client-vpn-client-configuration --client-vpn-endpoint-id $ENDPOINT_ID --output text > /var/tmp/production.ovpn - echo " - $CERT - " >> /var/tmp/production.ovpn - echo " - $KEY - " >> /var/tmp/production.ovpn + scripts/createVPNConfig.sh production 2> /dev/null - name: Connect to VPN uses: "kota65535/github-openvpn-connect-action@cd2ed8a90cc7b060dc4e001143e811b5f7ea0af5" # v3.1.0 diff --git a/.github/workflows/helmfile_staging_apply.yaml b/.github/workflows/helmfile_staging_apply.yaml index c02e5974b..3cc922e19 100644 --- a/.github/workflows/helmfile_staging_apply.yaml +++ b/.github/workflows/helmfile_staging_apply.yaml @@ -56,18 +56,7 @@ jobs: - name: Retrieve VPN Config run: | - git clone https://github.com/cds-snc/notification-terraform.git /var/tmp/notification-terraform - cd /var/tmp/notification-terraform/env/staging/eks - ENDPOINT_ID=$(terragrunt output --raw gha_vpn_id) - CERT=$(terragrunt output --raw gha_vpn_certificate) - KEY=$(terragrunt output --raw gha_vpn_key) - aws ec2 export-client-vpn-client-configuration --client-vpn-endpoint-id $ENDPOINT_ID --output text > /var/tmp/staging.ovpn - echo " - $CERT - " >> /var/tmp/staging.ovpn - echo " - $KEY - " >> /var/tmp/staging.ovpn + scripts/createVPNConfig.sh staging 2> /dev/null - name: Connect to VPN uses: "kota65535/github-openvpn-connect-action@cd2ed8a90cc7b060dc4e001143e811b5f7ea0af5" # v3.1.0 diff --git a/.github/workflows/helmfile_staging_apply_specific_app.yaml b/.github/workflows/helmfile_staging_apply_specific_app.yaml index 633c5220e..1c46b6743 100644 --- a/.github/workflows/helmfile_staging_apply_specific_app.yaml +++ b/.github/workflows/helmfile_staging_apply_specific_app.yaml @@ -74,18 +74,7 @@ jobs: - name: Retrieve VPN Config run: | - git clone https://github.com/cds-snc/notification-terraform.git /var/tmp/notification-terraform - cd /var/tmp/notification-terraform/env/staging/eks - ENDPOINT_ID=$(terragrunt output --raw gha_vpn_id) - CERT=$(terragrunt output --raw gha_vpn_certificate) - KEY=$(terragrunt output --raw gha_vpn_key) - aws ec2 export-client-vpn-client-configuration --client-vpn-endpoint-id $ENDPOINT_ID --output text > /var/tmp/staging.ovpn - echo " - $CERT - " >> /var/tmp/staging.ovpn - echo " - $KEY - " >> /var/tmp/staging.ovpn + scripts/createVPNConfig.sh staging 2> /dev/null - name: Connect to VPN uses: "kota65535/github-openvpn-connect-action@cd2ed8a90cc7b060dc4e001143e811b5f7ea0af5" # v3.1.0 diff --git a/.github/workflows/helmfile_staging_plan.yaml b/.github/workflows/helmfile_staging_plan.yaml index 18a7db916..d06e4e4d1 100644 --- a/.github/workflows/helmfile_staging_plan.yaml +++ b/.github/workflows/helmfile_staging_plan.yaml @@ -48,18 +48,7 @@ jobs: - name: Retrieve VPN Config run: | - git clone https://github.com/cds-snc/notification-terraform.git /var/tmp/notification-terraform - cd /var/tmp/notification-terraform/env/staging/eks - ENDPOINT_ID=$(terragrunt output --raw gha_vpn_id) - CERT=$(terragrunt output --raw gha_vpn_certificate) - KEY=$(terragrunt output --raw gha_vpn_key) - aws ec2 export-client-vpn-client-configuration --client-vpn-endpoint-id $ENDPOINT_ID --output text > /var/tmp/staging.ovpn - echo " - $CERT - " >> /var/tmp/staging.ovpn - echo " - $KEY - " >> /var/tmp/staging.ovpn + scripts/createVPNConfig.sh staging 2> /dev/null - name: Connect to VPN uses: "kota65535/github-openvpn-connect-action@cd2ed8a90cc7b060dc4e001143e811b5f7ea0af5" # v3.1.0 diff --git a/.github/workflows/merge_to_main_production.yaml b/.github/workflows/merge_to_main_production.yaml index f947f2fcd..947944b7b 100644 --- a/.github/workflows/merge_to_main_production.yaml +++ b/.github/workflows/merge_to_main_production.yaml @@ -63,19 +63,7 @@ jobs: - name: Retrieve VPN Config run: | - git clone https://github.com/cds-snc/notification-terraform.git /var/tmp/notification-terraform - cd /var/tmp/notification-terraform/env/production/eks - export INFRASTRUCTURE_VERSION=$(cat ../../../.github/workflows/infrastructure_version.txt) - ENDPOINT_ID=$(terragrunt output --raw gha_vpn_id) - CERT=$(terragrunt output --raw gha_vpn_certificate) - KEY=$(terragrunt output --raw gha_vpn_key) - aws ec2 export-client-vpn-client-configuration --client-vpn-endpoint-id $ENDPOINT_ID --output text > /var/tmp/production.ovpn - echo " - $CERT - " >> /var/tmp/production.ovpn - echo " - $KEY - " >> /var/tmp/production.ovpn + scripts/createVPNConfig.sh production 2> /dev/null - name: Connect to VPN uses: "kota65535/github-openvpn-connect-action@cd2ed8a90cc7b060dc4e001143e811b5f7ea0af5" # v3.1.0 diff --git a/.github/workflows/merge_to_main_staging.yaml b/.github/workflows/merge_to_main_staging.yaml index 0e01ccdd2..b8a0f26c8 100644 --- a/.github/workflows/merge_to_main_staging.yaml +++ b/.github/workflows/merge_to_main_staging.yaml @@ -56,19 +56,7 @@ jobs: - name: Retrieve VPN Config run: | - git clone https://github.com/cds-snc/notification-terraform.git /var/tmp/notification-terraform - cd /var/tmp/notification-terraform/env/staging/eks - ENDPOINT_ID=$(terragrunt output --raw gha_vpn_id) - CERT=$(terragrunt output --raw gha_vpn_certificate) - KEY=$(terragrunt output --raw gha_vpn_key) - aws ec2 export-client-vpn-client-configuration --client-vpn-endpoint-id $ENDPOINT_ID --output text > /var/tmp/staging.ovpn - echo " - $CERT - " >> /var/tmp/staging.ovpn - echo " - $KEY - " >> /var/tmp/staging.ovpn - + scripts/createVPNConfig.sh staging 2> /dev/null - name: Connect to VPN uses: "kota65535/github-openvpn-connect-action@cd2ed8a90cc7b060dc4e001143e811b5f7ea0af5" # v3.1.0 with: diff --git a/scripts/createVPNConfig.sh b/scripts/createVPNConfig.sh new file mode 100755 index 000000000..7ee7aaa7d --- /dev/null +++ b/scripts/createVPNConfig.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# This script will create a VPN configuration file for the specified environment +# Usage: ./createVPNConfig.sh +# Example: ./createVPNConfig.sh staging +ENVIRONMENT=$1 +git clone https://github.com/cds-snc/notification-terraform.git /var/tmp/notification-terraform +cd /var/tmp/notification-terraform/env/$ENVIRONMENT/eks +ENDPOINT_ID=$(terragrunt output --raw gha_vpn_id) +CERT=$(terragrunt output --raw gha_vpn_certificate) +KEY=$(terragrunt output --raw gha_vpn_key) +aws ec2 export-client-vpn-client-configuration --client-vpn-endpoint-id $ENDPOINT_ID --output text > /var/tmp/$ENVIRONMENT.ovpn +echo " +$CERT +" >> /var/tmp/$ENVIRONMENT.ovpn +echo " +$KEY +" >> /var/tmp/$ENVIRONMENT.ovpn \ No newline at end of file