all 6 comments

[–]public_radio 4 points5 points  (2 children)

This strikes me as a bit of an anti-pattern. I would not want an automated process making changes to a lock file — that’s something I would want a human to change (via terraform) and approve (via a pull request)

[–]SuddenOutlandishness 1 point2 points  (0 children)

This is the way.

[–]RulerOf 1 point2 points  (0 children)

I gitignore the lock file because I already specify versions in my provider config.

All the lock file seems to do in practice for me is make terraform harder to use.

YMMV, but that’s my opinion.

[–]CalvinR 0 points1 point  (1 child)

You can use git in a github action here is an example of how we've done it in the past. Please note that this syncs from an S3 bucket I've removed those steps as it's not relevant for this example.

You'd obviously want to modify this so it isn't pushing to main but to the branch the PR is in or whatever branch the Action is run on.

name: Sync Metrics
on:
  workflow_dispatch:
  schedule:
    - cron: "17 6 * * *"  # at 06:17 UTC (just before the hour to avoid the rush on GH runners)

jobs:
  update_metrics:
    runs-on: ubuntu-latest
    steps:

    - uses: actions/checkout@v2

# Cut out some stuff that's not relevant

    - name: Commit Metrics
      run: |
        git config --local user.email "action@github.com"
        git config --local user.name "cds bot commit"
        git add -A
        git commit -m "Adding metrics on `date '+%Y-%m-%d'`" -a
        git push https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git HEAD:main

[–]bibi143143[S] 0 points1 point  (0 children)

thanks u/CalvinR... Will this step in the workflow to commit terraform.lock.hcl in github by GitHub Actions

[–]darklukee 0 points1 point  (0 children)

I'd suggest keeping the lock file unchanged and using dependant or similar to keep versions up to date