Backport/v1.8/1826 (#1829)

Signed-off-by: James Humphries <james@james-humphries.co.uk>
Co-authored-by: James Humphries <james@james-humphries.co.uk>
This commit is contained in:
Christian Mesh 2024-07-18 08:11:39 -04:00 committed by GitHub
parent f668c48ffd
commit 0b2384a3ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 129 additions and 97 deletions

View File

@ -280,7 +280,7 @@ func (b *Local) localRunForPlanFile(op *backend.Operation, pf *planfile.Reader,
return variable.Default, nil
}
parsed, parsedErr := v.Decode(variable.Type)
parsed, parsedErr := v.Decode(cty.DynamicPseudoType)
if parsedErr != nil {
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,

View File

@ -6,6 +6,7 @@
package e2etest
import (
"fmt"
"path/filepath"
"testing"
@ -15,7 +16,13 @@ import (
// This is an e2e test as it relies on very specific configuration
// within the meta object that is currently very hard to mock out.
func TestStaticPlanVariables(t *testing.T) {
fixturePath := filepath.Join("testdata", "static_plan_variables")
fixtures := []string{
"static_plan_variables",
"static_plan_typed_variables",
}
for _, fixture := range fixtures {
t.Run(fmt.Sprintf("TestStaticPlanVariables/%s", fixture), func(t *testing.T) {
fixturePath := filepath.Join("testdata", fixture)
tf := e2e.NewBinary(t, tofuBin, fixturePath)
run := func(args ...string) tofuResult {
@ -132,4 +139,6 @@ func TestStaticPlanVariables(t *testing.T) {
// Destroy
run("destroy", "-auto-approve").Failure().StderrContains(backendErr)
run("destroy", stateVar, modVar, "-auto-approve").Success().Contains("You can apply this plan to save these new output values")
})
}
}

View File

@ -0,0 +1,19 @@
variable "state_path" {}
variable "src" {
type = string
}
terraform {
backend "local" {
path = var.state_path
}
}
module "mod" {
source = var.src
}
output "out" {
value = module.mod.out
}

View File

@ -0,0 +1,3 @@
output "out" {
value = "placeholder"
}

View File

@ -13,6 +13,8 @@ import (
"strings"
"github.com/hashicorp/hcl/v2"
"github.com/zclconf/go-cty/cty"
"github.com/opentofu/opentofu/internal/backend"
"github.com/opentofu/opentofu/internal/cloud"
"github.com/opentofu/opentofu/internal/cloud/cloudplan"
@ -27,7 +29,6 @@ import (
"github.com/opentofu/opentofu/internal/tfdiags"
"github.com/opentofu/opentofu/internal/tofu"
"github.com/opentofu/opentofu/internal/tofumigrate"
"github.com/zclconf/go-cty/cty"
)
// Many of the methods we get data from can emit special error types if they're
@ -382,7 +383,7 @@ func getDataFromPlanfileReader(planReader *planfile.Reader, rootCall configs.Sta
return variable.Default, nil
}
parsed, parsedErr := v.Decode(variable.Type)
parsed, parsedErr := v.Decode(cty.DynamicPseudoType)
if parsedErr != nil {
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,