mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
terraform: refresh ignores variables with no values [GH-478]
This commit is contained in:
parent
c84af741de
commit
22f09b487b
@ -1611,19 +1611,25 @@ func (c *walkContext) computeResourceVariable(
|
||||
// Get the relevant module
|
||||
module := c.Context.state.ModuleByPath(c.Path)
|
||||
|
||||
r, ok := module.Resources[id]
|
||||
if !ok {
|
||||
if v.Multi && v.Index == 0 {
|
||||
var r *ResourceState
|
||||
if module != nil {
|
||||
var ok bool
|
||||
r, ok = module.Resources[id]
|
||||
if !ok && v.Multi && v.Index == 0 {
|
||||
r, ok = module.Resources[v.ResourceId()]
|
||||
}
|
||||
if !ok {
|
||||
return "", fmt.Errorf(
|
||||
"Resource '%s' not found for variable '%s'",
|
||||
id,
|
||||
v.FullKey())
|
||||
r = nil
|
||||
}
|
||||
}
|
||||
|
||||
if r == nil {
|
||||
return "", fmt.Errorf(
|
||||
"Resource '%s' not found for variable '%s'",
|
||||
id,
|
||||
v.FullKey())
|
||||
}
|
||||
|
||||
if r.Primary == nil {
|
||||
goto MISSING
|
||||
}
|
||||
|
@ -4110,6 +4110,22 @@ func TestContextRefresh_modules(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextRefresh_moduleInputComputedOutput(t *testing.T) {
|
||||
m := testModule(t, "refresh-module-input-computed-output")
|
||||
p := testProvider("aws")
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
if _, err := ctx.Refresh(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// GH-70
|
||||
func TestContextRefresh_noState(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
|
@ -0,0 +1,9 @@
|
||||
variable "input" {}
|
||||
|
||||
resource "aws_instance" "foo" {
|
||||
foo = "${var.input}"
|
||||
}
|
||||
|
||||
output "foo" {
|
||||
value = "${aws_instance.foo.foo}"
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
module "child" {
|
||||
input = "${aws_instance.bar.foo}"
|
||||
source = "./child"
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
compute = "foo"
|
||||
}
|
Loading…
Reference in New Issue
Block a user