Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bundle/deploy/terraform/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (m *importResource) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn
if err != nil {
return diag.Errorf("terraform init: %v", err)
}
defer os.RemoveAll(tmpDir)
relPath, _ := b.StateFilenameTerraform(ctx)
tmpState := filepath.Join(tmpDir, filepath.Base(relPath))

Expand All @@ -62,8 +63,6 @@ func (m *importResource) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn
return diag.Errorf("terraform plan: %v", err)
}

defer os.RemoveAll(tmpDir)

if changed && !m.opts.AutoApprove {
output := buf.String()
// Remove output starting from Warning until end of output, if present.
Expand Down Expand Up @@ -103,6 +102,12 @@ func (m *importResource) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn
return diag.FromErr(err)
}

// A failed Close can mean a truncated state file; the deferred Close above covers error paths.
err = f.Close()
if err != nil {
return diag.FromErr(err)
}

return diags
}

Expand Down
Loading