Fix test crash when using deprecated outputs in the root module (#3249)

Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
Christian Mesh
2025-09-05 14:41:32 -04:00
committed by GitHub
parent c94c96864c
commit fd4e426a12
5 changed files with 43 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ BUG FIXES:
* Ensure that generated mock values for testing correctly follows the provider schema. ([#3069](https://github.com/opentofu/opentofu/pull/3069))
* Remote provisioners now reject SSH certificates whose signature key is a certificate key, as required by the current SSH Certificate Format specification draft. ([#3180](https://github.com/opentofu/opentofu/pull/3180))
* `tofu import` command now correctly validates when the target address contains non-existent for_each key ([#3106](https://github.com/opentofu/opentofu/pull/3106))
* Fix crash in tofu test when using deprecated outputs ([#3249](https://github.com/opentofu/opentofu/pull/3249))
BREAKING CHANGES:
* In the `azurerm` backend, the following backend variables have been changed ([#3034](https://github.com/opentofu/opentofu/pull/3034)):

View File

@@ -1609,3 +1609,27 @@ func TestTest_MockProviderValidationForEach(t *testing.T) {
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
}
}
// See https://github.com/opentofu/opentofu/issues/3246
func TestTest_DeprecatedOutputs(t *testing.T) {
td := t.TempDir()
testCopyDir(t, testFixturePath("test/deprecated_outputs"), td)
t.Chdir(td)
view, done := testView(t)
ui := new(cli.MockUi)
meta := Meta{
Ui: ui,
View: view,
}
testCmd := &TestCommand{
Meta: meta,
}
code := testCmd.Run(nil)
output := done(t)
if code != 0 {
t.Fatalf("expected status code 0 but got %d: %s", code, output.All())
}
}

View File

@@ -0,0 +1,4 @@
output "example" {
value = "example"
deprecated = "for reasons"
}

View File

@@ -0,0 +1,8 @@
run "example" {
command = plan
assert {
condition = output.example == "example"
error_message = "ruh-roh"
}
}

View File

@@ -117,6 +117,12 @@ func Deprecated(v cty.Value, cause DeprecationCause) cty.Value {
// DeprecatedOutput marks a given values as deprecated constructing a DeprecationCause
// from module output specific data.
func DeprecatedOutput(v cty.Value, addr addrs.AbsOutputValue, msg string, isFromRemoteModule bool) cty.Value {
if addr.Module.IsRoot() {
// Marking a root output as deprecated has no impact.
// We hit this case when using the test framework on a module however.
// This is requried as the ModuleCallOutput() below will panic on the root module.
return v
}
_, callOutAddr := addr.ModuleCallOutput()
return Deprecated(v, DeprecationCause{
IsFromRemoteModule: isFromRemoteModule,