mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 08:51:02 -06:00
update ignore_changes to use cty.Path.Equals
Remove reflect.DeepEqual from path comparisons to get reliable results. The equality issues were only noticed going the grpc interface, so add a corresponding test to the test provider.
This commit is contained in:
parent
e4fbc49fb8
commit
a0338df4d4
@ -1086,3 +1086,86 @@ resource "test_resource" "foo" {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Verify we can use use numeric indices in `ignore_changes` paths.
|
||||
func TestResource_ignoreChangesIndex(t *testing.T) {
|
||||
resource.UnitTest(t, resource.TestCase{
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckResourceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: strings.TrimSpace(`
|
||||
resource "test_resource" "foo" {
|
||||
required = "yep"
|
||||
required_map = {
|
||||
key = "value"
|
||||
}
|
||||
list_of_map = [
|
||||
{
|
||||
a = "b"
|
||||
}
|
||||
]
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [list_of_map[0]["a"]]
|
||||
}
|
||||
}
|
||||
`),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(
|
||||
"test_resource.foo", "list_of_map.0.a", "b",
|
||||
),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: strings.TrimSpace(`
|
||||
resource "test_resource" "foo" {
|
||||
required = "yep"
|
||||
required_map = {
|
||||
key = "value"
|
||||
}
|
||||
list_of_map = [
|
||||
{
|
||||
a = "c"
|
||||
}
|
||||
]
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [list_of_map[0]["a"]]
|
||||
}
|
||||
}
|
||||
`),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(
|
||||
"test_resource.foo", "list_of_map.0.a", "b",
|
||||
),
|
||||
),
|
||||
},
|
||||
// set ignore_changes to a prefix of the changed value
|
||||
resource.TestStep{
|
||||
Config: strings.TrimSpace(`
|
||||
resource "test_resource" "foo" {
|
||||
required = "yep"
|
||||
required_map = {
|
||||
key = "value"
|
||||
}
|
||||
list_of_map = [
|
||||
{
|
||||
a = "d"
|
||||
}
|
||||
]
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [list_of_map[0]]
|
||||
}
|
||||
}
|
||||
`),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(
|
||||
"test_resource.foo", "list_of_map.0.a", "b",
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/hcl2/hcl"
|
||||
@ -532,7 +531,7 @@ func processIgnoreChangesIndividual(prior, proposed cty.Value, ignoreChanges []h
|
||||
// away any deeper values we already produced at that point.
|
||||
var ignoreTraversal hcl.Traversal
|
||||
for i, candidate := range ignoreChangesPath {
|
||||
if reflect.DeepEqual(path, candidate) {
|
||||
if path.Equals(candidate) {
|
||||
ignoreTraversal = ignoreChanges[i]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user