2017-01-19 15:08:56 +01:00
|
|
|
package alicloud
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/denverdino/aliyungo/common"
|
2017-03-24 12:04:56 +01:00
|
|
|
"github.com/denverdino/aliyungo/ecs"
|
2017-01-19 15:08:56 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
type InstanceNetWork string
|
|
|
|
|
|
|
|
const (
|
|
|
|
ClassicNet = InstanceNetWork("classic")
|
|
|
|
VpcNet = InstanceNetWork("vpc")
|
|
|
|
)
|
|
|
|
|
2017-03-24 12:04:56 +01:00
|
|
|
// timeout for common product, ecs e.g.
|
2017-01-19 15:08:56 +01:00
|
|
|
const defaultTimeout = 120
|
|
|
|
|
2017-03-24 12:04:56 +01:00
|
|
|
// timeout for long time progerss product, rds e.g.
|
2017-04-18 14:18:57 +02:00
|
|
|
const defaultLongTimeout = 1000
|
2017-03-24 12:04:56 +01:00
|
|
|
|
2017-01-19 15:08:56 +01:00
|
|
|
func getRegion(d *schema.ResourceData, meta interface{}) common.Region {
|
|
|
|
return meta.(*AliyunClient).Region
|
|
|
|
}
|
|
|
|
|
|
|
|
func notFoundError(err error) bool {
|
2017-04-18 14:18:57 +02:00
|
|
|
if e, ok := err.(*common.Error); ok &&
|
|
|
|
(e.StatusCode == 404 || e.ErrorResponse.Message == "Not found" || e.Code == InstanceNotfound) {
|
2017-01-19 15:08:56 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-04-18 14:18:57 +02:00
|
|
|
// Protocol represents network protocol
|
|
|
|
type Protocol string
|
2017-01-19 15:08:56 +01:00
|
|
|
|
2017-04-18 14:18:57 +02:00
|
|
|
// Constants of protocol definition
|
2017-01-19 15:08:56 +01:00
|
|
|
const (
|
2017-04-18 14:18:57 +02:00
|
|
|
Http = Protocol("http")
|
|
|
|
Https = Protocol("https")
|
|
|
|
Tcp = Protocol("tcp")
|
|
|
|
Udp = Protocol("udp")
|
2017-01-19 15:08:56 +01:00
|
|
|
)
|
|
|
|
|
2017-04-18 14:18:57 +02:00
|
|
|
// ValidProtocols network protocol list
|
|
|
|
var ValidProtocols = []Protocol{Http, Https, Tcp, Udp}
|
2017-01-19 15:08:56 +01:00
|
|
|
|
|
|
|
// simple array value check method, support string type only
|
2017-04-18 14:18:57 +02:00
|
|
|
func isProtocolValid(value string) bool {
|
2017-01-19 15:08:56 +01:00
|
|
|
res := false
|
2017-04-18 14:18:57 +02:00
|
|
|
for _, v := range ValidProtocols {
|
2017-01-19 15:08:56 +01:00
|
|
|
if string(v) == value {
|
|
|
|
res = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
2017-03-24 12:04:56 +01:00
|
|
|
|
|
|
|
var DefaultBusinessInfo = ecs.BusinessInfo{
|
|
|
|
Pack: "terraform",
|
|
|
|
}
|
|
|
|
|
|
|
|
// default region for all resource
|
|
|
|
const DEFAULT_REGION = "cn-beijing"
|
|
|
|
|
|
|
|
// default security ip for db
|
|
|
|
const DEFAULT_DB_SECURITY_IP = "127.0.0.1"
|
|
|
|
|
|
|
|
// we the count of create instance is only one
|
|
|
|
const DEFAULT_INSTANCE_COUNT = 1
|
|
|
|
|
|
|
|
// symbol of multiIZ
|
|
|
|
const MULTI_IZ_SYMBOL = "MAZ"
|
|
|
|
|
|
|
|
// default connect port of db
|
|
|
|
const DB_DEFAULT_CONNECT_PORT = "3306"
|
|
|
|
|
|
|
|
const COMMA_SEPARATED = ","
|
|
|
|
|
2017-04-18 14:18:57 +02:00
|
|
|
const COLON_SEPARATED = ":"
|
|
|
|
|
2017-03-24 12:04:56 +01:00
|
|
|
const LOCAL_HOST_IP = "127.0.0.1"
|
2017-04-18 14:18:57 +02:00
|
|
|
|
|
|
|
// Takes the result of flatmap.Expand for an array of strings
|
|
|
|
// and returns a []string
|
|
|
|
func expandStringList(configured []interface{}) []string {
|
|
|
|
vs := make([]string, 0, len(configured))
|
|
|
|
for _, v := range configured {
|
|
|
|
vs = append(vs, v.(string))
|
|
|
|
}
|
|
|
|
return vs
|
|
|
|
}
|