- sqs-consumer: new Go binary v1.2 with tokenManager (auto-login /auth/login, 5min cache, retry on 401) - console: add MQ/KW triggers UI (mqtriggers.go, kwtriggers.go, mq.js) - console: update python-env image to v1.1 (boto3+psycopg2+requests) - weather-demo: fix consumer/main.py (Flask Request.get_json instead of dict access) - weather-demo: fix fetcher/main.py (boto3 SQS publish, 5 cities) - weather-demo: update main.tf (python-env v1.1, deploy_type=literal) - python-env: add psycopg2-binary to Dockerfile (v1.1) - terraform provider: client auth fix
144 lines
5.0 KiB
Terraform
144 lines
5.0 KiB
Terraform
terraform {
|
|
required_providers {
|
|
fission = {
|
|
source = "nail/fission"
|
|
version = "~> 0.2.0"
|
|
}
|
|
}
|
|
}
|
|
|
|
provider "fission" {
|
|
kubeconfig_path = var.kubeconfig_path
|
|
namespace = var.namespace
|
|
}
|
|
|
|
# ── Переменные ───────────────────────────────────────────────────────
|
|
|
|
variable "kubeconfig_path" {
|
|
default = "/home/naeel/.kube/config"
|
|
description = "Путь к kubeconfig."
|
|
}
|
|
|
|
variable "namespace" {
|
|
default = "fission-weather"
|
|
description = "Namespace для функций и триггеров."
|
|
}
|
|
|
|
variable "sqs_access_key" {
|
|
sensitive = true
|
|
description = "SQS Access Key."
|
|
}
|
|
|
|
variable "sqs_secret_key" {
|
|
sensitive = true
|
|
description = "SQS Secret Key."
|
|
}
|
|
|
|
variable "pg_dsn" {
|
|
sensitive = true
|
|
description = "PostgreSQL DSN для записи метрик. Пример: postgresql://user:pass@host:5432/db?sslmode=disable"
|
|
}
|
|
|
|
# ── IoT-устройство — виртуальная метеостанция ────────────────────────
|
|
|
|
resource "fission_iot_device" "weather_station" {
|
|
name = "weather-station"
|
|
device_id = "weather-station-01"
|
|
namespace = "sless"
|
|
metadata = {
|
|
type = "weather-station"
|
|
location = "multi-city"
|
|
cities = "Moscow,London,Paphos,Ulyanovsk,Santiago"
|
|
}
|
|
}
|
|
|
|
# ── Python environment ───────────────────────────────────────────────
|
|
|
|
resource "fission_environment" "python" {
|
|
name = "weather-python"
|
|
image = "naeel/fission-python-env:v1.1"
|
|
version = 2
|
|
namespace = var.namespace
|
|
}
|
|
|
|
# ── Пакет: fetcher ───────────────────────────────────────────────────
|
|
|
|
resource "fission_package" "fetcher" {
|
|
name = "weather-fetcher-pkg"
|
|
environment = fission_environment.python.name
|
|
namespace = var.namespace
|
|
source_dir = "${path.module}/fetcher"
|
|
deploy_type = "literal"
|
|
}
|
|
|
|
# ── Пакет: consumer ──────────────────────────────────────────────────
|
|
|
|
resource "fission_package" "consumer" {
|
|
name = "weather-consumer-pkg"
|
|
environment = fission_environment.python.name
|
|
namespace = var.namespace
|
|
source_dir = "${path.module}/consumer"
|
|
deploy_type = "literal"
|
|
}
|
|
|
|
# ── Функция: fetcher (читает Open-Meteo, пишет в SQS) ───────────────
|
|
# Open-Meteo: бесплатный API без ключа. https://open-meteo.com
|
|
resource "fission_function" "fetcher" {
|
|
name = "weather-fetcher"
|
|
environment = fission_environment.python.name
|
|
namespace = var.namespace
|
|
package_name = fission_package.fetcher.name
|
|
entrypoint = "main"
|
|
# Env vars задаются через K8s Secret weather-fetcher-env (namespace: var.namespace)
|
|
# Ключи: SQS_ACCESS_KEY, SQS_SECRET_KEY
|
|
}
|
|
|
|
# ── CRON trigger: каждые 10 минут ────────────────────────────────────
|
|
|
|
resource "fission_cron_trigger" "fetcher" {
|
|
name = "weather-cron"
|
|
function = fission_function.fetcher.name
|
|
namespace = var.namespace
|
|
cron = "*/10 * * * *"
|
|
}
|
|
|
|
# ── Функция: consumer (читает из SQS, пишет в PG) ────────────────────
|
|
|
|
resource "fission_function" "consumer" {
|
|
name = "weather-consumer"
|
|
environment = fission_environment.python.name
|
|
namespace = var.namespace
|
|
package_name = fission_package.consumer.name
|
|
entrypoint = "main"
|
|
# Env vars: PG_DSN задаётся через K8s Secret weather-consumer-env
|
|
}
|
|
|
|
# ── MQ trigger: SQS queue → consumer function ────────────────────────
|
|
|
|
resource "fission_mq_trigger" "weather" {
|
|
name = "weather-mq"
|
|
function = fission_function.consumer.name
|
|
namespace = var.namespace
|
|
queue = "weather-data"
|
|
access_key = var.sqs_access_key
|
|
secret_key = var.sqs_secret_key
|
|
sqs_endpoint = "http://shared-sqs.shared-sqs.svc.cluster.local:4100"
|
|
}
|
|
|
|
# ── Outputs ──────────────────────────────────────────────────────────
|
|
|
|
output "iot_device_phase" {
|
|
value = fission_iot_device.weather_station.phase
|
|
description = "Статус IoT-устройства weather-station."
|
|
}
|
|
|
|
output "iot_mqtt_username" {
|
|
value = fission_iot_device.weather_station.mqtt_username
|
|
description = "MQTT username для weather-station."
|
|
}
|
|
|
|
output "iot_topic_prefix" {
|
|
value = fission_iot_device.weather_station.topic_prefix
|
|
description = "MQTT topic prefix для weather-station."
|
|
}
|