Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ generate-cli-docs:
mkdir -p $(CLI_DOCS_PATH)
go run docs/*.go -output-path $(CLI_DOCS_PATH)

.PHONY: generate-plugin-list
generate-plugin-list:
@curl -Ss localhost:8001 | jq -r '.plugins.available_on_server | keys | "package kong2tf\n\nvar availablePlugins = []string{\n" + (map(" \"" + . + "\"") | join(",\n")) + ",\n}"' > kong2tf/available_plugins.go

.PHONY: setup-kong
setup-kong:
bash .ci/setup_kong.sh
Expand Down
118 changes: 118 additions & 0 deletions kong2tf/available_plugins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package kong2tf

var availablePlugins = []string{
"ace",
"acl",
"acme",
"ai-a2a-proxy",
"ai-aws-guardrails",
"ai-azure-content-safety",
"ai-custom-guardrail",
"ai-gcp-model-armor",
"ai-lakera-guard",
"ai-llm-as-judge",
"ai-mcp-oauth2",
"ai-mcp-proxy",
"ai-prompt-compressor",
"ai-prompt-decorator",
"ai-prompt-guard",
"ai-prompt-template",
"ai-proxy",
"ai-proxy-advanced",
"ai-rag-injector",
"ai-rate-limiting-advanced",
"ai-request-transformer",
"ai-response-transformer",
"ai-sanitizer",
"ai-semantic-cache",
"ai-semantic-prompt-guard",
"ai-semantic-response-guard",
"app-dynamics",
"aws-lambda",
"azure-functions",
"basic-auth",
"bot-detection",
"canary",
"confluent",
"confluent-consume",
"correlation-id",
"cors",
"datadog",
"datakit",
"degraphql",
"exit-transformer",
"file-log",
"forward-proxy",
"graphql-proxy-cache-advanced",
"graphql-rate-limiting-advanced",
"grpc-gateway",
"grpc-web",
"header-cert-auth",
"hmac-auth",
"http-log",
"injection-protection",
"ip-restriction",
"jq",
"json-threat-protection",
"jwe-decrypt",
"jwt",
"jwt-signer",
"kafka-consume",
"kafka-log",
"kafka-upstream",
"key-auth",
"key-auth-enc",
"konnect-application-auth",
"ldap-auth",
"ldap-auth-advanced",
"loggly",
"metering-and-billing",
"mocking",
"mtls-auth",
"oas-validation",
"oauth2",
"oauth2-introspection",
"opa",
"openid-connect",
"opentelemetry",
"post-function",
"pre-function",
"prometheus",
"proxy-cache",
"proxy-cache-advanced",
"rate-limiting",
"rate-limiting-advanced",
"redirect",
"request-callout",
"request-size-limiting",
"request-termination",
"request-transformer",
"request-transformer-advanced",
"request-validator",
"response-ratelimiting",
"response-transformer",
"response-transformer-advanced",
"route-by-header",
"route-transformer-advanced",
"saml",
"service-protection",
"session",
"solace-consume",
"solace-log",
"solace-upstream",
"standard-webhooks",
"statsd",
"statsd-advanced",
"syslog",
"tcp-log",
"tls-handshake-modifier",
"tls-metadata-headers",
"udp-log",
"upstream-oauth",
"upstream-timeout",
"vault-auth",
"websocket-size-limit",
"websocket-validator",
"xml-threat-protection",
"zipkin",
}
41 changes: 34 additions & 7 deletions kong2tf/generate_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,34 @@ func generateResourceWithCustomizations(
delete(entity, k)
}

isCustomPlugin := false
var s string
if entityType == "gateway_plugin" {
entityType = fmt.Sprintf("%s_%s", entityType, name)
delete(entity, "name")
// If `name` is not in availablePlugins, then it's a custom plugin and
// we should use the plugin name as the resource name
if !contains(availablePlugins, entity["name"].(string)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a new plugin is introduced in a new kong gateway version - wouldn't the previously released versions of deck treat it as custom plugin

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct. That's the tradeoff we're making (it would still work, just without schema checks in TF)

isCustomPlugin = true
if customizations == nil {
customizations = map[string]string{}
}
customizations["config"] = "jsonencode"

@harshadixit12 harshadixit12 Apr 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we do jsonencode - underlying value of config is a string in https://github.com/Kong/terraform-provider-konnect/blob/main/src/custom_plugin_model.go#L40 - config.String() returns string wrapped in additonal characters, which breaks unmarshal. (ex: output is "\"{\\\"hello\\\":\\\"world\\\"}\"" instead of "{\"hello\":\"world\"}")
We'll need to fix this in custom_plugin_model.go (i'll do it)

I don't think we need to block this PR though.


s = fmt.Sprintf(`
resource "konnect_gateway_custom_plugin" "%s" {
%s

%s control_plane_id = var.control_plane_id%s
}
`,
slugify(name),
strings.TrimRight(output(entityType, entity, 1, true, "\n", customizations, oneOfFields), "\n"),
generateParents(parents),
generateLifecycle(lifecycle))

} else {
entityType = fmt.Sprintf("%s_%s", entityType, name)
delete(entity, "name")
}
}

// We don't need to prefix SNIs with the Cert name
Expand All @@ -107,17 +132,19 @@ func generateResourceWithCustomizations(
}
}

s := fmt.Sprintf(`
if !isCustomPlugin {
s = fmt.Sprintf(`
resource "konnect_%s" "%s" {
%s

%s control_plane_id = var.control_plane_id%s
}
`,
entityType, slugify(name),
strings.TrimRight(output(entityType, entity, 1, true, "\n", customizations, oneOfFields), "\n"),
generateParents(parents),
generateLifecycle(lifecycle))
entityType, slugify(name),
strings.TrimRight(output(entityType, entity, 1, true, "\n", customizations, oneOfFields), "\n"),
generateParents(parents),
generateLifecycle(lifecycle))
}

// Generate imports
if imports.controlPlaneID != nil && entityID != "" {
Expand Down
63 changes: 63 additions & 0 deletions kong2tf/generate_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,66 @@ import {
}, []string{})
require.Equal(t, expected, result)
}

func TestCustomPlugin(t *testing.T) {
jsonInput := `{
"name": "my-header",
"config": {
"nested": "subkey"
}
}`

var entity map[string]any
err := json.Unmarshal([]byte(jsonInput), &entity)
require.NoError(t, err)

expected := `resource "konnect_gateway_custom_plugin" "my-header" {
name = "my-header"
config = jsonencode({
nested = "subkey"
})

control_plane_id = var.control_plane_id
}

`

cpID := new(string)
*cpID = "abc-123"

result := generateResource("gateway_plugin", "my-header", entity, map[string]string{}, importConfig{
controlPlaneID: cpID,
}, []string{})
require.Equal(t, expected, result)
}

func TestBuiltInPlugin(t *testing.T) {
jsonInput := `{
"name": "basic-auth",
"config": {
"hide_credentials": true
}
}`

var entity map[string]any
err := json.Unmarshal([]byte(jsonInput), &entity)
require.NoError(t, err)

expected := `resource "konnect_gateway_plugin_basic-auth" "basic-auth" {
config = {
hide_credentials = true
}

control_plane_id = var.control_plane_id
}

`

cpID := new(string)
*cpID = "abc-123"

result := generateResource("gateway_plugin", "basic-auth", entity, map[string]string{}, importConfig{
controlPlaneID: cpID,
}, []string{})
require.Equal(t, expected, result)
}
Loading