github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/states/statefile/write.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package statefile 5 6 import ( 7 "io" 8 9 tfversion "github.com/terramate-io/tf/version" 10 ) 11 12 // Write writes the given state to the given writer in the current state 13 // serialization format. 14 func Write(s *File, w io.Writer) error { 15 // Always record the current terraform version in the state. 16 s.TerraformVersion = tfversion.SemVer 17 18 diags := writeStateV4(s, w) 19 return diags.Err() 20 } 21 22 // WriteForTest writes the given state to the given writer in the current state 23 // serialization format without recording the current terraform version. This is 24 // intended for use in tests that need to override the current terraform 25 // version. 26 func WriteForTest(s *File, w io.Writer) error { 27 diags := writeStateV4(s, w) 28 return diags.Err() 29 }