From 6cda8f6fb5ae0bce48e501e8f32173b1a9df99b7 Mon Sep 17 00:00:00 2001 From: kevholditch-f3 <82885135+kevholditch-f3@users.noreply.github.com> Date: Mon, 9 Aug 2021 22:21:41 +0100 Subject: [PATCH] Feature/add missing fields (#128) * fixing code warnings * added 3 of the missing service fields * adding missing fields on service * implemented all missing fields on route except header * implemented all missing fields on route * implemented all missing fields Co-authored-by: kevholditch --- docs/resources/route.md | 6 +- docs/resources/service.md | 48 +++++- docs/resources/upstream.md | 18 +++ kong/provider.go | 16 +- kong/resource_kong_certificate.go | 15 +- kong/resource_kong_consumer.go | 57 ++++--- kong/resource_kong_consumer_acl.go | 21 ++- kong/resource_kong_consumer_basic_auth.go | 23 ++- kong/resource_kong_consumer_jwt_auth.go | 35 +++-- kong/resource_kong_plugin.go | 66 ++++++--- kong/resource_kong_route.go | 173 +++++++++++++++++++--- kong/resource_kong_route_test.go | 64 +++++++- kong/resource_kong_service.go | 136 ++++++++++++++--- kong/resource_kong_service_test.go | 138 ++++++++++++++--- kong/resource_kong_target.go | 21 ++- kong/resource_kong_upstream.go | 153 +++++++++++++------ kong/resource_kong_upstream_test.go | 43 +++++- kong/resource_reader.go | 50 +++++-- 18 files changed, 873 insertions(+), 210 deletions(-) diff --git a/docs/resources/route.md b/docs/resources/route.md index e62104c..f20b9ce 100644 --- a/docs/resources/route.md +++ b/docs/resources/route.md @@ -17,6 +17,10 @@ resource "kong_route" "route" { preserve_host = true regex_priority = 1 service_id = kong_service.service.id + header { + name = "x-test-1" + values = ["a", "b"] + } } ``` @@ -52,7 +56,7 @@ resource "kong_route" "route" { * `methods` - (Optional) A list of HTTP methods that match this Route * `hosts` - (Optional) A list of domain names that match this Route * `paths` - (Optional) A list of paths that match this Route -* `headers` - (Optional) One or more lists of values indexed by header name that will cause this Route to match if present in the request. The Host header cannot be used with this attribute: hosts should be specified using the hosts attribute. +* `header` - (Optional) One or more blocks of `name` to set name of header and `values` which is a list of `string` for the header values to match on. See above example of how to set. These headers will cause this Route to match if present in the request. The Host header cannot be used with this attribute: hosts should be specified using the hosts attribute. * `https_redirect_status_code` - (Optional) The status code Kong responds with when all properties of a Route match except the protocol i.e. if the protocol of the request is HTTP instead of HTTPS. Location header is injected by Kong if the field is set to `301`, `302`, `307` or `308`. Accepted values are: `426`, `301`, `302`, `307`, `308`. Default: `426`. * `strip_path` - (Optional) When matching a Route via one of the paths, strip the matching prefix from the upstream request URL. Default: true. * `regex_priority` - (Optional) A number used to choose which route resolves a given request when several routes match it using regexes simultaneously. diff --git a/docs/resources/service.md b/docs/resources/service.md index c88f44f..0f0d665 100644 --- a/docs/resources/service.md +++ b/docs/resources/service.md @@ -18,6 +18,48 @@ resource "kong_service" "service" { } ``` +To use a client certificate and ca certificates combine with certificate resource (note protocol must be `https`): + +```hcl +resource "kong_certificate" "certificate" { + certificate = < 0 { healthChecksMap := healthChecksArray[0].(map[string]interface{}) diff --git a/kong/resource_kong_upstream_test.go b/kong/resource_kong_upstream_test.go index 2416272..d6a0cc0 100644 --- a/kong/resource_kong_upstream_test.go +++ b/kong/resource_kong_upstream_test.go @@ -82,7 +82,7 @@ func TestAccKongUpstream(t *testing.T) { ), }, { - Config: testUpdateUpstreamConfig, + Config: fmt.Sprintf(testUpdateUpstreamConfig, testCert1, testKey1), Check: resource.ComposeTestCheckFunc( testAccCheckKongUpstreamExists("kong_upstream.upstream"), resource.TestCheckResourceAttr("kong_upstream.upstream", "name", "MyUpstream"), @@ -94,6 +94,33 @@ func TestAccKongUpstream(t *testing.T) { resource.TestCheckResourceAttr("kong_upstream.upstream", "hash_on_cookie", "CookieName"), resource.TestCheckResourceAttr("kong_upstream.upstream", "hash_on_cookie_path", "/path"), + resource.TestCheckResourceAttr("kong_upstream.upstream", "host_header", "x-host"), + resource.TestCheckResourceAttr("kong_upstream.upstream", "tags.#", "2"), + resource.TestCheckResourceAttr("kong_upstream.upstream", "tags.0", "a"), + resource.TestCheckResourceAttr("kong_upstream.upstream", "tags.1", "b"), + func(s *terraform.State) error { + module := s.RootModule() + cert, ok := module.Resources["kong_certificate.certificate"] + if !ok { + return fmt.Errorf("could not find certificate resource") + } + + service, ok := module.Resources["kong_upstream.upstream"] + if !ok { + return fmt.Errorf("could not find upstream resource") + } + + v, ok := service.Primary.Attributes["client_certificate_id"] + if !ok { + return fmt.Errorf("could not find client_certificate_id property") + } + + if v != cert.Primary.ID { + return fmt.Errorf("client_certificate_id does not match certificate id") + } + return nil + }, + resource.TestCheckResourceAttr("kong_upstream.upstream", "healthchecks.0.active.0.type", "https"), resource.TestCheckResourceAttr("kong_upstream.upstream", "healthchecks.0.active.0.timeout", "10"), resource.TestCheckResourceAttr("kong_upstream.upstream", "healthchecks.0.active.0.concurrency", "20"), @@ -1048,6 +1075,16 @@ resource "kong_upstream" "upstream" { } ` const testUpdateUpstreamConfig = ` +resource "kong_certificate" "certificate" { + certificate = <