github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/aws/diff_suppress_funcs.go (about)

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