diff --git a/app/_includes/plugins/create-consumer/terraform.html b/app/_includes/plugins/create-consumer/terraform.html new file mode 100644 index 000000000000..d8fd3fd36c4d --- /dev/null +++ b/app/_includes/plugins/create-consumer/terraform.html @@ -0,0 +1,27 @@ +{% if include.hub_example.auth_plugin? %} + +As this is an auth plugin, you need to create a consumer and attach a credential to it. + +Create a consumer: + +```bash +resource "konnect_gateway_consumer" "alex" { + username = "alex" + custom_id = "alex-custom" + control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id +} +``` + +Create a {{ include.hub_example.plugin_name }} credential attached to this consumer: + +{% assign plugin_name = include.hub_example.plugin_name | replace: "-","_" %} +```hcl +resource "konnect_gateway_{{ plugin_name }}" "my_{{ plugin_name }}" { +{%- for field in include.hub_example.auth_fields %} + {{ field[0] }} = {{ field[1] | quote }}{% endfor %} + + consumer_id = konnect_gateway_consumer.alex.id + control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id +} +``` +{% endif %} diff --git a/app/_includes/plugins/hub-examples/consumer.html b/app/_includes/plugins/hub-examples/consumer.html index 9ed4cae4d3a3..ed497633e5ef 100644 --- a/app/_includes/plugins/hub-examples/consumer.html +++ b/app/_includes/plugins/hub-examples/consumer.html @@ -79,4 +79,14 @@ {% endnavtab %} {% endif %} {% endunless %} + + {% unless page.terraform_examples == false %} + {% if hub_example.render_terraform? %} + {% navtab Konnect Terraform %} + + {% include_cached plugins/hub-examples/terraform.html example=hub_example parent="consumer" %} + + {% endnavtab %} + {% endif %} + {% endunless %} {% endnavtabs %} diff --git a/app/_includes/plugins/hub-examples/consumer_groups.html b/app/_includes/plugins/hub-examples/consumer_groups.html index 55ce17bdf003..482b689634ff 100644 --- a/app/_includes/plugins/hub-examples/consumer_groups.html +++ b/app/_includes/plugins/hub-examples/consumer_groups.html @@ -77,4 +77,15 @@ {% endnavtab %} {% endif %} {% endunless %} + + {% unless page.terraform_examples == false %} + {% if hub_example.render_terraform? %} + {% navtab Konnect Terraform %} + + {% include_cached plugins/hub-examples/terraform.html example=hub_example parent="consumer_group" %} + + {% endnavtab %} + {% endif %} + {% endunless %} + {% endnavtabs %} diff --git a/app/_includes/plugins/hub-examples/global.html b/app/_includes/plugins/hub-examples/global.html index c8e0670ef9b8..d96760090017 100644 --- a/app/_includes/plugins/hub-examples/global.html +++ b/app/_includes/plugins/hub-examples/global.html @@ -93,5 +93,18 @@ {% endnavtab %} {% endif %} {% endunless %} + + {% unless page.terraform_examples == false %} + {% if hub_example.render_terraform? %} + {% navtab Konnect Terraform %} + + {% include_cached plugins/hub-examples/terraform.html example=hub_example %} + + {% include_cached plugins/create-consumer/terraform.html hub_example=hub_example %} + + {% endnavtab %} + {% endif %} + {% endunless %} + {% endnavtabs %} {% endif %} diff --git a/app/_includes/plugins/hub-examples/route.html b/app/_includes/plugins/hub-examples/route.html index 1142aaf11a90..890eed645410 100644 --- a/app/_includes/plugins/hub-examples/route.html +++ b/app/_includes/plugins/hub-examples/route.html @@ -85,4 +85,17 @@ {% endnavtab %} {% endif %} {% endunless %} + +{% unless page.terraform_examples == false %} + {% if hub_example.render_terraform? %} + {% navtab Konnect Terraform %} + +{% include_cached plugins/hub-examples/terraform.html example=hub_example parent="route" %} + +{% include_cached plugins/create-consumer/terraform.html hub_example=hub_example %} + + {% endnavtab %} + {% endif %} +{% endunless %} + {% endnavtabs %} diff --git a/app/_includes/plugins/hub-examples/service.html b/app/_includes/plugins/hub-examples/service.html index 4b8bdda405df..a59e82113fa0 100644 --- a/app/_includes/plugins/hub-examples/service.html +++ b/app/_includes/plugins/hub-examples/service.html @@ -84,4 +84,16 @@ {% endnavtab %} {% endif %} {% endunless %} + + {% unless page.terraform_examples == false %} + {% if hub_example.render_terraform? %} + {% navtab Konnect Terraform %} + +{% include_cached plugins/hub-examples/terraform.html example=hub_example parent="service" %} + +{% include_cached plugins/create-consumer/terraform.html hub_example=hub_example %} + + {% endnavtab %} + {% endif %} + {% endunless %} {% endnavtabs %} diff --git a/app/_includes/plugins/hub-examples/terraform.html b/app/_includes/plugins/hub-examples/terraform.html new file mode 100644 index 000000000000..cc488b44d24b --- /dev/null +++ b/app/_includes/plugins/hub-examples/terraform.html @@ -0,0 +1,38 @@ +
+ Prerequisite: Configure your Personal Access Token + +```hcl +terraform { + required_providers { + konnect = { + source = "kong/konnect" + } + } +} + +provider "konnect" { + personal_access_token = "kpat_YOUR_TOKEN" + server_url = "https://us.api.konghq.com/v2" +} +``` +
+ +Add the following to your Terraform configuration to create a Konnect Gateway Plugin: + +{% assign plugin_name = include.example.plugin_name | replace: "-","_" %} +```hcl +resource "konnect_gateway_plugin_{{ plugin_name }}" "my_{{ plugin_name }}" { + enabled = true + + config = { + {%- for item in include.example.example.config %} + {{ item[0] }} = {{ item[1] | quote }}{%- endfor %} + } + + control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id{% if include.parent %} + {{ include.parent }} = { + id = konnect_gateway_{{ include.parent }}.my_{{ include.parent }}.id + } +{%- endif %} +} +``` diff --git a/app/_plugins/drops/plugins/hub_examples.rb b/app/_plugins/drops/plugins/hub_examples.rb index 49475bb0a8a3..6242639c1c27 100644 --- a/app/_plugins/drops/plugins/hub_examples.rb +++ b/app/_plugins/drops/plugins/hub_examples.rb @@ -2,6 +2,37 @@ # There are also oauth2, acl and mtls-auth but I don't have examples of how to use them yet AUTH_PLUGINS = %w[basic-auth hmac-auth jwt key-auth].freeze +TERRAFORM_ENABLED_PLUGINS = %w[ + key-auth + cors + rate-limiting + basic-auth + rate-limiting-advanced + openid-connect + jwt + prometheus + acl + request-termination + file-log + request-transformer + correlation-id + proxy-cache + request-transformer-advanced + response-transformer + response-transformer-advanced + ip-restriction + pre-function + oauth2 + opentelemetry + ai-proxy + ai-prompt-guard + ai-prompt-template + ai-prompt-decorator + aws-lambda + jq + jwt-signer + saml +].freeze module Jekyll module Drops @@ -31,6 +62,14 @@ def render_kubernetes? @formats.include?(:kubernetes) end + def render_terraform? + terraform_implemented? && @formats.include?(:terraform) + end + + def terraform_implemented? + TERRAFORM_ENABLED_PLUGINS.include?(plugin_name) + end + def auth_plugin? AUTH_PLUGINS.include?(plugin_name) end diff --git a/app/_plugins/filters/quote_filter.rb b/app/_plugins/filters/quote_filter.rb new file mode 100644 index 000000000000..7eb222fc8208 --- /dev/null +++ b/app/_plugins/filters/quote_filter.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module QuoteFilter + def quote(input) + if input.is_a?(Numeric) + input + else + "\"#{input}\"" + end + end +end + +Liquid::Template.register_filter(QuoteFilter) diff --git a/app/_plugins/generators/plugin_single_source/plugin/page_data.rb b/app/_plugins/generators/plugin_single_source/plugin/page_data.rb index 38e3a5fd062a..9ce6ad6c3fc8 100644 --- a/app/_plugins/generators/plugin_single_source/plugin/page_data.rb +++ b/app/_plugins/generators/plugin_single_source/plugin/page_data.rb @@ -72,7 +72,7 @@ def hub_examples schema: @release.schema, example: @release.schema.example, targets: ::Jekyll::InlinePluginExample::Config::TARGETS, - formats: %i[curl konnect yaml kubernetes] + formats: %i[curl konnect yaml kubernetes terraform] ) end