|
1 | | -# .github/workflows/terraform-dev |
2 | | -name: 'Deploy and Version Main to Pre-Prod' |
| 1 | +name: 'Deploy to Pre-Prod' |
3 | 2 |
|
4 | 3 | on: |
5 | 4 | workflow_dispatch: |
| 5 | + inputs: |
| 6 | + branch_or_tag: |
| 7 | + description: "What branch or tagged version do you want to deploy to pre-prod?" |
| 8 | + required: true |
| 9 | + type: "string" |
| 10 | + default: "main" |
6 | 11 |
|
7 | 12 | permissions: |
8 | 13 | pull-requests: write |
9 | 14 | id-token: write # This is required for requesting the JWT |
10 | 15 | contents: read # This is required for actions/checkout |
11 | 16 |
|
12 | 17 | jobs: |
13 | | - |
14 | 18 | tag_and_release: |
15 | 19 | runs-on: ubuntu-latest |
16 | 20 | outputs: |
17 | | - tag: ${{steps.versioning.outputs.tag}} |
18 | | - new_tag: ${{steps.versioning.outputs.new_tag}} |
| 21 | + tag: ${{ steps.version.outputs.tag || github.event.inputs.branch_or_tag }} |
19 | 22 | permissions: write-all |
20 | 23 |
|
21 | 24 | steps: |
22 | | - |
23 | | - - uses: actions/checkout@v4 |
| 25 | + - name: Checkout main |
| 26 | + if: ${{ github.event.inputs.branch_or_tag == 'main' }} |
| 27 | + uses: actions/checkout@v4 |
24 | 28 | with: |
25 | 29 | ref: main |
26 | 30 | fetch-depth: '0' |
27 | 31 |
|
28 | 32 | - name: Bump version and push tag |
29 | | - id: versioning |
| 33 | + id: version |
| 34 | + if: ${{ github.event.inputs.branch_or_tag == 'main' }} |
30 | 35 | uses: anothrNick/[email protected] |
31 | 36 | env: |
32 | 37 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
33 | 38 | WITH_V: false |
34 | 39 | DEFAULT_BUMP: patch |
35 | | - |
36 | | - - name: View outputs |
37 | | - run: | |
38 | | - echo Current tag: ${{steps.versioning.outputs.tag}} |
39 | | - echo New tag: ${{steps.versioning.outputs.new_tag}} |
40 | 40 |
|
41 | 41 | terraform_process: |
42 | 42 | runs-on: ubuntu-latest |
43 | 43 | needs: ['tag_and_release'] |
44 | 44 | environment: pre-prod |
| 45 | + |
45 | 46 | steps: |
46 | | - # Checkout the repository to the GitHub Actions runner |
| 47 | + - name: View outputs |
| 48 | + run: | |
| 49 | + echo Deploying branch or tagged version to pre-prod: ${{ needs.tag_and_release.outputs.tag }} |
| 50 | +
|
47 | 51 | - name: Checkout |
48 | 52 | uses: actions/checkout@v4 |
49 | 53 | with: |
|
57 | 61 | role-skip-session-tagging: true |
58 | 62 | aws-region: ${{ vars.AWS_REGION }} |
59 | 63 | mask-aws-account-id: true |
60 | | - |
61 | | - - name: View AWS Role |
62 | | - run: aws sts get-caller-identity |
63 | 64 |
|
64 | | - # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token |
65 | 65 | - name: Setup Terraform |
66 | 66 | uses: hashicorp/setup-terraform@v3 |
67 | 67 | with: |
|
79 | 79 | run: terraform workspace select ${{ secrets.AWS_WORKSPACE }} |
80 | 80 | working-directory: ./infrastructure |
81 | 81 | shell: bash |
82 | | - |
83 | | - # Checks that all Terraform configuration files adhere to a canonical format |
| 82 | + |
84 | 83 | - name: Terraform Format |
85 | 84 | run: terraform fmt -check |
86 | 85 | working-directory: ./infrastructure |
|
95 | 94 | - name: Terraform Apply |
96 | 95 | run: terraform apply -auto-approve -input=false tf.plan |
97 | 96 | working-directory: ./infrastructure |
98 | | - |
99 | | - |
0 commit comments