github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/azurerm/location.go (about)

     1  package azurerm
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  )
     8  
     9  func locationSchema() *schema.Schema {
    10  	return &schema.Schema{
    11  		Type:             schema.TypeString,
    12  		Required:         true,
    13  		ForceNew:         true,
    14  		StateFunc:        azureRMNormalizeLocation,
    15  		DiffSuppressFunc: azureRMSuppressLocationDiff,
    16  	}
    17  }
    18  
    19  // azureRMNormalizeLocation is a function which normalises human-readable region/location
    20  // names (e.g. "West US") to the values used and returned by the Azure API (e.g. "westus").
    21  // In state we track the API internal version as it is easier to go from the human form
    22  // to the canonical form than the other way around.
    23  func azureRMNormalizeLocation(location interface{}) string {
    24  	input := location.(string)
    25  	return strings.Replace(strings.ToLower(input), " ", "", -1)
    26  }
    27  
    28  func azureRMSuppressLocationDiff(k, old, new string, d *schema.ResourceData) bool {
    29  	return azureRMNormalizeLocation(old) == azureRMNormalizeLocation(new)
    30  }