Skip to content

Commit e649c08

Browse files
committed
Allow fetching module in GitHub workflow
* Adding a personal access token as repository secret * Fetch the module via https
1 parent aaf08e6 commit e649c08

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

.github/workflows/deploy-backup-infrastructure.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy Backup vault infrastructure
1+
name: Deploy backup vault infrastructure
22
run-name: Deploy backup vault infrastructure for ${{ inputs.environment }}
33

44
on:
@@ -46,8 +46,11 @@ jobs:
4646
terraform_version: 1.10.5
4747
- name: Terraform Plan
4848
id: plan
49+
env:
50+
PERSONAL_ACCESS_TOKEN: ${{ secrets.BACKUP_MODULES_ACCESS_TOKEN }}
4951
run: |
5052
set -e
53+
git config --global url."https://foo:${PERSONAL_ACCESS_TOKEN}@github.com/NHSDigital".insteadOf "https://github.com/NHSDigital"
5154
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
5255
terraform plan -var-file="env/${{ inputs.environment }}.tfvars" \
5356
-out ${{ runner.temp }}/tfplan | tee ${{ runner.temp }}/tf_stdout
@@ -86,7 +89,10 @@ jobs:
8689
with:
8790
terraform_version: 1.10.5
8891
- name: Apply the changes
92+
env:
93+
PERSONAL_ACCESS_TOKEN: ${{ secrets.BACKUP_MODULES_ACCESS_TOKEN }}
8994
run: |
9095
set -e
96+
git config --global url."https://foo:${PERSONAL_ACCESS_TOKEN}@github.com/NHSDigital".insteadOf "https://github.com/NHSDigital"
9197
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
9298
terraform apply ${{ runner.temp }}/tfplan

terraform/backup/README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ provided by NHSDigital in https://github.com/NHSDigital/terraform-aws-backup.
66
## Usage
77

88
The `source` directory contains the configuration to be applied in the main AWS account where the app is running.
9-
It is set up with the `terraform-backup-module.yml` GitHub Action workflow.
9+
It is set up with the `deploy-backup-infrastructure.yml` GitHub Action workflow.
1010

1111
The `destination` directory contains the configuration to be applied in a different AWS account that stores the backup of the backup.
1212
It will rarely change. In case of changes, terraform needs to be run manually.
@@ -18,8 +18,18 @@ To set up the backup infrastructure from scratch, follow these steps:
1818
It returns the ARN of the destination vault that is created.
1919
3. Put the ARN of the destination vault in the \*.tfvars file in the `source` directory.
2020
4. Create an AWS policy based on the `aws-backup-policy.json` file.
21-
This policy should be attached to the IAM role that is used by the `terraform-backup-module.yml` GitHub Action workflow.
22-
5. Set up the **source** account by running the `terraform-backup-module.yml` GitHub Action workflow.
21+
This policy should be attached to the IAM role that is used by the `deploy-backup-infrastructure.yml` GitHub Action workflow.
22+
5. Set up the **source** account by running the `deploy-backup-infrastructure.yml` GitHub Action workflow.
23+
24+
### Personal Access Token
25+
26+
The `deploy-backup-infrastructure.yml` GitHub Action workflow requires a personal access token to be set in the repository secrets to be able to fetch the terraform module.
27+
This token has a limited lifetime. If it has expired, create a new fine-grained personal access token as described in the [GitHub documentation](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token)
28+
and add it as repository secret.
29+
30+
- Resource Owner: NHS Digital
31+
- Repository access: terraform-aws-backup
32+
- Permissions: read-only Content
2333

2434
## Disaster Recovery
2535

terraform/backup/source/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ resource "aws_kms_key" "backup_notifications" {
116116
# Now we can deploy the source and destination modules, referencing the resources we've created above.
117117

118118
module "source" {
119-
source = "git@github.com:NHSDigital/terraform-aws-backup.git//modules/aws-backup-source?ref=v1.1.0"
119+
source = "github.com/NHSDigital/terraform-aws-backup.git//modules/aws-backup-source?ref=v1.1.0"
120120

121121
backup_copy_vault_account_id = local.destination_account_id
122122
backup_copy_vault_arn = var.destination_vault_arn

0 commit comments

Comments
 (0)