Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/workflows/base-deployment.yml
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
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
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 }}
Comment on lines +10 to +20

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions Job or Workflow does not set permissions

Copilot Autofix

AI 7 months ago

To fix the problem, add an explicit permissions block 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 the permissions block at the top-level of the workflow file to apply to all jobs, or within the specific sonarcloud job for a targeted approach. For simplicity and clarity, set it at the root of .github/workflows/build.yml (above jobs:), as it applies to all jobs unless overridden.

You only need to edit .github/workflows/build.yml: insert the following block after the workflow name::

permissions:
  contents: read
  pull-requests: write

This grants contents read access and pull request write access—which aligns with least privilege and the requirements for SonarCloud and GitHub PR integration.


Suggested changeset 1
.github/workflows/build.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -1,3 +1,6 @@
+permissions:
+  contents: read
+  pull-requests: write
 name: Build
 on:
   push:
EOF
@@ -1,3 +1,6 @@
permissions:
contents: read
pull-requests: write
name: Build
on:
push:
Copilot is powered by AI and may make mistakes. Always verify output.
21 changes: 21 additions & 0 deletions .github/workflows/ci-cd.yml
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
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ jobs:
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
Expand Down