Merge pull request #29849 from hashicorp/kmoe/ignore_changes-override

configs: fix ignore_changes config override bug
This commit is contained in:
kmoe 2021-11-01 19:54:04 +00:00 committed by GitHub
commit ba4b6652fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 1 deletions

View File

@ -17,7 +17,7 @@ import (
// diagnostics if any problems are found.
//
// This method is "optimistic" in that it will not return errors for possible
// problems that cannot be detected statically. It is possible that an
// problems that cannot be detected statically. It is possible that a
// traversal which passed static validation will still fail when evaluated.
func (b *Block) StaticValidateTraversal(traversal hcl.Traversal) tfdiags.Diagnostics {
if !traversal.IsRelative() {

View File

@ -242,6 +242,9 @@ func (r *Resource) merge(or *Resource, rps map[string]*RequiredProvider) hcl.Dia
if len(or.Managed.IgnoreChanges) != 0 {
r.Managed.IgnoreChanges = or.Managed.IgnoreChanges
}
if or.Managed.IgnoreAllChanges {
r.Managed.IgnoreAllChanges = true
}
if or.Managed.PreventDestroySet {
r.Managed.PreventDestroy = or.Managed.PreventDestroy
r.Managed.PreventDestroySet = or.Managed.PreventDestroySet

View File

@ -320,3 +320,13 @@ func TestModuleOverrideResourceFQNs(t *testing.T) {
t.Fatalf("wrong result: found provider config ref %s, expected nil", got.ProviderConfigRef)
}
}
func TestModuleOverrideIgnoreAllChanges(t *testing.T) {
mod, diags := testModuleFromDir("testdata/valid-modules/override-ignore-changes")
assertNoDiagnostics(t, diags)
r := mod.ManagedResources["test_instance.foo"]
if !r.Managed.IgnoreAllChanges {
t.Fatalf("wrong result: expected r.Managed.IgnoreAllChanges to be true")
}
}

View File

@ -0,0 +1,3 @@
resource "test_instance" "foo" {
foo = "bar"
}

View File

@ -0,0 +1,6 @@
resource "test_instance" "foo" {
foo = "bar"
lifecycle {
ignore_changes = all
}
}