default optional+computed to prior value

This commit is contained in:
James Bardin 2022-09-20 10:59:15 -04:00
parent 673d6ca2bc
commit 3e281e1eda
3 changed files with 8 additions and 2 deletions

View File

@ -4543,6 +4543,11 @@ func TestContext2Plan_ignoreChangesWildcard(t *testing.T) {
t.Error("computed id set in plan config")
}
foo := req.Config.GetAttr("foo")
if foo.IsNull() {
t.Error(`missing "foo" during plan, was set to "bar" in state and config`)
}
return testDiffFn(req)
}
@ -4552,7 +4557,7 @@ func TestContext2Plan_ignoreChangesWildcard(t *testing.T) {
mustResourceInstanceAddr("aws_instance.foo").Resource,
&states.ResourceInstanceObjectSrc{
Status: states.ObjectReady,
AttrsJSON: []byte(`{"id":"bar","ami":"ami-abcd1234","instance":"t2.micro","type":"aws_instance"}`),
AttrsJSON: []byte(`{"id":"bar","ami":"ami-abcd1234","instance":"t2.micro","type":"aws_instance","foo":"bar"}`),
},
mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`),
)

View File

@ -1165,7 +1165,7 @@ func (n *NodeAbstractResource) processIgnoreChanges(prior, config cty.Value, sch
// to the provider as if they were included in the configuration.
ret, _ := cty.Transform(prior, func(path cty.Path, v cty.Value) (cty.Value, error) {
attr := schema.AttributeByPath(path)
if attr != nil && attr.Computed {
if attr != nil && attr.Computed && !attr.Optional {
return cty.NullVal(v.Type()), nil
}

View File

@ -5,6 +5,7 @@ variable "bar" {}
resource "aws_instance" "foo" {
ami = "${var.foo}"
instance = "${var.bar}"
foo = "bar"
lifecycle {
ignore_changes = all