Have terraform own build - #45
Conversation
Terraform plan ·
|
Terraform plan ·
|
| concurrency: | ||
| group: tf-apply-${{ inputs.environment || github.ref_name }} | ||
| group: deploy-${{ inputs.environment || github.ref_name }} | ||
| cancel-in-progress: false |
There was a problem hiding this comment.
false is the default, so you could remove this entire concurrency block if you'd like
There was a problem hiding this comment.
it is correct that you don't ever want to cancel in progress for a workflow that includes terraform commands
| build: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| environment: ${{ inputs.environment || (github.ref_name == 'main' && 'production' || 'development') }} |
There was a problem hiding this comment.
I would suggest making environment a required input without a default - this prevents accidental deploys to the wrong place
| - name: Check out repository code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ inputs.commit_sha || '' }} |
There was a problem hiding this comment.
I'm not sure how this functions if you pass an empty string here, but it may be more explicit to pass the current ref (github.sha)
| id: build | ||
| run: | | ||
| set -euo pipefail | ||
| SHA="$(git rev-parse HEAD)" |
There was a problem hiding this comment.
this will always use the latest checked-out sha. not sure if that was your intention, given that the above allows commit_sha as an input
There was a problem hiding this comment.
goal is a default automated run just uses the latest (triggering) commit to dev/production, but if youre trying to run it manually like you showed me you can select a specific commit
There was a problem hiding this comment.
if that is the case this needs to be reworked - the sha used throughout the workflow should be the one set by the condition (use the input, or if none, use github.sha)
you can set it as a global var if that is easiest, example here https://github.com/arXiv/arxiv-qa/blob/12179214f91ded347e764c1267048f7976dfda23/.github/workflows/build-push.yml#L42
There was a problem hiding this comment.
to be clear - you should use the same sha for your build/image throughout. if you want the ability to use a different sha for terraform code (which is nice in the case of a rollback that changes the image but not the infra code) you might want to separate the build workflow from the deploy. or you can set two different shas and run the checkout step twice
| timeout-minutes: 30 | ||
|
|
||
| # develop applies development, main applies production. A manual run says which. | ||
| environment: ${{ inputs.environment || (github.ref_name == 'main' && 'production' || 'development') }} |
| set -o pipefail | ||
| terraform plan -lock=false -no-color -input=false \ | ||
| -var-file=envs/${{ matrix.environment }}.tfvars 2>&1 \ | ||
| -var-file=envs/${{ matrix.environment }}.tfvars \ |
There was a problem hiding this comment.
I was a little confused by this workflow. I would suggest planning develop from develop and then production on PR to your main/production branch, if only for the reason that planning from develop may be misleading - other changes may have been made on develop prior to a PR from develop to production (or, less likely, there may be changes on the main/production branch that are not on develop, as in a hotfix)
There was a problem hiding this comment.
the additional changes ahead of these is an interesting point! I added the production plan because i wanted a preview incase there's was a mistake before I got too far ahead, but if showing those bonus changes ends up being more trouble than its worth ill go down to one per PR
|
another suggestion as I'm circling back on these comments - |
| terraform_version: "1.13.5" | ||
| terraform_wrapper: false | ||
|
|
||
| - name: Cache providers |
There was a problem hiding this comment.
the .terraform.lock doesn't actually need to be committed in the repo (there may be some stray ones you've seen committed from early days terraforming things)
| echo "image=$REPO:$SHA" >> "$GITHUB_OUTPUT" | ||
| echo "Built $REPO:$SHA" | ||
|
|
||
| apply: |
There was a problem hiding this comment.
keeping these in the same workflow means you will have to rebuild the image (albeit cached) each time. for now I think this is fine though
carly-jones
left a comment
There was a problem hiding this comment.
a couple more comments, but I think this looks good
remove old cloudbuild trigger, terraform now builds image and deploys it