-
Notifications
You must be signed in to change notification settings - Fork 3
[PRM-481] Add deployment actions to prm-deductions-infra #145
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
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2f04997
Adds cicd and base deployment workflows
jack-nhs d1a642e
Restore build workflow
jack-nhs c5aaa41
Updated the base-deployment and its trigger to correctly apply on mer…
oliverbeumkes-nhs bd4fedc
Updated the pr and deploy scripts to include ehr-hard-deletion-lambda
oliverbeumkes-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,92 @@ | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| environment: | ||
| description: "Which Environment settings to use" | ||
| required: true | ||
| type: string | ||
| default: "dev" | ||
| is_deployment: | ||
| description: "Do you want to run Terraform Apply" | ||
| type: boolean | ||
| default: false | ||
|
|
||
| workflow_dispatch: | ||
| inputs: | ||
| environment: | ||
| description: "Which Environment settings to use" | ||
| required: true | ||
| type: choice | ||
| options: | ||
| - dev | ||
| - pre-prod | ||
| - prod | ||
| is_deployment: | ||
| description: "Do you want to run Terraform Apply" | ||
| type: boolean | ||
| default: false | ||
|
|
||
| name: Base Plan and Apply | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| plan: | ||
| name: ${{ inputs.environment }} - Plan and Apply | ||
| runs-on: ubuntu-latest | ||
| environment: ${{ inputs.environment }} | ||
| defaults: | ||
| run: | ||
| working-directory: ./terraform | ||
| steps: | ||
| - name: Set up git repo | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Terraform | ||
| uses: hashicorp/setup-terraform@v3 | ||
|
|
||
| - name: Configure AWS Credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| role-to-assume: ${{ secrets.IAM_ROLE }} | ||
| aws-region: eu-west-2 | ||
| mask-aws-account-id: true | ||
|
|
||
| - name: terraform init | ||
| id: init | ||
| run: terraform init -no-color -upgrade -backend-config="bucket=${{ secrets.TF_BACKEND_BUCKET }}" -backend-config="key=${{ secrets.TF_BACKEND_KEY }}" -backend-config="dynamodb_table=${{ secrets.TF_BACKEND_DYNAMODB_TABLE }}" | ||
|
|
||
| - name: terraform validate | ||
| id: validate | ||
| run: terraform validate -no-color | ||
|
|
||
| ## REPOSITORY SPECIFIC ## | ||
| - name: Setup Terraform variables | ||
| id: vars | ||
| run: | | ||
| COMMON_ACCOUNT_ID=$(aws ssm get-parameter --name /repo/ci/user-input/external/aws-account-id --with-decryption | jq -r .Parameter.Value) | ||
| cat > pipeline.auto.tfvars <<EOF | ||
| common_account_id=$COMMON_ACCOUNT_ID | ||
| common_account_role="CiReadOnly" | ||
| EOF | ||
|
|
||
| mkdir ../generate-cost-report-lambda/build | ||
| touch ../generate-cost-report-lambda/build/generate-cost-report-lambda.zip | ||
| mkdir ../notification-lambda/build | ||
| touch ../notification-lambda/build/alarm.zip | ||
| mkdir ../ehr-hard-deletion-lambda/build | ||
| touch ../ehr-hard-deletion-lambda/build/ehr-hard-deletion-lambda.zip | ||
|
|
||
| - name: terraform plan | ||
| id: plan | ||
| run: | | ||
| terraform plan -var-file="${{ inputs.environment }}.tfvars" -no-color -out=${{ inputs.environment }}.tfplan | ||
|
|
||
| - name: terraform apply | ||
| if: ${{ inputs.is_deployment }} | ||
| id: apply | ||
| run: | | ||
| terraform apply -auto-approve -input=false ${{ inputs.environment }}.tfplan | ||
| working-directory: ./terraform |
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,20 @@ | ||
| name: Build | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| jobs: | ||
| sonarcloud: | ||
| name: SonarCloud | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| with: | ||
| fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
| - name: SonarCloud Scan | ||
| uses: SonarSource/sonarqube-scan-action@v4 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | ||
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
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,21 @@ | ||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| paths: | ||
| - '**' | ||
|
|
||
|
|
||
| name: CI/CD | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
| id-token: write # This is required for requesting the JWT | ||
| contents: read # This is required for actions/checkout | ||
|
|
||
| jobs: | ||
| automated-dev-deployment: | ||
| uses: ./.github/workflows/base-deployment.yml | ||
| with: | ||
| environment: dev | ||
| is_deployment: ${{ github.ref == 'refs/heads/main' }} | ||
| secrets: inherit |
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.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 7 months ago
To fix the problem, add an explicit
permissionsblock specifying the minimum permissions necessary for the workflow to operate correctly. For a SonarCloud scan job, this generally means granting read access to contents and write access to pull requests (so that analysis results can be published as comments, if configured). Place thepermissionsblock at the top-level of the workflow file to apply to all jobs, or within the specificsonarcloudjob for a targeted approach. For simplicity and clarity, set it at the root of.github/workflows/build.yml(abovejobs:), as it applies to all jobs unless overridden.You only need to edit
.github/workflows/build.yml: insert the following block after the workflowname::This grants contents read access and pull request write access—which aligns with least privilege and the requirements for SonarCloud and GitHub PR integration.