-
Notifications
You must be signed in to change notification settings - Fork 4
NRL-1595 account wide infra deploy pipeline #1098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
c99e926
NRL-1595 Create workflow to deploy account-wide infrastructure
atrace 75991e2
NRL-1595 Make input variable description better & add versioning info…
anjalitrace2-nhs f09e1b2
Merge branch 'develop' of github.com:NHSDigital/NRLF into NRL-1595-ac…
anjalitrace2-nhs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| name: Deploy Account-wide infrastructure | ||
| run-name: Account-wide infra deployment to ${{ inputs.environment }} of ${{ inputs.branch_name }} by ${{ github.actor }} | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| environment: | ||
| description: "Account to deploy to" | ||
| required: true | ||
| default: "account-dev" | ||
| type: environment | ||
| branch_name: | ||
| description: Branch to deploy | ||
| required: true | ||
|
|
||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| actions: write | ||
|
|
||
| jobs: | ||
| check-selected-environment: | ||
| name: Check Workflow Env | ||
| runs-on: codebuild-nhsd-nrlf-ci-build-project-${{ github.run_id }}-${{ github.run_attempt }} | ||
| steps: | ||
| - name: Validate environment | ||
| env: | ||
| IS_VALID_ENV: ${{ startsWith(inputs.environment, 'account-') }} | ||
| run: | | ||
| echo "valid workflow environment selected:" $IS_VALID_ENV | ||
| if [[ $IS_VALID_ENV == true ]]; then | ||
| exit 0 | ||
| fi | ||
| echo "This workflow can only be run with 'account-*' environments as it deploys account-specific infrastructure" | ||
| exit 1 | ||
|
|
||
| terraform-plan: | ||
| name: Terraform Plan - ${{ inputs.environment }} | ||
| environment: ${{ inputs.environment }} | ||
| needs: [check-selected-environment] | ||
| runs-on: codebuild-nhsd-nrlf-ci-build-project-${{ github.run_id }}-${{ github.run_attempt }} | ||
|
|
||
| steps: | ||
| - name: Git clone - ${{ inputs.branch_name }} | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ inputs.branch_name }} | ||
|
|
||
| - name: Setup environment | ||
| run: | | ||
| echo "${HOME}/.asdf/bin" >> $GITHUB_PATH | ||
| poetry install --no-root | ||
|
|
||
| - name: Configure Management Credentials | ||
| uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a #v4.3.1 | ||
| with: | ||
| aws-region: eu-west-2 | ||
| role-to-assume: ${{ secrets.MGMT_ROLE_ARN }} | ||
| role-session-name: github-actions-ci-${{ inputs.environment }}-${{ github.run_id }} | ||
|
|
||
| - name: Retrieve Server Certificates | ||
| env: | ||
| ACCOUNT_NAME: ${{ vars.ACCOUNT_NAME }} | ||
| run: | | ||
| make truststore-pull-all-for-account ACCOUNT=${ACCOUNT_NAME} | ||
|
|
||
| - name: Terraform Init | ||
| env: | ||
| ACCOUNT_NAME: ${{ vars.ACCOUNT_NAME }} | ||
| run: | | ||
| terraform -chdir=terraform/account-wide-infrastructure/${ACCOUNT_NAME} init | ||
| terraform -chdir=terraform/account-wide-infrastructure/${ACCOUNT_NAME} workspace new ${ACCOUNT_NAME} || \ | ||
| terraform -chdir=terraform/account-wide-infrastructure/${ACCOUNT_NAME} workspace select ${ACCOUNT_NAME} | ||
|
|
||
| - name: Terraform Plan | ||
| env: | ||
| ACCOUNT_NAME: ${{ vars.ACCOUNT_NAME }} | ||
| ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | ||
| run: | | ||
| terraform -chdir=terraform/account-wide-infrastructure/${ACCOUNT_NAME} plan \ | ||
| -var assume_account=${ACCOUNT_ID} \ | ||
| -var assume_role=terraform \ | ||
| -out tfplan | ||
|
|
||
| - name: Save Terraform Plan | ||
| env: | ||
| ACCOUNT_NAME: ${{ vars.ACCOUNT_NAME }} | ||
| run: | | ||
| terraform -chdir=terraform/account-wide-infrastructure/${ACCOUNT_NAME} show -no-color tfplan > terraform/account-wide-infrastructure/$ACCOUNT_NAME/tfplan.txt | ||
|
|
||
| aws s3 cp terraform/account-wide-infrastructure/$ACCOUNT_NAME/tfplan s3://nhsd-nrlf--mgmt--github-ci-logging/acc-$ACCOUNT_NAME/${{ github.run_id }}/tfplan | ||
| aws s3 cp terraform/account-wide-infrastructure/$ACCOUNT_NAME/tfplan.txt s3://nhsd-nrlf--mgmt--github-ci-logging/acc-$ACCOUNT_NAME/${{ github.run_id }}/tfplan.txt | ||
|
|
||
| terraform-apply: | ||
| name: Terraform Apply - ${{ inputs.environment }} | ||
| needs: [terraform-plan] | ||
| runs-on: codebuild-nhsd-nrlf-ci-build-project-${{ github.run_id }}-${{ github.run_attempt }} | ||
| environment: ${{ inputs.environment }} | ||
|
|
||
| steps: | ||
| - name: Git clone - ${{ inputs.branch_name }} | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ inputs.branch_name }} | ||
|
|
||
| - name: Setup environment | ||
| run: | | ||
| echo "${HOME}/.asdf/bin" >> $GITHUB_PATH | ||
| poetry install --no-root | ||
|
|
||
| - name: Configure Management Credentials | ||
| uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a #v4.3.1 | ||
| with: | ||
| aws-region: eu-west-2 | ||
| role-to-assume: ${{ secrets.MGMT_ROLE_ARN }} | ||
| role-session-name: github-actions-ci-${{ inputs.environment }}-${{ github.run_id}} | ||
|
|
||
| - name: Download Terraform Plan artifact | ||
| env: | ||
| ACCOUNT_NAME: ${{ vars.ACCOUNT_NAME }} | ||
| run: aws s3 cp s3://nhsd-nrlf--mgmt--github-ci-logging/acc-$ACCOUNT_NAME/${{ github.run_id }}/tfplan terraform/account-wide-infrastructure/${ACCOUNT_NAME}/tfplan | ||
|
|
||
| - name: Retrieve Server Certificates | ||
| env: | ||
| ACCOUNT_NAME: ${{ vars.ACCOUNT_NAME }} | ||
| run: | | ||
| make truststore-pull-all-for-account ACCOUNT=${ACCOUNT_NAME} | ||
|
|
||
| - name: Terraform Init | ||
| env: | ||
| ACCOUNT_NAME: ${{ vars.ACCOUNT_NAME }} | ||
| run: | | ||
| terraform -chdir=terraform/account-wide-infrastructure/${ACCOUNT_NAME} init | ||
| terraform -chdir=terraform/account-wide-infrastructure/${ACCOUNT_NAME} workspace new ${ACCOUNT_NAME} || \ | ||
| terraform -chdir=terraform/account-wide-infrastructure/${ACCOUNT_NAME} workspace select ${ACCOUNT_NAME} | ||
|
|
||
| - name: Terraform Apply | ||
| env: | ||
| ACCOUNT_NAME: ${{ vars.ACCOUNT_NAME }} | ||
| ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | ||
| run: | | ||
| terraform -chdir=terraform/account-wide-infrastructure/${ACCOUNT_NAME} apply tfplan | ||
|
|
||
| - name: Update environment config version | ||
| env: | ||
| ACCOUNT_NAME: ${{ vars.ACCOUNT_NAME }} | ||
| run: | | ||
| deployed_version=$(terraform -chdir=terraform/account-wide-infrastructure/${ACCOUNT_NAME} output --raw version) | ||
| echo $deployed_version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/bin/bash | ||
| # Get the names of all environments in a provided NRL AWS account | ||
| set -o errexit -o nounset -o pipefail | ||
|
|
||
| if [[ $# -ne 1 ]]; then | ||
| echo "Usage: get-envs-for-account.sh <account>" | ||
| exit 1 | ||
| fi | ||
|
|
||
| account="$1" | ||
|
|
||
| case "${account}" in | ||
| dev) | ||
| envs_array=("dev" "dev-sandbox") | ||
| echo ${envs_array[@]} | ||
| ;; | ||
| test) | ||
| envs_array=("qa" "perftest" "ref" "int" "int-sandbox") # "qa-sandbox" currently broken | ||
| echo ${envs_array[@]} | ||
| ;; | ||
| prod) | ||
| envs_array=("prod") | ||
| echo ${envs_array[@]} | ||
| ;; | ||
| *) | ||
| echo "Unknown account ${account}" | ||
| exit 1 | ||
| esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.