This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
91 lines (78 loc) · 3.05 KB
/
aws-child-dns.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: "aws-10-administer-child-dns-zone"
on:
workflow_call:
inputs:
baseDomain:
description: "A domain under management by a Route53 hosted zone"
type: string
required: true
domainPrefix:
description: "The prefix to use as the subdomain for the child zone (e.g., participant-1)"
type: string
required: true
region:
description: "The AWS region where the Route53 Hosted Zone will be available"
type: string
required: true
action:
required: true
type: string
description: "Create (new) or destroy (existing)"
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
AWS_SESSION_TOKEN:
required: false
TF_BACKEND_S3_BUCKET_NAME:
required: true
AWS_KMS_ALIAS:
required: true
jobs:
terraform:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }}
AWS_REGION: ${{ inputs.region }}
TF_VAR_base_domain: ${{ inputs.baseDomain }}
TF_VAR_domain_prefix: "${{ inputs.domainPrefix }}"
runs-on: ubuntu-22.04
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-22.04, macos-latest, or windows-latest
defaults:
run:
shell: bash
working-directory: terraform/aws/child-dns
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v4
# Install the latest version of Terraform CLI
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
- name: Generate backend configuration
run: |
cp ../backend/backend.tf .
echo "bucket = \"${{ secrets.TF_BACKEND_S3_BUCKET_NAME }}\"" > config.aws.tfbackend
echo "key = \"dns/${{ inputs.domainPrefix }}.${{ inputs.baseDomain }}/terraform.tfstate\"" >> config.aws.tfbackend
echo "region = \"${{ env.AWS_REGION }}\"" >> config.aws.tfbackend
echo "encrypt = true" >> config.aws.tfbackend
echo "kms_key_id = \"${{ secrets.AWS_KMS_ALIAS }}\"" >> config.aws.tfbackend
echo "dynamodb_table = \"${{ secrets.TF_BACKEND_S3_BUCKET_NAME }}\"" >> config.aws.tfbackend
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
run: terraform init -upgrade -backend-config=./config.aws.tfbackend
# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
run: terraform fmt -check
# Generates an execution plan for Terraform
- name: Terraform Plan
if: inputs.action == 'create'
run: terraform plan
- name: Terraform Apply
if: inputs.action == 'create'
run: terraform apply -auto-approve
- name: Terraform Destroy
if: inputs.action == 'destroy'
run: terraform destroy -auto-approve