mirror of https://github.com/hashicorp/terraform
parent
bfc107f90e
commit
a1939e70f7
@ -0,0 +1,17 @@
|
||||
resource "aws_instance" "web" {
|
||||
ami = "foo"
|
||||
lifecycle {
|
||||
ignore_changes = ["ami"]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
ami = "foo"
|
||||
lifecycle {
|
||||
ignore_changes = []
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_instance" "baz" {
|
||||
ami = "foo"
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package terraform
|
||||
import (
|
||||
"github.com/hashicorp/terraform/config"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// EvalIgnoreChanges is an EvalNode implementation that removes diff
|
||||
// attributes if their name matches names provided by the resource's
|
||||
// IgnoreChanges lifecycle.
|
||||
type EvalIgnoreChanges struct {
|
||||
Resource *config.Resource
|
||||
Diff **InstanceDiff
|
||||
}
|
||||
|
||||
func (n *EvalIgnoreChanges) Eval(ctx EvalContext) (interface{}, error) {
|
||||
if n.Diff == nil || *n.Diff == nil || n.Resource == nil || n.Resource.Id() == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
diff := *n.Diff
|
||||
ignoreChanges := n.Resource.Lifecycle.IgnoreChanges
|
||||
|
||||
for _, ignoredName := range ignoreChanges {
|
||||
for name := range diff.Attributes {
|
||||
if strings.HasPrefix(name, ignoredName) {
|
||||
delete(diff.Attributes, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
variable "foo" {}
|
||||
|
||||
resource "aws_instance" "foo" {
|
||||
ami = "${var.foo}"
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = ["ami"]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue