Skip to content

Instantly share code, notes, and snippets.

@nghnam
Last active February 14, 2020 06:42
Show Gist options
  • Save nghnam/6b49f18c01c5d0468c7dff7ccfe607f1 to your computer and use it in GitHub Desktop.
Save nghnam/6b49f18c01c5d0468c7dff7ccfe607f1 to your computer and use it in GitHub Desktop.

Revisions

  1. nghnam revised this gist Feb 14, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kong.tf
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ provider "kong" {

    variable "kong_admin_url" {
    description = "Kong admin api"
    default = "http://192.168.8.100:8001"
    default = "http://192.168.1.100:8001"
    }

    variable "example-user" {
  2. nghnam revised this gist Feb 14, 2020. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions kong.tf
    Original file line number Diff line number Diff line change
    @@ -39,8 +39,14 @@ resource "kong_upstream" "example" {
    slots = 1000
    }

    resource "kong_target" "example-target" {
    target = "192.168.1.100:6555"
    resource "kong_target" "example-target1" {
    target = "192.168.1.150:6555"
    weight = 10
    upstream_id = kong_upstream.example.id
    }

    resource "kong_target" "example-target2" {
    target = "192.168.1.151:6555"
    weight = 10
    upstream_id = kong_upstream.example.id
    }
  3. nghnam created this gist Feb 13, 2020.
    80 changes: 80 additions & 0 deletions kong.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,80 @@
    provider "kong" {
    kong_admin_uri = "http://192.168.1.100:8001"
    }

    variable "kong_admin_url" {
    description = "Kong admin api"
    default = "http://192.168.8.100:8001"
    }

    variable "example-user" {
    default = "admin"
    }

    variable "example-password" {
    default = "admin"
    }

    resource "kong_service" "example" {
    name = "example"
    protocol = "http"
    host = "example"
    port = 6555
    retries = 5
    }

    resource "kong_route" "example-route" {
    name = "example-route"
    protocols = ["https"]
    hosts = ["api.example.com"]
    paths = ["/"]
    https_redirect_status_code = 301
    strip_path = false
    preserve_host = true
    service_id = kong_service.example.id
    }

    resource "kong_upstream" "example" {
    name = "example"
    slots = 1000
    }

    resource "kong_target" "example-target" {
    target = "192.168.1.100:6555"
    weight = 10
    upstream_id = kong_upstream.example.id
    }

    resource "kong_consumer" "example" {
    username = "example"
    custom_id = "123"

    provisioner "local-exec" {
    command = <<EOT
    curl -X POST ${var.kong_admin_url}/consumers/${kong_consumer.example.id}/basic-auth \
    --data username=${var.example-user} \
    --data password=${var.example-password}
    EOT
    }
    }

    resource "kong_plugin" "example-basic-auth" {
    name = "basic-auth"
    route_id = kong_route.example-route.id
    enabled = true
    config_json = <<EOT
    {
    "hide_credentials": true
    }
    EOT
    }

    resource "kong_certificate" "example" {
    certificate = file("certificates/example.com/fullchain.pem")
    private_key = file("certificates/example.com/privkey.pem")
    }

    resource "kong_sni" "example" {
    name = "api.example.com"
    certificate_id = kong_certificate.example.id
    }