mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #19548 from hashicorp/b-helper-schema-NewComputed-propagation
helper/schema: Always propagate NewComputed for previously zero value primitive type attributes
This commit is contained in:
commit
a3b327dbac
@ -599,6 +599,37 @@ func testDiffCases(t *testing.T, oldPrefix string, oldOffset int, computed bool)
|
||||
},
|
||||
},
|
||||
},
|
||||
resourceDiffTestCase{
|
||||
Name: "NewComputed should always propagate",
|
||||
Schema: map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"foo": "",
|
||||
},
|
||||
ID: "pre-existing",
|
||||
},
|
||||
Config: testConfig(t, map[string]interface{}{}),
|
||||
Diff: &terraform.InstanceDiff{Attributes: map[string]*terraform.ResourceAttrDiff{}},
|
||||
Key: "foo",
|
||||
NewValue: "",
|
||||
Expected: &terraform.InstanceDiff{
|
||||
Attributes: func() map[string]*terraform.ResourceAttrDiff {
|
||||
if computed {
|
||||
return map[string]*terraform.ResourceAttrDiff{
|
||||
"foo": &terraform.ResourceAttrDiff{
|
||||
NewComputed: computed,
|
||||
},
|
||||
}
|
||||
}
|
||||
return map[string]*terraform.ResourceAttrDiff{}
|
||||
}(),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1185,7 +1185,7 @@ func (m schemaMap) diffString(
|
||||
return fmt.Errorf("%s: %s", k, err)
|
||||
}
|
||||
|
||||
if os == ns && !all {
|
||||
if os == ns && !all && !computed {
|
||||
// They're the same value. If there old value is not blank or we
|
||||
// have an ID, then return right away since we're already setup.
|
||||
if os != "" || d.Id() != "" {
|
||||
@ -1193,7 +1193,7 @@ func (m schemaMap) diffString(
|
||||
}
|
||||
|
||||
// Otherwise, only continue if we're computed
|
||||
if !schema.Computed && !computed {
|
||||
if !schema.Computed {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -3126,6 +3126,40 @@ func TestSchemaMap_Diff(t *testing.T) {
|
||||
Err: false,
|
||||
},
|
||||
|
||||
{
|
||||
Name: "NewComputed should always propagate with CustomizeDiff",
|
||||
Schema: map[string]*Schema{
|
||||
"foo": &Schema{
|
||||
Type: TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"foo": "",
|
||||
},
|
||||
ID: "pre-existing",
|
||||
},
|
||||
|
||||
Config: map[string]interface{}{},
|
||||
|
||||
CustomizeDiff: func(d *ResourceDiff, meta interface{}) error {
|
||||
d.SetNewComputed("foo")
|
||||
return nil
|
||||
},
|
||||
|
||||
Diff: &terraform.InstanceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||
"foo": &terraform.ResourceAttrDiff{
|
||||
NewComputed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Err: false,
|
||||
},
|
||||
|
||||
{
|
||||
Name: "vetoing a diff",
|
||||
Schema: map[string]*Schema{
|
||||
|
Loading…
Reference in New Issue
Block a user