github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/terraform/eval_ignore_changes.go (about)

     1  package terraform
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/hashicorp/terraform/config"
     7  )
     8  
     9  // EvalIgnoreChanges is an EvalNode implementation that removes diff
    10  // attributes if their name matches names provided by the resource's
    11  // IgnoreChanges lifecycle.
    12  type EvalIgnoreChanges struct {
    13  	Resource *config.Resource
    14  	Diff     **InstanceDiff
    15  }
    16  
    17  func (n *EvalIgnoreChanges) Eval(ctx EvalContext) (interface{}, error) {
    18  	if n.Diff == nil || *n.Diff == nil || n.Resource == nil || n.Resource.Id() == "" {
    19  		return nil, nil
    20  	}
    21  
    22  	diff := *n.Diff
    23  	ignoreChanges := n.Resource.Lifecycle.IgnoreChanges
    24  
    25  	for _, ignoredName := range ignoreChanges {
    26  		for name := range diff.Attributes {
    27  			if strings.HasPrefix(name, ignoredName) {
    28  				delete(diff.Attributes, name)
    29  			}
    30  		}
    31  	}
    32  
    33  	return nil, nil
    34  }