-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from NHSDigital/AMB-0003-Terraform-check
AMB-0003-Terraform Check
- Loading branch information
Showing
7 changed files
with
113 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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,23 @@ | ||
name: Teardown | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
|
||
jobs: | ||
build: | ||
name: Call Azure Pipeline | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get Access Token | ||
id: get-access-token | ||
run: | | ||
echo "ACCESS_TOKEN"=$(curl 'https://app.vssps.visualstudio.com/oauth2/token' --data "client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_assertion=${{ secrets.PR_TEARDWN_CLIENT_SECRET }}&grant_type=refresh_token&assertion=${{ secrets.PR_TEARDWN_REFRESH_TOKEN }}&redirect_uri=https://localhost:1337/callback" | jq -r '.access_token') >> $GITHUB_OUTPUT | ||
- name: Azure Pipelines Action | ||
uses: Azure/pipelines@v1.2 | ||
with: | ||
azure-devops-project-url: 'https://dev.azure.com/NHSD-APIM/API%20Platform' | ||
azure-pipeline-name: 'immunisation-fhir-api-pr-teardown' | ||
azure-pipeline-variables: '{ "action_pr_number": "${{ github.event.pull_request.number }}" }' | ||
azure-devops-token: ${{ steps.get-access-token.outputs.ACCESS_TOKEN }} |
This file contains 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 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 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,53 @@ | ||
name: "$(SourceBranchName)+$(BuildID)" | ||
|
||
trigger: none | ||
pr: none | ||
|
||
resources: | ||
repositories: | ||
- repository: common | ||
type: github | ||
name: NHSDigital/api-management-utils | ||
ref: refs/heads/edge | ||
endpoint: NHSDigital | ||
|
||
variables: | ||
- template: project.yml | ||
|
||
jobs: | ||
- job: teardown | ||
displayName: PR Teardown | ||
timeoutInMinutes: 30 | ||
pool: | ||
name: 'AWS-ECS' | ||
vmImage: 'ubuntu-latest' | ||
steps: | ||
- checkout: self | ||
|
||
- bash: | | ||
echo $(action_pr_number) | ||
WORKSPACE="pr-"$(ACTION_PR_NUMBER) | ||
echo $WORKSPACE | ||
echo "##vso[task.setvariable variable=WORKSPACE]$WORKSPACE" | ||
echo "##vso[task.setvariable variable=ACTION_PR_NUMBER]$(ACTION_PR_NUMBER)" | ||
displayName: Set workspace tag | ||
- template: "azure/components/aws-assume-role.yml@common" | ||
parameters: | ||
role: "auto-ops" | ||
profile: "apim-dev" | ||
aws_account: "dev" | ||
|
||
- bash: | | ||
echo "##vso[task.setvariable variable=AWS_DEFAULT_REGION]eu-west-2" | ||
displayName: Set AWS default region | ||
- bash: | | ||
export AWS_PROFILE=apim-dev | ||
account_id="$(aws sts get-caller-identity --query Account --output text)" | ||
cd terraform | ||
terraform workspace select $(WORKSPACE) | ||
make init && make destroy aws_account_no=${account_id} environment=$(WORKSPACE) | ||
displayName: Destroy terraform PR workspace and linked resources | ||
retryCountOnTaskFailure: 2 |
This file contains 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 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 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,15 @@ | ||
locals { | ||
zone_subdomain = var.project_short_name | ||
} | ||
|
||
data "aws_route53_zone" "root_zone" { | ||
name = var.root_domain_name | ||
} | ||
|
||
locals { | ||
project_zone_name = "${local.zone_subdomain}.${data.aws_route53_zone.root_zone.name}" | ||
} | ||
|
||
data "aws_route53_zone" "project_zone" { | ||
name = local.project_zone_name | ||
} |