114 lines
3.0 KiB
Terraform
114 lines
3.0 KiB
Terraform
# Phase 6.6: Terraform Module to Create kmsvc Topics
|
|||
|
|
# Topics:
|
||
|
|
# - poimen-memory-dlq
|
||
|
|
# - poimen-memory-metric-dlq
|
||
|
|
#
|
||
|
|
# Usage:
|
||
|
|
# terraform init
|
||
|
|
# terraform apply -target=null_resource.create_kmsvc_topics
|
||
|
|
#
|
||
|
|
# Or add to existing Terraform stack
|
||
|
|
|
||
|
|
terraform {
|
||
|
|
required_version = ">= 1.0"
|
||
|
|
required_providers {
|
||
|
|
null = {
|
||
|
|
source = "hashicorp/null"
|
||
|
|
version = "~> 3.2"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Variables
|
||
|
|
variable "management_service_endpoint" {
|
||
|
|
description = "Management service endpoint (SQS API)"
|
||
|
|
type = string
|
||
|
|
default = "http://localhost:8080"
|
||
|
|
}
|
||
|
|
|
||
|
|
variable "namespace" {
|
||
|
|
description = "Kubernetes namespace for port-forward"
|
||
|
|
type = string
|
||
|
|
default = "sqs"
|
||
|
|
}
|
||
|
|
|
||
|
|
variable "service_name" {
|
||
|
|
description = "Management service name"
|
||
|
|
type = string
|
||
|
|
default = "management-service"
|
||
|
|
}
|
||
|
|
|
||
|
|
# Local function to create topics
|
||
|
|
locals {
|
||
|
|
topics = {
|
||
|
|
"poimen-memory-dlq" = {
|
||
|
|
description = "DLQ for extraction, webhook, and agent failures"
|
||
|
|
fifoQueue = false
|
||
|
|
visibilityTimeoutSeconds = 300
|
||
|
|
messageRetentionPeriodSeconds = 1209600 # 14 days
|
||
|
|
}
|
||
|
|
"poimen-memory-metric-dlq" = {
|
||
|
|
description = "DLQ for metrics persistence failures"
|
||
|
|
fifoQueue = false
|
||
|
|
visibilityTimeoutSeconds = 300
|
||
|
|
messageRetentionPeriodSeconds = 1209600 # 14 days
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Create topics via null_resource + local-exec
|
||
|
|
resource "null_resource" "create_kmsvc_topics" {
|
||
|
|
for_each = local.topics
|
||
|
|
|
||
|
|
provisioner "local-exec" {
|
||
|
|
command = <<-EOT
|
||
|
|
curl -X POST "${var.management_service_endpoint}/v1/queues" \
|
||
|
|
-H "Content-Type: application/json" \
|
||
|
|
-d '{
|
||
|
|
"name": "${each.key}",
|
||
|
|
"fifoQueue": ${each.value.fifoQueue},
|
||
|
|
"visibilityTimeoutSeconds": ${each.value.visibilityTimeoutSeconds},
|
||
|
|
"messageRetentionPeriodSeconds": ${each.value.messageRetentionPeriodSeconds}
|
||
|
|
}' \
|
||
|
|
-w "\nResponse Status: %{http_code}\n" || echo "Topic creation failed or already exists"
|
||
|
|
EOT
|
||
|
|
}
|
||
|
|
|
||
|
|
triggers = {
|
||
|
|
topic_name = each.key
|
||
|
|
endpoint = var.management_service_endpoint
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# Output
|
||
|
|
output "created_topics" {
|
||
|
|
description = "Created kmsvc topics"
|
||
|
|
value = keys(local.topics)
|
||
|
|
}
|
||
|
|
|
||
|
|
output "management_service_endpoint" {
|
||
|
|
description = "Management service endpoint used"
|
||
|
|
value = var.management_service_endpoint
|
||
|
|
}
|
||
|
|
|
||
|
|
# Instructions for local testing
|
||
|
|
output "local_test_commands" {
|
||
|
|
description = "Commands to test locally"
|
||
|
|
value = <<-EOT
|
||
|
|
# Port-forward
|
||
|
|
kubectl -n ${var.namespace} port-forward svc/${var.service_name} 8080:8080 &
|
||
|
|
|
||
|
|
# Create topics
|
||
|
|
terraform apply -target=null_resource.create_kmsvc_topics \
|
||
|
|
-var="management_service_endpoint=http://localhost:8080"
|
||
|
|
|
||
|
|
# List topics
|
||
|
|
curl http://localhost:8080/v1/queues | jq
|
||
|
|
|
||
|
|
# Send test message to DLQ
|
||
|
|
curl -X POST http://localhost:8080/v1/queues/poimen-memory-dlq/messages \
|
||
|
|
-H "Content-Type: application/json" \
|
||
|
|
-d '{"body": "test message"}'
|
||
|
|
EOT
|
||
|
|
}
|