github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/aws/diff_suppress_funcs.go (about) 1 package aws 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "log" 7 "strings" 8 9 "github.com/hashicorp/terraform/helper/schema" 10 "github.com/jen20/awspolicyequivalence" 11 ) 12 13 func suppressEquivalentAwsPolicyDiffs(k, old, new string, d *schema.ResourceData) bool { 14 equivalent, err := awspolicy.PoliciesAreEquivalent(old, new) 15 if err != nil { 16 return false 17 } 18 19 return equivalent 20 } 21 22 // Suppresses minor version changes to the db_instance engine_version attribute 23 func suppressAwsDbEngineVersionDiffs(k, old, new string, d *schema.ResourceData) bool { 24 // First check if the old/new values are nil. 25 // If both are nil, we have no state to compare the values with, so register a diff. 26 // This populates the attribute field during a plan/apply with fresh state, allowing 27 // the attribute to still be used in future resources. 28 // See https://github.com/hashicorp/terraform/issues/11881 29 if old == "" && new == "" { 30 return false 31 } 32 33 if v, ok := d.GetOk("auto_minor_version_upgrade"); ok { 34 if v.(bool) { 35 // If we're set to auto upgrade minor versions 36 // ignore a minor version diff between versions 37 if strings.HasPrefix(old, new) { 38 log.Printf("[DEBUG] Ignoring minor version diff") 39 return true 40 } 41 } 42 } 43 44 // Throw a diff by default 45 return false 46 } 47 48 func suppressEquivalentJsonDiffs(k, old, new string, d *schema.ResourceData) bool { 49 ob := bytes.NewBufferString("") 50 if err := json.Compact(ob, []byte(old)); err != nil { 51 return false 52 } 53 54 nb := bytes.NewBufferString("") 55 if err := json.Compact(nb, []byte(new)); err != nil { 56 return false 57 } 58 59 return jsonBytesEqual(ob.Bytes(), nb.Bytes()) 60 }