Terraform for self-managed Kong Gateway
Goal
Author or revise Terraform-managed self-managed Kong Gateway entities while
preserving the repository's current module layout, provider model, and state
ownership.
Use this skill once Terraform is already the right tool for Admin API-backed
self-managed Gateway work. Do not use it as the default for Konnect platform
resources or for design and troubleshooting work that should happen before
tool-specific HCL changes.
Tool Positioning
- Use this skill when the repository already uses Terraform for self-managed
Gateway resources or the user explicitly asks for Terraform.
- This skill owns HCL authoring, import-first adoption, plan review, and
Terraform-native proof after the Terraform path is chosen.
- Preserve existing Terraform modules, variables, backend settings, and
workspaces.
- Use the official
kong/kong-gateway provider for self-managed Gateway
resources reachable through the Admin API.
- Hand off to
deck-gateway when the user wants file-based Gateway GitOps,
dump/diff workflows, or a decK-native repository.
- Hand off to
terraform-konnect when the target resources actually belong to
Konnect rather than a self-managed Admin API surface.
- Hand off to Gateway or product-specific diagnosis skills when the harder
problem is gateway health, plugin behavior, or design intent rather than HCL
ownership.
References To Load
Load only the reference file that matches the active branch:
references/provider-and-import.md
- Load when provider inputs, existing live resources, or import-first
handling is the main question.
references/entity-patterns.md
- Load when the user is deciding how self-managed Gateway entities should be
grouped or modeled in the existing HCL layout.
references/plan-safety-and-state.md
- Load when the main issue is how to inspect plan impact safely before
applying to a live Admin API surface.
references/provider-schema-debugging.md
- Load when nested resource shape is unclear, validation reports
object-vs-string or similar type mismatches, or provider behavior does not
line up cleanly with docs or example HCL.
Validation Contract
Preflight
Before writing HCL or proposing a plan:
- Confirm Terraform is installed and runnable.
- Confirm the target Admin API endpoint and auth method already exist.
- Inspect provider blocks, backend settings, workspace selection, and module
conventions before adding HCL.
- Keep Admin API tokens and secrets out of committed files.
- Confirm whether existing live Gateway entities must be imported before
planning.
- Use
terraform providers schema -json as the default source of truth when
nested resource shape is unclear before guessing from docs or examples
Preview
Use Terraform's native preview surface before apply:
- run the repo's normal format and validation checks when they exist
- run
terraform validate
- run
terraform plan
- import first when a live Service, Route, plugin, or other entity already
exists and should be brought under state
- check the exact resource addresses, environment, and create-update-destroy
shape before considering apply
Execute
- Describe the intended effect before any mutating command.
- Run
terraform apply only when the user explicitly asked for live mutation.
- Keep apply scoped to the same directory, workspace, and variable inputs that
were previewed.
Prove
After a requested apply:
- confirm the intended resource addresses are now present in Terraform state
- inspect key addresses with
terraform state show <address> or the repo's
normal output surface
- when practical, run a follow-up
terraform plan and expect no remaining
intended changes for the touched slice
- do not treat apply success by itself as proof that the live Gateway matches
intent
Operating Rules
- Preserve existing HCL layout, resource grouping, and variable usage.
- Use
terraform providers schema -json as the default source of truth for
unknown nested resource shape before guessing HCL from docs or examples.
- Prefer
terraform plan before terraform apply unless the user explicitly
asks for direct execution.
- If
terraform providers schema -json, provider startup, terraform validate,
or terraform plan fails in a way that suggests sandbox interference,
retry outside the sandbox with approval before treating it as a provider,
auth, or schema problem.
- Prefer importing existing Gateway resources over recreating them.
- Keep the scope limited to the Gateway entities requested by the user.
- Do not mix self-managed Gateway assumptions into Konnect tasks.
- When the repository already uses
decK, do not switch it to Terraform unless
migration is the task.
- Do not treat a successful
terraform apply as proof by itself; follow with
state or plan-based verification of the touched addresses.
Workflow
1. Classify the ownership boundary
Establish whether the task is actually:
- self-managed Gateway Admin API configuration that this skill should own
- Konnect platform configuration that belongs to
terraform-konnect
- a
decK-native Gateway workflow that belongs to deck-gateway
- gateway behavior or design diagnosis that should be resolved before
Terraform-specific implementation
Do not write HCL until that split is clear.
2. Inspect the Terraform shape
Identify:
- root and child modules
- provider aliases
- backend or remote state configuration
- variable files and secrets conventions
- existing ownership boundaries for services, routes, plugins, consumers, or
certificates
3. Confirm the target Gateway surface
Pin down:
- which Admin API endpoint is in scope
- which Gateway entities are being managed
- whether the task is create, update, import, or drift correction
Load references/provider-and-import.md when provider inputs, import-first
adoption, or Admin API targeting is the real uncertainty.
4. Choose the narrow implementation path
Default paths:
- new managed entity: add HCL in the existing module layout
- existing unmanaged entity: import first, then normalize the HCL
- large-scale file-based Gateway GitOps: consider
deck-gateway instead of
forcing Terraform if that matches the user's intent better
Load references/entity-patterns.md when repo ownership shape is the harder
question. Load references/provider-schema-debugging.md when resource shape is
the main uncertainty.
5. Author HCL with minimal churn
- reuse existing variables and locals
- keep names and identifiers stable
- avoid broad refactors while making a narrow Gateway change
- add outputs only when another module or pipeline consumes them
- inspect
terraform providers schema -json before guessing nested block or
attribute structure
6. Preview before any apply path
- run the repo's normal format and validation checks when they exist
- run
terraform validate
- run
terraform plan
- import first if the plan would recreate an entity that already exists live
- inspect whether the plan touches only the intended addresses and workspace
Load references/plan-safety-and-state.md when the operator needs a safer
inspection-first path before touching a live Gateway.
7. Execute only when requested
- Describe the intended live effect before presenting or running
terraform apply.
- Use the same directory, workspace, and variable inputs that produced the
reviewed plan.
- Run
terraform apply only when the user explicitly asked to mutate live
Gateway state.
8. Prove the result with Terraform-native checks
After any requested terraform apply:
- confirm the touched resource addresses now appear in
terraform state list
- inspect key addresses with
terraform state show <address> or the repo's
normal outputs
- when practical, run a follow-up
terraform plan and expect no remaining
intended changes for the affected slice
- call out remaining drift or ownership surprises instead of hiding them behind
apply success
9. Report config and state impact
State:
- which files or modules changed
- which Gateway entities are affected
- whether import is required
- whether the next step is
plan, apply, or external verification
Kong-Specific Gotchas
- Terraform state is not a substitute for checking what the live Gateway
already has; import matters.
- Recreating existing plugins, services, or routes can cause avoidable
identifier churn.
- Provider docs and Gateway examples can describe intent, but the Terraform
provider schema is the authoritative shape for nested HCL.
- Some teams use Terraform for infrastructure but
decK for Gateway entities;
preserve the established split if it already exists.
- A self-managed Admin API workflow is not the same as a Konnect control plane
workflow even if the resource names look similar.
Validation Checklist
Before answering, verify that you can state:
- why Terraform is the right tool for this repository or request
- which Admin API-backed Gateway surface is in scope
- which module or file owns the resources
- whether import is required
- which preview commands prove the intended change before mutation
- whether provider schema inspection is needed before guessing nested HCL shape
- whether the task stops at HCL authoring or continues to
plan/apply
- how the touched resource addresses will be proved after apply
- whether
deck-gateway would be a better fit for the user's intent
Handoffs
- Use
deck-gateway when the user wants decK-native Gateway GitOps or live
Gateway export/diff workflows.
- Use
terraform-konnect when the resources actually belong to Konnect.
- Use Gateway or product-specific domain skills when the user first needs
troubleshooting or design help rather than HCL authoring.
1---2name: terraform-kong-gateway3description: Use when editing or reviewing Terraform that manages self-managed Kong Gateway Admin API entities with the official `kong/kong-gateway` provider; not for Konnect resources, decK-native Gateway GitOps, or gateway troubleshooting before tool choice.4license: MIT5---67# Terraform for self-managed Kong Gateway89## Goal1011Author or revise Terraform-managed self-managed Kong Gateway entities while12preserving the repository's current module layout, provider model, and state13ownership.1415Use this skill once Terraform is already the right tool for Admin API-backed16self-managed Gateway work. Do not use it as the default for Konnect platform17resources or for design and troubleshooting work that should happen before18tool-specific HCL changes.1920## Tool Positioning2122- Use this skill when the repository already uses Terraform for self-managed23 Gateway resources or the user explicitly asks for Terraform.24- This skill owns HCL authoring, import-first adoption, plan review, and25 Terraform-native proof after the Terraform path is chosen.26- Preserve existing Terraform modules, variables, backend settings, and27 workspaces.28- Use the official `kong/kong-gateway` provider for self-managed Gateway29 resources reachable through the Admin API.30- Hand off to `deck-gateway` when the user wants file-based Gateway GitOps,31 dump/diff workflows, or a `decK`-native repository.32- Hand off to `terraform-konnect` when the target resources actually belong to33 Konnect rather than a self-managed Admin API surface.34- Hand off to Gateway or product-specific diagnosis skills when the harder35 problem is gateway health, plugin behavior, or design intent rather than HCL36 ownership.3738## References To Load3940Load only the reference file that matches the active branch:4142- `references/provider-and-import.md`43 - Load when provider inputs, existing live resources, or import-first44 handling is the main question.45- `references/entity-patterns.md`46 - Load when the user is deciding how self-managed Gateway entities should be47 grouped or modeled in the existing HCL layout.48- `references/plan-safety-and-state.md`49 - Load when the main issue is how to inspect plan impact safely before50 applying to a live Admin API surface.51- `references/provider-schema-debugging.md`52 - Load when nested resource shape is unclear, validation reports53 object-vs-string or similar type mismatches, or provider behavior does not54 line up cleanly with docs or example HCL.5556## Validation Contract5758### Preflight5960Before writing HCL or proposing a plan:6162- Confirm Terraform is installed and runnable.63- Confirm the target Admin API endpoint and auth method already exist.64- Inspect provider blocks, backend settings, workspace selection, and module65 conventions before adding HCL.66- Keep Admin API tokens and secrets out of committed files.67- Confirm whether existing live Gateway entities must be imported before68 planning.69- Use `terraform providers schema -json` as the default source of truth when70 nested resource shape is unclear before guessing from docs or examples7172### Preview7374Use Terraform's native preview surface before apply:7576- run the repo's normal format and validation checks when they exist77- run `terraform validate`78- run `terraform plan`79- import first when a live Service, Route, plugin, or other entity already80 exists and should be brought under state81- check the exact resource addresses, environment, and create-update-destroy82 shape before considering apply8384### Execute8586- Describe the intended effect before any mutating command.87- Run `terraform apply` only when the user explicitly asked for live mutation.88- Keep apply scoped to the same directory, workspace, and variable inputs that89 were previewed.9091### Prove9293After a requested apply:9495- confirm the intended resource addresses are now present in Terraform state96- inspect key addresses with `terraform state show <address>` or the repo's97 normal output surface98- when practical, run a follow-up `terraform plan` and expect no remaining99 intended changes for the touched slice100- do not treat apply success by itself as proof that the live Gateway matches101 intent102103## Operating Rules104105- Preserve existing HCL layout, resource grouping, and variable usage.106- Use `terraform providers schema -json` as the default source of truth for107 unknown nested resource shape before guessing HCL from docs or examples.108- Prefer `terraform plan` before `terraform apply` unless the user explicitly109 asks for direct execution.110- If `terraform providers schema -json`, provider startup, `terraform validate`,111 or `terraform plan` fails in a way that suggests sandbox interference,112 retry outside the sandbox with approval before treating it as a provider,113 auth, or schema problem.114- Prefer importing existing Gateway resources over recreating them.115- Keep the scope limited to the Gateway entities requested by the user.116- Do not mix self-managed Gateway assumptions into Konnect tasks.117- When the repository already uses `decK`, do not switch it to Terraform unless118 migration is the task.119- Do not treat a successful `terraform apply` as proof by itself; follow with120 state or plan-based verification of the touched addresses.121122## Workflow123124### 1. Classify the ownership boundary125126Establish whether the task is actually:127128- self-managed Gateway Admin API configuration that this skill should own129- Konnect platform configuration that belongs to `terraform-konnect`130- a `decK`-native Gateway workflow that belongs to `deck-gateway`131- gateway behavior or design diagnosis that should be resolved before132 Terraform-specific implementation133134Do not write HCL until that split is clear.135136### 2. Inspect the Terraform shape137138Identify:139140- root and child modules141- provider aliases142- backend or remote state configuration143- variable files and secrets conventions144- existing ownership boundaries for services, routes, plugins, consumers, or145 certificates146147### 3. Confirm the target Gateway surface148149Pin down:150151- which Admin API endpoint is in scope152- which Gateway entities are being managed153- whether the task is create, update, import, or drift correction154155Load `references/provider-and-import.md` when provider inputs, import-first156adoption, or Admin API targeting is the real uncertainty.157158### 4. Choose the narrow implementation path159160Default paths:161162- new managed entity: add HCL in the existing module layout163- existing unmanaged entity: import first, then normalize the HCL164- large-scale file-based Gateway GitOps: consider `deck-gateway` instead of165 forcing Terraform if that matches the user's intent better166167Load `references/entity-patterns.md` when repo ownership shape is the harder168question. Load `references/provider-schema-debugging.md` when resource shape is169the main uncertainty.170171### 5. Author HCL with minimal churn172173- reuse existing variables and locals174- keep names and identifiers stable175- avoid broad refactors while making a narrow Gateway change176- add outputs only when another module or pipeline consumes them177- inspect `terraform providers schema -json` before guessing nested block or178 attribute structure179180### 6. Preview before any apply path181182- run the repo's normal format and validation checks when they exist183- run `terraform validate`184- run `terraform plan`185- import first if the plan would recreate an entity that already exists live186- inspect whether the plan touches only the intended addresses and workspace187188Load `references/plan-safety-and-state.md` when the operator needs a safer189inspection-first path before touching a live Gateway.190191### 7. Execute only when requested192193- Describe the intended live effect before presenting or running194 `terraform apply`.195- Use the same directory, workspace, and variable inputs that produced the196 reviewed plan.197- Run `terraform apply` only when the user explicitly asked to mutate live198 Gateway state.199200### 8. Prove the result with Terraform-native checks201202After any requested `terraform apply`:203204- confirm the touched resource addresses now appear in `terraform state list`205- inspect key addresses with `terraform state show <address>` or the repo's206 normal outputs207- when practical, run a follow-up `terraform plan` and expect no remaining208 intended changes for the affected slice209- call out remaining drift or ownership surprises instead of hiding them behind210 apply success211212### 9. Report config and state impact213214State:215216- which files or modules changed217- which Gateway entities are affected218- whether import is required219- whether the next step is `plan`, `apply`, or external verification220221## Kong-Specific Gotchas222223- Terraform state is not a substitute for checking what the live Gateway224 already has; import matters.225- Recreating existing plugins, services, or routes can cause avoidable226 identifier churn.227- Provider docs and Gateway examples can describe intent, but the Terraform228 provider schema is the authoritative shape for nested HCL.229- Some teams use Terraform for infrastructure but `decK` for Gateway entities;230 preserve the established split if it already exists.231- A self-managed Admin API workflow is not the same as a Konnect control plane232 workflow even if the resource names look similar.233234## Validation Checklist235236Before answering, verify that you can state:237238- why Terraform is the right tool for this repository or request239- which Admin API-backed Gateway surface is in scope240- which module or file owns the resources241- whether import is required242- which preview commands prove the intended change before mutation243- whether provider schema inspection is needed before guessing nested HCL shape244- whether the task stops at HCL authoring or continues to `plan/apply`245- how the touched resource addresses will be proved after apply246- whether `deck-gateway` would be a better fit for the user's intent247248## Handoffs249250- Use `deck-gateway` when the user wants `decK`-native Gateway GitOps or live251 Gateway export/diff workflows.252- Use `terraform-konnect` when the resources actually belong to Konnect.253- Use Gateway or product-specific domain skills when the user first needs254 troubleshooting or design help rather than HCL authoring.