|
| 1 | +--- |
| 2 | +name: Deploy RDS Aurora Cluster |
| 3 | + |
| 4 | +description: | |
| 5 | + This GitHub Action automates the deployment of an RDS Aurora cluster using Terraform. |
| 6 | + This action will also install Terraform and awscli. It will output the Aurora cluster endpoint. |
| 7 | +
|
| 8 | +inputs: |
| 9 | + aws-region: |
| 10 | + description: AWS region where the cluster will be deployed |
| 11 | + required: true |
| 12 | + |
| 13 | + cluster-name: |
| 14 | + description: Name of the RDS Aurora cluster to deploy |
| 15 | + required: true |
| 16 | + |
| 17 | + username: |
| 18 | + description: Username for the PostgreSQL admin user |
| 19 | + required: true |
| 20 | + |
| 21 | + password: |
| 22 | + description: Password for the PostgreSQL admin user |
| 23 | + required: true |
| 24 | + |
| 25 | + vpc-id: |
| 26 | + description: VPC ID to create the cluster in |
| 27 | + required: true |
| 28 | + |
| 29 | + subnet-ids: |
| 30 | + description: List of subnet IDs to create the cluster in |
| 31 | + required: true |
| 32 | + |
| 33 | + cidr-blocks: |
| 34 | + description: CIDR blocks to allow access from and to |
| 35 | + required: true |
| 36 | + |
| 37 | + availability-zones: |
| 38 | + description: Array of availability zones to use for the Aurora cluster |
| 39 | + required: true |
| 40 | + |
| 41 | + additional-terraform-vars: |
| 42 | + description: JSON object containing additional Terraform variables |
| 43 | + required: false |
| 44 | + default: '{}' |
| 45 | + |
| 46 | + s3-backend-bucket: |
| 47 | + description: Name of the S3 bucket to store Terraform state |
| 48 | + required: true |
| 49 | + |
| 50 | + s3-bucket-region: |
| 51 | + description: Region of the bucket containing the resources states |
| 52 | + required: false |
| 53 | + |
| 54 | + s3-bucket-key-prefix: |
| 55 | + description: Key prefix of the bucket containing the resources states. It must contain a / at the end e.g 'my-prefix/'. |
| 56 | + default: '' |
| 57 | + |
| 58 | + tf-modules-revision: |
| 59 | + description: Git revision of the tf modules to use |
| 60 | + default: merge-branch |
| 61 | + |
| 62 | + tf-modules-path: |
| 63 | + description: Path where the tf Aurora modules will be cloned |
| 64 | + default: ./.action-tf-modules/aurora/ |
| 65 | + |
| 66 | + # inherited from https://github.com/hashicorp/setup-terraform/blob/main/action.yml |
| 67 | + tf-cli-config-credentials-hostname: |
| 68 | + description: | |
| 69 | + The hostname of a HCP Terraform/Terraform Enterprise instance to place within the credentials block |
| 70 | + of the Terraform CLI configuration file. Defaults to `app.terraform.io`. |
| 71 | + default: app.terraform.io |
| 72 | + |
| 73 | + tf-cli-config-credentials-token: |
| 74 | + description: | |
| 75 | + The API token for a HCP Terraform/Terraform Enterprise instance to place |
| 76 | + within the credentials block of the Terraform CLI configuration file. |
| 77 | + required: false |
| 78 | + |
| 79 | + tf-terraform-version: |
| 80 | + description: The version of Terraform CLI to install. Defaults to `latest`. |
| 81 | + default: latest |
| 82 | + |
| 83 | + tf-terraform-wrapper: |
| 84 | + description: | |
| 85 | + Whether or not to install a wrapper to wrap subsequent calls of the `terraform` binary |
| 86 | + and expose its STDOUT, STDERR, and exit code |
| 87 | + as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`. |
| 88 | + default: 'true' |
| 89 | + |
| 90 | + awscli-version: |
| 91 | + description: Version of the aws cli to use |
| 92 | + # renovate: datasource=github-releases depName=aws/aws-cli |
| 93 | + default: 2.15.52 |
| 94 | + |
| 95 | +outputs: |
| 96 | + aurora-endpoint: |
| 97 | + description: The endpoint of the deployed Aurora cluster |
| 98 | + value: ${{ steps.apply.outputs.aurora_endpoint }} |
| 99 | + |
| 100 | + terraform-state-url: |
| 101 | + description: URL of the Terraform state file in the S3 bucket |
| 102 | + value: ${{ steps.utility.outputs.terraform-state-url }} |
| 103 | + |
| 104 | + # Add all terraform outputs dynamically |
| 105 | + all-terraform-outputs: |
| 106 | + description: All outputs from Terraform |
| 107 | + value: ${{ steps.fetch_outputs.outputs.all_terraform_outputs }} |
| 108 | + |
| 109 | +runs: |
| 110 | + using: composite |
| 111 | + steps: |
| 112 | + - name: Use Utility Actions |
| 113 | + id: utility |
| 114 | + # see https://github.com/orgs/community/discussions/41927 it's not possible to optimize this yet |
| 115 | + # steps.uses cannot access the github context. |
| 116 | + uses: camunda/camunda-deployment-references/.github/actions/aws-utility-action@merge-branch |
| 117 | + with: |
| 118 | + awscli-version: ${{ inputs.awscli-version }} |
| 119 | + terraform-version: ${{ inputs.terraform-version }} |
| 120 | + |
| 121 | + aws-region: ${{ inputs.aws-region }} |
| 122 | + |
| 123 | + s3-backend-bucket: ${{ inputs.s3-backend-bucket }} |
| 124 | + s3-bucket-region: ${{ inputs.s3-bucket-region }} |
| 125 | + |
| 126 | + tf-state-key: ${{ inputs.s3-bucket-key-prefix }}tfstate-${{ inputs.cluster-name }}/${{ inputs.cluster-name }}.tfstate |
| 127 | + |
| 128 | + tf-cli-config-credentials-hostname: ${{ inputs.tf-cli-config-credentials-hostname }} |
| 129 | + tf-cli-config-credentials-token: ${{ inputs.tf-cli-config-credentials-token }} |
| 130 | + tf-terraform-wrapper: ${{ inputs.tf-terraform-wrapper }} |
| 131 | + |
| 132 | + - name: Checkout Repository Aurora modules |
| 133 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 134 | + with: |
| 135 | + repository: camunda/camunda-deployment-references |
| 136 | + ref: ${{ inputs.tf-modules-revision }} |
| 137 | + path: ${{ inputs.tf-modules-path }} |
| 138 | + fetch-depth: 0 |
| 139 | + |
| 140 | + - name: Terraform Init |
| 141 | + shell: bash |
| 142 | + id: init |
| 143 | + working-directory: ${{ inputs.tf-modules-path }}/aws/modules/aurora/ |
| 144 | + run: | |
| 145 | + set -euxo pipefail |
| 146 | +
|
| 147 | + cp ../fixtures/backend.tf ./ |
| 148 | + terraform version |
| 149 | + terraform init -backend-config="bucket=${{ steps.utility.outputs.TFSTATE_BUCKET }}" -backend-config="key=${{ steps.utility.outputs.TFSTATE_KEY }}" \ |
| 150 | + -backend-config="region=${{ steps.utility.outputs.TFSTATE_REGION }}" |
| 151 | + terraform validate -no-color |
| 152 | +
|
| 153 | + - name: Terraform Plan |
| 154 | + shell: bash |
| 155 | + id: plan |
| 156 | + working-directory: ${{ inputs.tf-modules-path }}/aws/modules/aurora/ |
| 157 | + run: | |
| 158 | + set -euxo pipefail |
| 159 | +
|
| 160 | + echo '${{ inputs.additional-terraform-vars }}' > /tmp/var.tfvars.json |
| 161 | + terraform plan -no-color -out aurora.plan \ |
| 162 | + -var-file=/tmp/var.tfvars.json \ |
| 163 | + -var "cluster_name=${{ inputs.cluster-name }}" \ |
| 164 | + -var "username=${{ inputs.username }}" \ |
| 165 | + -var "password=${{ inputs.password }}" \ |
| 166 | + -var 'availability_zones=${{ inputs.availability-zones }}' \ |
| 167 | + -var "vpc_id=${{ inputs.vpc-id }}" \ |
| 168 | + -var 'subnet_ids=${{ inputs.subnet-ids }}' \ |
| 169 | + -var 'cidr_blocks=${{ inputs.cidr-blocks }}' |
| 170 | +
|
| 171 | + - name: Terraform Apply |
| 172 | + shell: bash |
| 173 | + id: apply |
| 174 | + working-directory: ${{ inputs.tf-modules-path }}/aws/modules/aurora/ |
| 175 | + run: | |
| 176 | + set -euxo pipefail |
| 177 | +
|
| 178 | + terraform apply -no-color aurora.plan |
| 179 | + export aurora_endpoint="$(terraform output -raw aurora_endpoint)" |
| 180 | + echo "aurora_endpoint=$aurora_endpoint" >> "$GITHUB_OUTPUT" |
| 181 | +
|
| 182 | + - name: Fetch Terraform Outputs |
| 183 | + shell: bash |
| 184 | + id: fetch_outputs |
| 185 | + working-directory: ${{ inputs.tf-modules-path }}/aws/modules/aurora/ |
| 186 | + run: | |
| 187 | + set -euxo pipefail |
| 188 | +
|
| 189 | + all_outputs=$(terraform output -json | jq -c .) |
| 190 | + echo "all_terraform_outputs=$all_outputs" | tee -a "$GITHUB_OUTPUT" |
0 commit comments