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