Skip to content

Commit 4556cfa

Browse files
bartoszjkevholditch
authored andcommitted
Kong pre 1.0.0 - Upstreams & Targets (#68)
* Updated Upstream * Add support for targets (#61) * Upstream Added additional "standard" documentation regarding upstreams * Add support for targets Revert "Add support for targets" This reverts commit c518fd9. Add support for targets * Update README.md Co-Authored-By: onematchfox <brianhfox@gmail.com> * Upstream Added additional "standard" documentation regarding upstreams * Add support for targets Revert "Add support for targets" This reverts commit c518fd9. Add support for targets * Update README.md Co-Authored-By: onematchfox <brianhfox@gmail.com> * Formatting alignment Ugh... Tabs vs spaces
1 parent 20e9fa7 commit 4556cfa

14 files changed

+2309
-15
lines changed

README.md

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,70 @@ terraform import kong_sni.<sni_identifier> <sni_id>
274274
## Upstreams
275275
```hcl
276276
resource "kong_upstream" "upstream" {
277-
name = "sample_upstream"
278-
slots = 10
277+
name = "sample_upstream"
278+
slots = 10
279+
hash_on = "header"
280+
hash_fallback = "consumer"
281+
hash_on_header = "HeaderName"
282+
hash_fallback_header = "FallbackHeaderName"
283+
healthchecks = {
284+
active = {
285+
http_path = "/status"
286+
timeout = 10
287+
concurrency = 20
288+
healthy = {
289+
successes = 1
290+
interval = 5
291+
http_statuses = [200, 201]
292+
}
293+
unhealthy = {
294+
timeouts = 7
295+
interval = 3
296+
tcp_failures = 1
297+
http_failures = 2
298+
http_statuses = [500, 501]
299+
}
300+
}
301+
passive = {
302+
healthy = {
303+
successes = 1
304+
http_statuses = [200, 201, 202]
305+
}
306+
unhealthy = {
307+
timeouts = 3
308+
tcp_failures = 5
309+
http_failures = 6
310+
http_statuses = [500, 501, 502]
311+
}
312+
}
313+
}
279314
}
280315
```
281316

317+
* `name` is a hostname like name that can be referenced in the upstream_url field of a service.
318+
* `slots` is the number of slots in the load balancer algorithm (10-65536, defaults to 10000).
319+
* `hash_on` is a hashing input type: `none `(resulting in a weighted-round-robin scheme with no hashing), `consumer`, `ip`, `header`, or `cookie`. Defaults to `none`.
320+
* `hash_fallback` is a hashing input type if the primary `hash_on` does not return a hash (eg. header is missing, or no consumer identified). One of: `none`, `consumer`, `ip`, `header`, or `cookie`. Not available if `hash_on` is set to `cookie`. Defaults to `none`.
321+
* `hash_on_header` is a header name to take the value from as hash input. Only required when `hash_on` is set to `header`. Default `nil`.
322+
* `hash_fallback_header` is a header name to take the value from as hash input. Only required when `hash_fallback` is set to `header`. Default `nil`.
323+
* `healthchecks.active.timeout` is a socket timeout for active health checks (in seconds). Defaults to `1`.
324+
* `healthchecks.active.concurrency` is a number of targets to check concurrently in active health checks. Defaults to `10`.
325+
* `healthchecks.active.http_path` is a path to use in GET HTTP request to run as a probe on active health checks. Defaults to `/`.
326+
* `healthchecks.active.healthy.interval` is an interval between active health checks for healthy targets (in seconds). A value of zero indicates that active probes for healthy targets should not be performed. Defaults to `0`.
327+
* `healthchecks.active.healthy.successes` is a number of successes in active probes (as defined by `healthchecks.active.healthy.http_statuses`) to consider a target healthy. Defaults to `0`.
328+
* `healthchecks.active.healthy.http_statuses` is an array of HTTP statuses to consider a success, indicating healthiness, when returned by a probe in active health checks. Defaults to `[200, 302]`.
329+
* `healthchecks.active.unhealthy.interval` is an interval between active health checks for unhealthy targets (in seconds). A value of zero indicates that active probes for unhealthy targets should not be performed. Defaults to `0`.
330+
* `healthchecks.active.unhealthy.tcp_failures` is a number of TCP failures in active probes to consider a target unhealthy. Defaults to `0`.
331+
* `healthchecks.active.unhealthy.http_failures` is a number of HTTP failures in active probes (as defined by `healthchecks.active.unhealthy.http_statuses`) to consider a target unhealthy. Defaults to `0`.
332+
* `healthchecks.active.unhealthy.timeouts` is a number of timeouts in active probes to consider a target unhealthy. Defaults to `0`.
333+
* `healthchecks.active.unhealthy.http_statuses` is an array of HTTP statuses to consider a failure, indicating unhealthiness, when returned by a probe in active health checks. Defaults to `[429, 404, 500, 501, 502, 503, 504, 505]`.
334+
* `healthchecks.passive.healthy.successes` is a Number of successes in proxied traffic (as defined by `healthchecks.passive.healthy.http_statuses`) to consider a target healthy, as observed by passive health checks. Defaults to `0`.
335+
* `healthchecks.passive.healthy.http_statuses` is an array of HTTP statuses which represent healthiness when produced by proxied traffic, as observed by passive health checks. Defaults to `[200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308]`.
336+
* `healthchecks.passive.unhealthy.tcp_failures` is a number of TCP failures in proxied traffic to consider a target unhealthy, as observed by passive health checks. Defaults to `0`.
337+
* `healthchecks.passive.unhealthy.http_failures` is a number of HTTP failures in proxied traffic (as defined by `healthchecks.passive.unhealthy.http_statuses`) to consider a target unhealthy, as observed by passive health checks. Defaults to `0`.
338+
* `healthchecks.passive.unhealthy.timeouts` is a number of timeouts in proxied traffic to consider a target unhealthy, as observed by passive health checks. Defaults to `0`.
339+
* `healthchecks.passive.unhealthy.http_statuses` is an array of HTTP statuses which represent unhealthiness when produced by proxied traffic, as observed by passive health checks. Defaults to `[429, 500, 503]`.
340+
282341

283342
# Data Sources
284343
## APIs
@@ -376,10 +435,53 @@ data "kong_upstream" "upstream_data_source" {
376435
Each of the filter parameters are optional and they are combined for an AND search against all upstreams. The following output parameters are returned:
377436

378437
* `id` - the Kong id of the found upstream
379-
* `name` - the name of the found upstream
380-
* `slots` - the number of slots on the found upstream
438+
* `name` is a hostname like name that can be referenced in the upstream_url field of a service.
439+
* `slots` is the number of slots in the load balancer algorithm (10-65536, defaults to 10000).
440+
* `hash_on` is a hashing input type: `none `(resulting in a weighted-round-robin scheme with no hashing), `consumer`, `ip`, `header`, or `cookie`. Defaults to `none`.
441+
* `hash_fallback` is a hashing input type if the primary `hash_on` does not return a hash (eg. header is missing, or no consumer identified). One of: `none`, `consumer`, `ip`, `header`, or `cookie`. Not available if `hash_on` is set to `cookie`. Defaults to `none`.
442+
* `hash_on_header` is a header name to take the value from as hash input. Only required when `hash_on` is set to `header`. Default `nil`.
443+
* `hash_fallback_header` is a header name to take the value from as hash input. Only required when `hash_fallback` is set to `header`. Default `nil`.
444+
* `healthchecks.active.timeout` is a socket timeout for active health checks (in seconds). Defaults to `1`.
445+
* `healthchecks.active.concurrency` is a number of targets to check concurrently in active health checks. Defaults to `10`.
446+
* `healthchecks.active.http_path` is a path to use in GET HTTP request to run as a probe on active health checks. Defaults to `/`.
447+
* `healthchecks.active.healthy.interval` is an interval between active health checks for healthy targets (in seconds). A value of zero indicates that active probes for healthy targets should not be performed. Defaults to `0`.
448+
* `healthchecks.active.healthy.successes` is a number of successes in active probes (as defined by `healthchecks.active.healthy.http_statuses`) to consider a target healthy. Defaults to `0`.
449+
* `healthchecks.active.healthy.http_statuses` is an array of HTTP statuses to consider a success, indicating healthiness, when returned by a probe in active health checks. Defaults to `[200, 302]`.
450+
* `healthchecks.active.unhealthy.interval` is an interval between active health checks for unhealthy targets (in seconds). A value of zero indicates that active probes for unhealthy targets should not be performed. Defaults to `0`.
451+
* `healthchecks.active.unhealthy.tcp_failures` is a number of TCP failures in active probes to consider a target unhealthy. Defaults to `0`.
452+
* `healthchecks.active.unhealthy.http_failures` is a number of HTTP failures in active probes (as defined by `healthchecks.active.unhealthy.http_statuses`) to consider a target unhealthy. Defaults to `0`.
453+
* `healthchecks.active.unhealthy.timeouts` is a number of timeouts in active probes to consider a target unhealthy. Defaults to `0`.
454+
* `healthchecks.active.unhealthy.http_statuses` is an array of HTTP statuses to consider a failure, indicating unhealthiness, when returned by a probe in active health checks. Defaults to `[429, 404, 500, 501, 502, 503, 504, 505]`.
455+
* `healthchecks.passive.healthy.successes` is a Number of successes in proxied traffic (as defined by `healthchecks.passive.healthy.http_statuses`) to consider a target healthy, as observed by passive health checks. Defaults to `0`.
456+
* `healthchecks.passive.healthy.http_statuses` is an array of HTTP statuses which represent healthiness when produced by proxied traffic, as observed by passive health checks. Defaults to `[200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308]`.
457+
* `healthchecks.passive.unhealthy.tcp_failures` is a number of TCP failures in proxied traffic to consider a target unhealthy, as observed by passive health checks. Defaults to `0`.
458+
* `healthchecks.passive.unhealthy.http_failures` is a number of HTTP failures in proxied traffic (as defined by `healthchecks.passive.unhealthy.http_statuses`) to consider a target unhealthy, as observed by passive health checks. Defaults to `0`.
459+
* `healthchecks.passive.unhealthy.timeouts` is a number of timeouts in proxied traffic to consider a target unhealthy, as observed by passive health checks. Defaults to `0`.
460+
* `healthchecks.passive.unhealthy.http_statuses` is an array of HTTP statuses which represent unhealthiness when produced by proxied traffic, as observed by passive health checks. Defaults to `[429, 500, 503]`.
381461
* `order_list` - a list containing the slot order on the found upstream
382462

463+
To import an upstream:
464+
```
465+
terraform import kong_upstream.<upstream_identifier> <upstream_id>
466+
```
467+
468+
## Targets
469+
```hcl
470+
resource "kong_target" "target" {
471+
target = "sample_target:80"
472+
weight = 10
473+
upstream_id = "${kong_upstream.upstream.id}"
474+
}
475+
```
476+
`target` is the target address (IP or hostname) and port. If omitted the port defaults to 8000.
477+
`weight` is the weight this target gets within the upstream load balancer (0-1000, defaults to 100).
478+
`upstream_id` is the id of the upstream to apply this target to.
479+
480+
481+
To import a target use a combination of the upstream id and the target id as follows:
482+
```
483+
terraform import kong_target.<target_identifier> <upstream_id>/<target_id>
484+
```
383485

384486
# Contributing
385487
I would love to get contributions to the project so please feel free to submit a PR. To setup your dev station you need go and docker installed.
@@ -393,4 +495,3 @@ goimports needs running on the following files:
393495
Then all you need to do is run `make goimports` this will reformat all of the code (I know awesome)!!
394496

395497
Please write tests for your new feature/bug fix, PRs will only be accepted with covering tests and where all tests pass. If you want to start work on a feature feel free to open a PR early so we can discuss it or if you need help.
396-

kong/data_source_upstream.go

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,191 @@ func dataSourceKongUpstream() *schema.Resource {
3939
Type: schema.TypeInt,
4040
Computed: true,
4141
},
42+
"hash_on": &schema.Schema{
43+
Type: schema.TypeString,
44+
Optional: true,
45+
ForceNew: false,
46+
Default: "none",
47+
},
48+
"hash_fallback": &schema.Schema{
49+
Type: schema.TypeString,
50+
Optional: true,
51+
ForceNew: false,
52+
Default: "none",
53+
},
54+
"hash_on_header": &schema.Schema{
55+
Type: schema.TypeString,
56+
Optional: true,
57+
ForceNew: false,
58+
Default: nil,
59+
},
60+
"hash_fallback_header": &schema.Schema{
61+
Type: schema.TypeString,
62+
Optional: true,
63+
ForceNew: false,
64+
Default: nil,
65+
},
66+
"healthchecks": &schema.Schema{
67+
Type: schema.TypeList,
68+
Optional: true,
69+
MaxItems: 1,
70+
Computed: true,
71+
Elem: &schema.Resource{
72+
Schema: map[string]*schema.Schema{
73+
"active": &schema.Schema{
74+
Type: schema.TypeList,
75+
Optional: true,
76+
MaxItems: 1,
77+
Computed: true,
78+
Elem: &schema.Resource{
79+
Schema: map[string]*schema.Schema{
80+
"timeout": &schema.Schema{
81+
Type: schema.TypeInt,
82+
Optional: true,
83+
Default: 1,
84+
},
85+
"concurrency": &schema.Schema{
86+
Type: schema.TypeInt,
87+
Optional: true,
88+
Default: 10,
89+
},
90+
"http_path": &schema.Schema{
91+
Type: schema.TypeString,
92+
Optional: true,
93+
Default: "/",
94+
},
95+
"healthy": &schema.Schema{
96+
Type: schema.TypeList,
97+
Optional: true,
98+
MaxItems: 1,
99+
Computed: true,
100+
Elem: &schema.Resource{
101+
Schema: map[string]*schema.Schema{
102+
"interval": &schema.Schema{
103+
Type: schema.TypeInt,
104+
Optional: true,
105+
Computed: true,
106+
},
107+
"http_statuses": &schema.Schema{
108+
Type: schema.TypeList,
109+
Optional: true,
110+
Computed: true,
111+
Elem: &schema.Schema{
112+
Type: schema.TypeInt,
113+
},
114+
},
115+
"successes": &schema.Schema{
116+
Type: schema.TypeInt,
117+
Optional: true,
118+
Computed: true,
119+
},
120+
},
121+
},
122+
},
123+
"unhealthy": &schema.Schema{
124+
Type: schema.TypeList,
125+
Optional: true,
126+
MaxItems: 1,
127+
Computed: true,
128+
Elem: &schema.Resource{
129+
Schema: map[string]*schema.Schema{
130+
"interval": &schema.Schema{
131+
Type: schema.TypeInt,
132+
Optional: true,
133+
Computed: true,
134+
},
135+
"http_statuses": &schema.Schema{
136+
Type: schema.TypeList,
137+
Optional: true,
138+
Computed: true,
139+
Elem: &schema.Schema{
140+
Type: schema.TypeInt,
141+
},
142+
},
143+
"tcp_failures": &schema.Schema{
144+
Type: schema.TypeInt,
145+
Optional: true,
146+
Computed: true,
147+
},
148+
"http_failures": &schema.Schema{
149+
Type: schema.TypeInt,
150+
Optional: true,
151+
Computed: true,
152+
},
153+
"timeouts": &schema.Schema{
154+
Type: schema.TypeInt,
155+
Optional: true,
156+
Computed: true,
157+
},
158+
},
159+
},
160+
},
161+
},
162+
},
163+
},
164+
"passive": &schema.Schema{
165+
Type: schema.TypeList,
166+
Optional: true,
167+
MaxItems: 1,
168+
Computed: true,
169+
Elem: &schema.Resource{
170+
Schema: map[string]*schema.Schema{
171+
"healthy": &schema.Schema{
172+
Type: schema.TypeList,
173+
Optional: true,
174+
MaxItems: 1,
175+
Computed: true,
176+
Elem: &schema.Resource{
177+
Schema: map[string]*schema.Schema{
178+
"http_statuses": &schema.Schema{
179+
Type: schema.TypeList,
180+
Optional: true,
181+
Elem: &schema.Schema{
182+
Type: schema.TypeInt,
183+
},
184+
},
185+
"successes": &schema.Schema{
186+
Type: schema.TypeInt,
187+
Optional: true,
188+
},
189+
},
190+
},
191+
},
192+
"unhealthy": &schema.Schema{
193+
Type: schema.TypeList,
194+
Optional: true,
195+
MaxItems: 1,
196+
Computed: true,
197+
Elem: &schema.Resource{
198+
Schema: map[string]*schema.Schema{
199+
"http_statuses": &schema.Schema{
200+
Type: schema.TypeList,
201+
Optional: true,
202+
Elem: &schema.Schema{
203+
Type: schema.TypeInt,
204+
},
205+
},
206+
"tcp_failures": &schema.Schema{
207+
Type: schema.TypeInt,
208+
Optional: true,
209+
},
210+
"http_failures": &schema.Schema{
211+
Type: schema.TypeInt,
212+
Optional: true,
213+
},
214+
"timeouts": &schema.Schema{
215+
Type: schema.TypeInt,
216+
Optional: true,
217+
},
218+
},
219+
},
220+
},
221+
},
222+
},
223+
},
224+
},
225+
},
226+
},
42227
"order_list": {
43228
Type: schema.TypeList,
44229
Optional: true,
@@ -82,6 +267,13 @@ func dataSourceKongUpstreamRead(d *schema.ResourceData, meta interface{}) error
82267
d.Set("id", upstream.Id)
83268
d.Set("name", upstream.Name)
84269
d.Set("slots", upstream.Slots)
270+
d.Set("hash_on", upstream.HashOn)
271+
d.Set("hash_fallback", upstream.HashFallback)
272+
d.Set("hash_on_header", upstream.HashOnHeader)
273+
d.Set("hash_fallback_header", upstream.HashFallbackHeader)
274+
if err := d.Set("healthchecks", flattenHealthCheck(upstream.HealthChecks)); err != nil {
275+
return err
276+
}
85277

86278
return nil
87279
}

0 commit comments

Comments
 (0)