Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: warn when .terraform.lock.hcl is modified during terraform init#18276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
blink-so wants to merge5 commits intomain
base:main
Choose a base branch
Loading
fromfix/terraform-lock-file-warning

Conversation

blink-so[bot]
Copy link
Contributor

@blink-soblink-sobot commentedJun 8, 2025

Fixes#18237

This PR adds checksum validation for.terraform.lock.hcl files before and after runningterraform init to detect when provider hashes are missing for the target architecture.

Problem

When users runterraform init locally on a different OS/architecture than their Coder instance, the generated.terraform.lock.hcl file may be missing provider hashes for the target architecture. This causes Terraform to download providers unnecessarily during provisioning, slowing down the process.

Solution

  • Calculate SHA256 checksum of.terraform.lock.hcl before runningterraform init
  • Calculate checksum again afterterraform init completes
  • If checksums differ, log a warning with actionable guidance
  • Warning appears in both debug and error streams for visibility

Changes

  • AddedcalculateFileChecksum() helper function using SHA256
  • AddedgetTerraformLockFilePath() helper function
  • Modifiedinit() function to perform checksum validation
  • Added comprehensive unit tests
  • Warning message guides users to regenerate lock file on correct architecture

Testing

  • Unit tests verify checksum calculation and file path functions
  • Code compiles successfully
  • Warning only appears when lock file is actually modified

The warning message provides clear guidance on how to resolve the issue by regenerating the lock file on the same OS/architecture as the Coder instance.

blink-sobotand others added5 commitsJune 8, 2025 02:20
This change addresses issue#18237 by adding checksum validation for.terraform.lock.hcl files before and after running terraform init.When the lock file is modified during init, it indicates that providerhashes may be missing for the target architecture, leading to unnecessaryprovider downloads and slower provisioning.Changes:- Add calculateFileChecksum() helper function using SHA256- Add getTerraformLockFilePath() helper function- Modify init() function to calculate checksums before/after terraform init- Log warning when lock file changes with actionable guidance- Add unit tests for new functionalityThe warning message guides users to regenerate the lock file on the sameOS/architecture as their Coder instance to improve performance.Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
Fixes gosec G306 linting error that expects WriteFile permissionsto be 0600 or less for security reasons.Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Warn if your .terraform.lock.hcl is modified after runningterraform init
0 participants

[8]ページ先頭

©2009-2025 Movatter.jp