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