Skip to content

Commit e89326a

Browse files
authored
Support kong 1.0.0 (#55)
* starting work on Kong 1.0.0 compatibility * global plugin test passing * all plugin tests passing * fixing upstream tests * early version with all tests passing * removing unsupported property * make goimports * make goimports * updated readme
1 parent 20e9fa7 commit e89326a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+595
-2549
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: go
22
go:
3-
- 1.10.x
3+
- 1.11.x
44
services:
55
- docker
66
install:
@@ -11,7 +11,6 @@ after_success:
1111
- make release
1212
env:
1313
matrix:
14-
- KONG_VERSION=0.13 TF_ACC=1
15-
- KONG_VERSION=0.13.1 TF_ACC=1
14+
- KONG_VERSION=1.0.0 TF_ACC=1
1615
global:
1716
- secure: WdxZxmO0DUJnIZMh54Ivtnnn65UiKrJ5obLY+8X7Fdc1CTMtKcxg1EFXVo1ixvvRKZJBc8IxuitogQPB4y5WiFNle7uwHCMVhpTnSd5nzy5V2zAa+uDA7BfC+4tIma3vRfI9DxM6i53n3s2vwaqzWdE3/RtcgSALpD06hGKFYFebg5D1YV9d11G2rzze4MCm0rca3oNK3clKYcR8oePJhUtBdwX/F0j2deEpw1wLBYVS8XAc13oWsiZ9j3hTAyXUtDXImIQrLCqYLgivW/hNjSsZBrfy2J1vy/xJyXF4iihyhLxnmvpc5STEBaHsJWc2dnjEYjIxfeRd1iF2ym8KNXW9R38ZFghL2bp1RzMdh3SbEHHTQOCoG927FFjyloPLJ/H7RG7SIkwwsA4m7429BWDit+S5/oBPdLtqIXvF+2vioKiBxMSoa858JfJgBdN+Oe/oVfZGTBkXEfi+af257b7VjhgbgLh4/fkOEKKMWPsm0ogsKMbHQTfnUG+beAd9hgV03z7uBon5sUJ5gCkC6XBQQ6j3qboN+gT/XCkglUTd4ySaZ2Eg2ofvy+1DFeJePIKaI7WELYUPRAI5Bes9e3MdZCbhAebGj2iEB3Gnj+5c6Vuz2l3I5Mgm7Ax6kT0BPwCl+0rF9wBXUoM/rc9QoNTZDJl4Ynkof2pr3Bzmlk8=

README.md

Lines changed: 77 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ Terraform Provider Kong
55
The Kong Terraform Provider tested against real Kong!
66

77

8-
Notice
8+
IMPORTANT
99
------
10-
**CURRENTLY NOT COMPATIBLE WITH KONG 1.0.0 - Im working on support for it**
10+
This provider now supports kong `v1.0.0` and onwards (from `v2.0.0` onwards of provider) Since the release of Kong `v1.0.0` has many breaking changes (e.g. removing APIs) this provider is
11+
no longer compatible with version of kong pre v1.0.0. If you want to use the provider with versions of kong pre `v1.0.0` then please checkout branch `kong-pre-1.0.0` or
12+
use a version of the provider `v1.9.1` or less.
1113

12-
I have recently updated the provider to use `v1.0.0` of [gokong](http://github.com/kevholditch/gokong) this pulls in the changes to use pointers to all api fields. If you update to the latest provider
13-
be aware of this change. Terraform may want to update some api resources as this fixes a bug where if you set a string from a value to `""` it will now be treated as empty string and not ignored. If you
14-
have set any of your api fields to empty string this will now be picked up.
14+
Due to compatibility issues I have had to remove some of the properties on the resources. Most notability for a plugin you can only configure it using the `config_json` property
15+
the `config` property has been removed. This is due to some internal changes that have been made to kong in `v1.0.0`.
1516

1617
Requirements
1718
------------
@@ -71,7 +72,7 @@ resource "kong_service" "service" {
7172
7273
}
7374
```
74-
The service resource maps directly onto the json for the service endpoint in Kong. For more information on the parameters [see the Kong Service create documentation](https://getkong.org/docs/0.13.x/admin-api/#service-object).
75+
The service resource maps directly onto the json for the service endpoint in Kong. For more information on the parameters [see the Kong Service create documentation](https://getkong.org/docs/1.0.x/admin-api/#service-object).
7576

7677
To import a service:
7778
```
@@ -91,89 +92,98 @@ resource "kong_route" "route" {
9192
}
9293
9394
```
94-
The route resource maps directly onto the json for the route endpoint in Kong. For more information on the parameters [see the Kong Route create documentation](https://getkong.org/docs/0.13.x/admin-api/#route-object).
95+
The route resource maps directly onto the json for the route endpoint in Kong. For more information on the parameters [see the Kong Route create documentation](https://getkong.org/docs/1.0.x/admin-api/#route-object).
9596

9697
To import a route:
9798
```
9899
terraform import kong_route.<route_identifier> <route_id>
99100
```
100101

101-
## Apis
102+
103+
## Plugins
102104
```hcl
103-
resource "kong_api" "api" {
104-
name = "TestApi"
105-
hosts = [ "example.com" ]
106-
uris = [ "/example" ]
107-
methods = [ "GET", "POST" ]
108-
upstream_url = "http://localhost:4140"
109-
strip_uri = false
110-
preserve_host = false
111-
retries = 3
112-
upstream_connect_timeout = 60000
113-
upstream_send_timeout = 30000
114-
upstream_read_timeout = 10000
115-
https_only = false
116-
http_if_terminated = false
117-
}
105+
resource "kong_plugin" "rate_limit" {
106+
name = "rate-limiting"
107+
config_json = <<EOT
108+
{
109+
"second": 5,
110+
"hour" : 1000
111+
}
112+
EOT
118113
```
119-
The api resource maps directly onto the json for the API endpoint in Kong. For more information on the parameters [see the Kong Api create documentation](https://getkong.org/docs/0.13.x/admin-api/#api-object).
120114

121-
To import an API:
122-
```
123-
terraform import kong_api.<api_identifier> <api_id>
124-
```
115+
The `config_json` is passed through to the plugin to configure it as is. Note that the old `config` property has been removed due to incompatibility issues with kong v1.0.0.
116+
Having the `config_json` property gives you ultimate flexibility to configure the plugin.
125117

126-
## Plugins
118+
To apply a plugin to a consumer use the `consumer_id` property, for example:
127119
```hcl
128-
resource "kong_plugin" "response_rate_limiting" {
129-
name = "response-ratelimiting"
130-
config = {
131-
limits.sms.minute = 10
132-
}
120+
resource "kong_consumer" "plugin_consumer" {
121+
username = "PluginUser"
122+
custom_id = "567"
133123
}
134-
```
135-
136-
The plugin resource maps directly onto the json for the API endpoint in Kong. For more information on the parameters [see the Kong Api create documentation](https://getkong.org/docs/0.13.x/admin-api/#plugin-object).
137124
138-
To import a plugin:
139-
```
140-
terraform import kong_plugin.<plugin_identifier> <plugin_id>
125+
resource "kong_plugin" "rate_limit" {
126+
name = "rate-limiting"
127+
consumer_id = "${kong_consumer.plugin_consumer.id}"
128+
config_json = <<EOT
129+
{
130+
"second": 5,
131+
"hour" : 1000
132+
}
133+
EOT
134+
}
141135
```
142136

143-
Here is a more complex example for creating a plugin for a consumer and an API:
137+
To apply a plugin to a service use the `service_id` property, for example:
144138

145139
```hcl
146-
resource "kong_api" "api" {
147-
name = "TestApi"
148-
hosts = [ "example.com" ]
149-
uris = [ "/example" ]
150-
methods = [ "GET", "POST" ]
151-
upstream_url = "http://localhost:4140"
152-
strip_uri = false
153-
preserve_host = false
154-
retries = 3
155-
upstream_connect_timeout = 60000
156-
upstream_send_timeout = 30000
157-
upstream_read_timeout = 10000
158-
https_only = false
159-
http_if_terminated = false
140+
resource "kong_service" "service" {
141+
name = "test"
142+
protocol = "http"
143+
host = "test.org"
160144
}
161145
162-
resource "kong_consumer" "plugin_consumer" {
163-
username = "PluginUser"
164-
custom_id = "111"
146+
resource "kong_plugin" "rate_limit" {
147+
name = "rate-limiting"
148+
service_id = "${kong_service.service.id}"
149+
config_json = <<EOT
150+
{
151+
"second": 10,
152+
"hour" : 2000
153+
}
154+
EOT
155+
}
156+
```
157+
158+
To apply a plugin to a route use the `route_id` property, for example:
159+
160+
```hcl
161+
resource "kong_service" "service" {
162+
name = "test"
163+
protocol = "http"
164+
host = "test.org"
165165
}
166166
167167
resource "kong_plugin" "rate_limit" {
168-
name = "response-ratelimiting"
169-
api_id = "${kong_api.api.id}"
170-
consumer_id = "${kong_consumer.plugin_consumer.id}"
171-
config = {
172-
limits.sms.minute = 77
173-
}
168+
name = "rate-limiting"
169+
service_id = "${kong_service.service.id}"
170+
config_json = <<EOT
171+
{
172+
"second": 11,
173+
"hour" : 4000
174+
}
175+
EOT
174176
}
175177
```
176178

179+
180+
The plugin resource maps directly onto the json for the API endpoint in Kong. For more information on the parameters [see the Kong Api create documentation](https://getkong.org/docs/1.0.x/admin-api/#plugin-object).
181+
182+
To import a plugin:
183+
```
184+
terraform import kong_plugin.<plugin_identifier> <plugin_id>
185+
```
186+
177187
### Configure plugins for a consumer
178188
Some plugins allow you to configure them for a specific consumer for example the [jwt](https://getkong.org/plugins/jwt/#create-a-jwt-credential) and [key-auth](https://getkong.org/plugins/key-authentication/#create-an-api-key) plugins.
179189
To configure a plugin for a consumer this terraform provider provides a generic way to do this for all plugins the `kong_consumer_plugin_config` resource.
@@ -224,7 +234,7 @@ resource "kong_consumer" "consumer" {
224234
}
225235
```
226236

227-
The consumer resource maps directly onto the json for creating an Consumer in Kong. For more information on the parameters [see the Kong Consumer create documentation](https://getkong.org/docs/0.13.x/admin-api/#consumer-object).
237+
The consumer resource maps directly onto the json for creating an Consumer in Kong. For more information on the parameters [see the Kong Consumer create documentation](https://getkong.org/docs/1.0.x/admin-api/#consumer-object).
228238

229239
To import a consumer:
230240
```
@@ -242,7 +252,7 @@ resource "kong_certificate" "certificate" {
242252
`certificate` should be the public key of your certificate it is mapped to the `Cert` parameter on the Kong API.
243253
`private_key` should be the private key of your certificate it is mapped to the `Key` parameter on the Kong API.
244254

245-
For more information on creating certificates in Kong [see their documentation](https://getkong.org/docs/0.13.x/admin-api/#certificate-object)
255+
For more information on creating certificates in Kong [see their documentation](https://getkong.org/docs/1.0.x/admin-api/#certificate-object)
246256

247257
To import a certificate:
248258
```
@@ -264,7 +274,7 @@ resource "kong_sni" "sni" {
264274
`name` is your domain you want to assign to the certificate
265275
`certificate_id` is the id of a certificate
266276

267-
For more information on creating SNIs in Kong [see their documentaton](https://getkong.org/docs/0.13.x/admin-api/#sni-objects)
277+
For more information on creating SNIs in Kong [see their documentaton](https://getkong.org/docs/1.0.x/admin-api/#sni-objects)
268278

269279
To import a SNI:
270280
```
@@ -279,108 +289,6 @@ resource "kong_upstream" "upstream" {
279289
}
280290
```
281291

282-
283-
# Data Sources
284-
## APIs
285-
To look up an existing api you can do so by using a filter:
286-
```hcl
287-
data "kong_api" "api_data_source" {
288-
filter = {
289-
id = "de539d26-97d2-4d5b-aaf9-628e51087d9c"
290-
name = "TestDataSourceApi"
291-
upstream_url = "http://localhost:4140"
292-
}
293-
}
294-
```
295-
Each of the filter parameters are optional and they are combined for an AND search against all APIs. The following output parameters are
296-
returned:
297-
298-
* `id` - the id of the API
299-
* `name` - the name of the API
300-
* `hosts` - a list of the hosts configured on the API
301-
* `uris` - a list of the uri prefixes for the API
302-
* `methods` - a list of the allowed methods on the API
303-
* `upstream_url` - the upstream url for the API
304-
* `strip_uri` - whether the API strips the matching prefix from the uri
305-
* `preserve_host` - whether the API forwards the host header onto the upstream service
306-
* `retries` - number of retries the API executes upon failure to the upstream service
307-
* `upstream_connect_timeout` - the timeout in milliseconds for establishing a connection to your upstream service
308-
* `upstream_send_timeout` - the timeout in milliseconds between two successive write operations for transmitting a request to your upstream service
309-
* `upstream_read_timeout` - the timeout in milliseconds between two successive read operations for transmitting a request to your upstream service
310-
* `https_only` - whether the API is served through HTTPS
311-
* `http_if_terminated` - whether the API considers the X-Forwarded-Proto header when enforcing HTTPS only traffic
312-
313-
## Certificates
314-
To look up an existing certificate:
315-
```hcl
316-
data "kong_certificate" "certificate_data_source" {
317-
filter = {
318-
id = "471c625a-4eba-4b78-985f-86cf54a2dc12"
319-
}
320-
}
321-
```
322-
You can only find existing certificates by their id in Kong. The following output parameters are returned:
323-
324-
* `id` - the Kong id for the certificate
325-
* `certificate` - the public key of the certificate
326-
* `private_key` - the private key of the certificate
327-
328-
## Consumers
329-
To look up an existing consumer:
330-
```hcl
331-
data "kong_consumer" "consumer_data_source" {
332-
filter = {
333-
id = "8086a91b-cb5a-4e60-90b0-ca6650e82464"
334-
username = "User777"
335-
custom_id = "123456"
336-
}
337-
}
338-
```
339-
Each of the filter parameters are optional and they are combined for an AND search against all consumers. The following output parameters are
340-
returned:
341-
342-
* `id` - the Kong id of the found consumer
343-
* `username` - the username of the found consumer
344-
* `custom_id` - the custom id of the found consumer
345-
346-
## Plugins
347-
To look up an existing plugin:
348-
```hcl
349-
data "kong_plugin" "plugin_data_source" {
350-
filter = {
351-
id = "f0e656af-ad53-4622-ac73-ffd46ae05289"
352-
name = "response-ratelimiting"
353-
api_id = "51694bcd-3c72-43b3-b414-a09bbf4e3c30"
354-
consumer_id = "88154fd2-7a0e-41b1-97ba-4a59ebe2cc39"
355-
}
356-
}
357-
```
358-
Each of the filter parameters are optional and they are combined for an AND search against all plugins. The following output parameters are returned:
359-
360-
* `id` - the Kong id of the found plugin
361-
* `name` - the name of the found plugin
362-
* `api_id` - the API id the found plugin is associated with (might be empty if not associated with an API)
363-
* `consumer_id` - the consumer id the found plugin is associated with (might be empty if not associated with a consumer)
364-
* `enabled` - whether the plugin is enabled
365-
366-
## Upstreams
367-
To lookup an existing upstream:
368-
```hcl
369-
data "kong_upstream" "upstream_data_source" {
370-
filter = {
371-
id = "893a49a8-090f-421e-afce-ba70b02ce958"
372-
name = "TestUpstream"
373-
}
374-
}
375-
```
376-
Each of the filter parameters are optional and they are combined for an AND search against all upstreams. The following output parameters are returned:
377-
378-
* `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
381-
* `order_list` - a list containing the slot order on the found upstream
382-
383-
384292
# Contributing
385293
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.
386294

0 commit comments

Comments
 (0)