github.com/cmalfait/terraform@v0.11.12-beta1/helper/customdiff/force_new.go (about) 1 package customdiff 2 3 import ( 4 "github.com/hashicorp/terraform/helper/schema" 5 ) 6 7 // ForceNewIf returns a CustomizeDiffFunc that flags the given key as 8 // requiring a new resource if the given condition function returns true. 9 // 10 // The return value of the condition function is ignored if the old and new 11 // values of the field compare equal, since no attribute diff is generated in 12 // that case. 13 func ForceNewIf(key string, f ResourceConditionFunc) schema.CustomizeDiffFunc { 14 return func(d *schema.ResourceDiff, meta interface{}) error { 15 if f(d, meta) { 16 d.ForceNew(key) 17 } 18 return nil 19 } 20 } 21 22 // ForceNewIfChange returns a CustomizeDiffFunc that flags the given key as 23 // requiring a new resource if the given condition function returns true. 24 // 25 // The return value of the condition function is ignored if the old and new 26 // values compare equal, since no attribute diff is generated in that case. 27 // 28 // This function is similar to ForceNewIf but provides the condition function 29 // only the old and new values of the given key, which leads to more compact 30 // and explicit code in the common case where the decision can be made with 31 // only the specific field value. 32 func ForceNewIfChange(key string, f ValueChangeConditionFunc) schema.CustomizeDiffFunc { 33 return func(d *schema.ResourceDiff, meta interface{}) error { 34 old, new := d.GetChange(key) 35 if f(old, new, meta) { 36 d.ForceNew(key) 37 } 38 return nil 39 } 40 }