Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

blink-so[bot]
Copy link
Contributor

@blink-so blink-so bot commented Jun 8, 2025

Fixes #18237

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

Problem

When users run terraform 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 running terraform init
  • Calculate checksum again after terraform init completes
  • If checksums differ, log a warning with actionable guidance
  • Warning appears in both debug and error streams for visibility

Changes

  • Added calculateFileChecksum() helper function using SHA256
  • Added getTerraformLockFilePath() helper function
  • Modified init() 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-so bot and others added 5 commits June 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 provider
hashes may be missing for the target architecture, leading to unnecessary
provider 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 functionality

The warning message guides users to regenerate the lock file on the same
OS/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 permissions
to be 0600 or less for security reasons.

Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn if your .terraform.lock.hcl is modified after running terraform init
0 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy