github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/digitalocean/loadbalancer.go (about) 1 package digitalocean 2 3 import ( 4 "fmt" 5 6 "github.com/digitalocean/godo" 7 "github.com/hashicorp/terraform/helper/resource" 8 ) 9 10 func loadbalancerStateRefreshFunc(client *godo.Client, loadbalancerId string) resource.StateRefreshFunc { 11 return func() (interface{}, string, error) { 12 lb, _, err := client.LoadBalancers.Get(loadbalancerId) 13 if err != nil { 14 return nil, "", fmt.Errorf("Error issuing read request in LoadbalancerStateRefreshFunc to DigitalOcean for Load Balancer '%s': %s", loadbalancerId, err) 15 } 16 17 return lb, lb.Status, nil 18 } 19 } 20 21 func expandStickySessions(config []interface{}) *godo.StickySessions { 22 stickysessionConfig := config[0].(map[string]interface{}) 23 24 stickySession := &godo.StickySessions{ 25 Type: stickysessionConfig["type"].(string), 26 } 27 28 if v, ok := stickysessionConfig["cookie_name"]; ok { 29 stickySession.CookieName = v.(string) 30 } 31 32 if v, ok := stickysessionConfig["cookie_ttl_seconds"]; ok { 33 stickySession.CookieTtlSeconds = v.(int) 34 } 35 36 return stickySession 37 } 38 39 func expandHealthCheck(config []interface{}) *godo.HealthCheck { 40 healthcheckConfig := config[0].(map[string]interface{}) 41 42 healthcheck := &godo.HealthCheck{ 43 Protocol: healthcheckConfig["protocol"].(string), 44 Port: healthcheckConfig["port"].(int), 45 CheckIntervalSeconds: healthcheckConfig["check_interval_seconds"].(int), 46 ResponseTimeoutSeconds: healthcheckConfig["response_timeout_seconds"].(int), 47 UnhealthyThreshold: healthcheckConfig["unhealthy_threshold"].(int), 48 HealthyThreshold: healthcheckConfig["healthy_threshold"].(int), 49 } 50 51 if v, ok := healthcheckConfig["path"]; ok { 52 healthcheck.Path = v.(string) 53 } 54 55 return healthcheck 56 } 57 58 func expandForwardingRules(config []interface{}) []godo.ForwardingRule { 59 forwardingRules := make([]godo.ForwardingRule, 0, len(config)) 60 61 for _, rawRule := range config { 62 rule := rawRule.(map[string]interface{}) 63 64 r := godo.ForwardingRule{ 65 EntryPort: rule["entry_port"].(int), 66 EntryProtocol: rule["entry_protocol"].(string), 67 TargetPort: rule["target_port"].(int), 68 TargetProtocol: rule["target_protocol"].(string), 69 TlsPassthrough: rule["tls_passthrough"].(bool), 70 } 71 72 if v, ok := rule["certificate_id"]; ok { 73 r.CertificateID = v.(string) 74 } 75 76 forwardingRules = append(forwardingRules, r) 77 78 } 79 80 return forwardingRules 81 } 82 83 func flattenDropletIds(list []int) []interface{} { 84 vs := make([]interface{}, 0, len(list)) 85 for _, v := range list { 86 vs = append(vs, v) 87 } 88 return vs 89 } 90 91 func flattenHealthChecks(health *godo.HealthCheck) []map[string]interface{} { 92 result := make([]map[string]interface{}, 0, 1) 93 94 if health != nil { 95 96 r := make(map[string]interface{}) 97 r["protocol"] = (*health).Protocol 98 r["port"] = (*health).Port 99 r["path"] = (*health).Path 100 r["check_interval_seconds"] = (*health).CheckIntervalSeconds 101 r["response_timeout_seconds"] = (*health).ResponseTimeoutSeconds 102 r["unhealthy_threshold"] = (*health).UnhealthyThreshold 103 r["healthy_threshold"] = (*health).HealthyThreshold 104 105 result = append(result, r) 106 } 107 108 return result 109 } 110 111 func flattenStickySessions(session *godo.StickySessions) []map[string]interface{} { 112 result := make([]map[string]interface{}, 0, 1) 113 114 if session != nil { 115 116 r := make(map[string]interface{}) 117 r["type"] = (*session).Type 118 r["cookie_name"] = (*session).CookieName 119 r["cookie_ttl_seconds"] = (*session).CookieTtlSeconds 120 121 result = append(result, r) 122 } 123 124 return result 125 } 126 127 func flattenForwardingRules(rules []godo.ForwardingRule) []map[string]interface{} { 128 result := make([]map[string]interface{}, 0, 1) 129 130 if rules != nil { 131 for _, rule := range rules { 132 r := make(map[string]interface{}) 133 r["entry_protocol"] = rule.EntryProtocol 134 r["entry_port"] = rule.EntryPort 135 r["target_protocol"] = rule.TargetProtocol 136 r["target_port"] = rule.TargetPort 137 r["certificate_id"] = rule.CertificateID 138 r["tls_passthrough"] = rule.TlsPassthrough 139 140 result = append(result, r) 141 } 142 } 143 144 return result 145 }