github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/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  func deprecatedLocationSchema() *schema.Schema {
    20  	return &schema.Schema{
    21  		Type:             schema.TypeString,
    22  		ForceNew:         true,
    23  		Optional:         true,
    24  		StateFunc:        azureRMNormalizeLocation,
    25  		DiffSuppressFunc: azureRMSuppressLocationDiff,
    26  		Deprecated:       "location is no longer used",
    27  	}
    28  }
    29  
    30  // azureRMNormalizeLocation is a function which normalises human-readable region/location
    31  // names (e.g. "West US") to the values used and returned by the Azure API (e.g. "westus").
    32  // In state we track the API internal version as it is easier to go from the human form
    33  // to the canonical form than the other way around.
    34  func azureRMNormalizeLocation(location interface{}) string {
    35  	input := location.(string)
    36  	return strings.Replace(strings.ToLower(input), " ", "", -1)
    37  }
    38  
    39  func azureRMSuppressLocationDiff(k, old, new string, d *schema.ResourceData) bool {
    40  	return azureRMNormalizeLocation(old) == azureRMNormalizeLocation(new)
    41  }