|
| 1 | +name: Update Terraform |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + secrets: |
| 5 | + PERSONAL_ACCESS_TOKEN: |
| 6 | + required: true |
| 7 | + inputs: |
| 8 | + image_tag: |
| 9 | + description: Tag for the image for docker/ghcr registries |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + deployment_environment: |
| 13 | + description: The terraform target environment |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + default: staging |
| 17 | +jobs: |
| 18 | + update: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + env: |
| 21 | + GIT_SHA: ${{ github.sha }} |
| 22 | + GIT_TAG: ${{ inputs.image_tag }} |
| 23 | + steps: |
| 24 | + - name: Checkout terraform config repo |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + # public repo with terraform configuration |
| 28 | + repository: "datacite/mastino" |
| 29 | + persist-credentials: false |
| 30 | + - name: Setup dokerize and template parameters |
| 31 | + run: | |
| 32 | + git config --local user.email "action@github.com" |
| 33 | + git config --local user.name "GitHub Action" |
| 34 | + wget https://github.com/jwilder/dockerize/releases/download/v0.6.0/dockerize-linux-amd64-v0.6.0.tar.gz |
| 35 | + tar -xzvf dockerize-linux-amd64-v0.6.0.tar.gz |
| 36 | + rm dockerize-linux-amd64-v0.6.0.tar.gz |
| 37 | +
|
| 38 | + - name: Conditionally update staging environment |
| 39 | + if: ${{ (inputs.deployment_environment == 'staging') }} |
| 40 | + run: | |
| 41 | + ./dockerize -template stage/services/client-api/_events.auto.tfvars.tmpl:stage/services/client-api/_events.auto.tfvars |
| 42 | + git add stage/services/client-api/_events.auto.tfvars |
| 43 | + git commit -m "Adding events git variables for commit ${{ github.sha }}" |
| 44 | +
|
| 45 | + - name: Conditionally update production/test environments |
| 46 | + if: ${{ (inputs.deployment_environment == 'production') }} |
| 47 | + run: | |
| 48 | + ./dockerize -template prod-eu-west/services/client-api/_events.auto.tfvars.tmpl:prod-eu-west/services/client-api/_events.auto.tfvars |
| 49 | + ./dockerize -template test/services/client-api/_events.auto.tfvars.tmpl:test/services/client-api/_events.auto.tfvars |
| 50 | +
|
| 51 | + git add prod-eu-west/services/client-api/_events.auto.tfvars |
| 52 | + git add test/services/client-api/_events.auto.tfvars |
| 53 | + git commit -m "Adding events git variables for tag ${{ inputs.image_tag }}" |
| 54 | + - name: Push changes |
| 55 | + uses: ad-m/github-push-action@v0.8.0 |
| 56 | + with: |
| 57 | + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 58 | + repository: "datacite/mastino" |
| 59 | + branch: "refs/heads/master" |
| 60 | + tags: false |
0 commit comments