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

     1  package alicloud
     2  
     3  import (
     4  	"github.com/denverdino/aliyungo/common"
     5  	"github.com/denverdino/aliyungo/ecs"
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  )
     8  
     9  type InstanceNetWork string
    10  
    11  const (
    12  	ClassicNet = InstanceNetWork("classic")
    13  	VpcNet     = InstanceNetWork("vpc")
    14  )
    15  
    16  // timeout for common product, ecs e.g.
    17  const defaultTimeout = 120
    18  
    19  // timeout for long time progerss product, rds e.g.
    20  const defaultLongTimeout = 1000
    21  
    22  func getRegion(d *schema.ResourceData, meta interface{}) common.Region {
    23  	return meta.(*AliyunClient).Region
    24  }
    25  
    26  func notFoundError(err error) bool {
    27  	if e, ok := err.(*common.Error); ok &&
    28  		(e.StatusCode == 404 || e.ErrorResponse.Message == "Not found" || e.Code == InstanceNotfound) {
    29  		return true
    30  	}
    31  
    32  	return false
    33  }
    34  
    35  // Protocol represents network protocol
    36  type Protocol string
    37  
    38  // Constants of protocol definition
    39  const (
    40  	Http  = Protocol("http")
    41  	Https = Protocol("https")
    42  	Tcp   = Protocol("tcp")
    43  	Udp   = Protocol("udp")
    44  )
    45  
    46  // ValidProtocols network protocol list
    47  var ValidProtocols = []Protocol{Http, Https, Tcp, Udp}
    48  
    49  // simple array value check method, support string type only
    50  func isProtocolValid(value string) bool {
    51  	res := false
    52  	for _, v := range ValidProtocols {
    53  		if string(v) == value {
    54  			res = true
    55  		}
    56  	}
    57  	return res
    58  }
    59  
    60  var DefaultBusinessInfo = ecs.BusinessInfo{
    61  	Pack: "terraform",
    62  }
    63  
    64  // default region for all resource
    65  const DEFAULT_REGION = "cn-beijing"
    66  
    67  // default security ip for db
    68  const DEFAULT_DB_SECURITY_IP = "127.0.0.1"
    69  
    70  // we the count of create instance is only one
    71  const DEFAULT_INSTANCE_COUNT = 1
    72  
    73  // symbol of multiIZ
    74  const MULTI_IZ_SYMBOL = "MAZ"
    75  
    76  // default connect port of db
    77  const DB_DEFAULT_CONNECT_PORT = "3306"
    78  
    79  const COMMA_SEPARATED = ","
    80  
    81  const COLON_SEPARATED = ":"
    82  
    83  const LOCAL_HOST_IP = "127.0.0.1"
    84  
    85  // Takes the result of flatmap.Expand for an array of strings
    86  // and returns a []string
    87  func expandStringList(configured []interface{}) []string {
    88  	vs := make([]string, 0, len(configured))
    89  	for _, v := range configured {
    90  		vs = append(vs, v.(string))
    91  	}
    92  	return vs
    93  }