@@ -15,6 +15,7 @@ import (
1515"sync"
1616"time"
1717
18+ "github.com/google/go-cmp/cmp"
1819"github.com/hashicorp/go-version"
1920tfjson"github.com/hashicorp/terraform-json"
2021"go.opentelemetry.io/otel/attribute"
@@ -249,21 +250,22 @@ func (e *executor) init(ctx, killCtx context.Context, logr logSink) error {
249250
250251// Check if .terraform.lock.hcl was modified after terraform init
251252postInitLockFileContent ,_ := os .ReadFile (lockFilePath )
252- diff := generateFileDiff (preInitLockFileContent ,postInitLockFileContent )
253- if diff != "" {
254- // Log informational message about lock file changes with diff
255- infoMsg := "INFO: .terraform.lock.hcl was modified during 'terraform init'. " +
256- "This is normal when Terraform downloads providers or updates dependencies. " +
253+ if ! bytes .Equal (preInitLockFileContent ,postInitLockFileContent ) {
254+ diff := cmp .Diff (string (preInitLockFileContent ),string (postInitLockFileContent ))
255+ // Log warning message about lock file changes with diff
256+ warnMsg := "WARN: .terraform.lock.hcl was modified during 'terraform init'. " +
257+ "This may indicate that provider hashes are missing for your target architecture, " +
258+ "which can cause unnecessary provider downloads and slower workspace builds. " +
257259"See https://developer.hashicorp.com/terraform/language/files/dependency-lock#understanding-lock-file-changes " +
258260"for more information about lock file changes."
259261
260- // Writeinfo message todebug stream
261- if outWriter != nil {
262- _ ,_ = outWriter .Write ([]byte (infoMsg + "\n " ))
263- _ ,_ = outWriter .Write ([]byte ("\n Lock file changes:\n " + diff + "\n " ))
262+ // Writewarning message toerror stream for visibility
263+ if errWriter != nil {
264+ _ ,_ = errWriter .Write ([]byte (warnMsg + "\n " ))
265+ _ ,_ = errWriter .Write ([]byte ("\n Lock file changes:\n " + diff + "\n " ))
264266}
265267
266- e .logger .Info (ctx ,"terraform lock file modified during init" ,
268+ e .logger .Warn (ctx ,"terraform lock file modified during init" ,
267269slog .F ("lock_file_path" ,lockFilePath ),
268270slog .F ("diff" ,diff ),
269271)
@@ -290,48 +292,7 @@ func getTerraformLockFilePath(workdir string) string {
290292return filepath .Join (workdir ,".terraform.lock.hcl" )
291293}
292294
293- // generateFileDiff generates a simple diff between two file contents.
294- // Returns empty string if files are identical.
295- func generateFileDiff (beforeContent ,afterContent []byte )string {
296- if bytes .Equal (beforeContent ,afterContent ) {
297- return ""
298- }
299-
300- // Simple line-by-line diff
301- beforeLines := strings .Split (string (beforeContent ),"\n " )
302- afterLines := strings .Split (string (afterContent ),"\n " )
303-
304- var diff strings.Builder
305- diff .WriteString ("--- .terraform.lock.hcl (before terraform init)\n " )
306- diff .WriteString ("+++ .terraform.lock.hcl (after terraform init)\n " )
307-
308- // Simple diff showing added/removed lines
309- beforeMap := make (map [string ]bool )
310- for _ ,line := range beforeLines {
311- beforeMap [line ]= true
312- }
313-
314- afterMap := make (map [string ]bool )
315- for _ ,line := range afterLines {
316- afterMap [line ]= true
317- }
318295
319- // Show removed lines
320- for _ ,line := range beforeLines {
321- if ! afterMap [line ]&& strings .TrimSpace (line )!= "" {
322- diff .WriteString ("- " + line + "\n " )
323- }
324- }
325-
326- // Show added lines
327- for _ ,line := range afterLines {
328- if ! beforeMap [line ]&& strings .TrimSpace (line )!= "" {
329- diff .WriteString ("+ " + line + "\n " )
330- }
331- }
332-
333- return diff .String ()
334- }
335296
336297// revive:disable-next-line:flag-parameter
337298func (e * executor )plan (ctx ,killCtx context.Context ,env ,vars []string ,logr logSink ,metadata * proto.Metadata ) (* proto.PlanComplete ,error ) {