feat(aws): optionally provision managed ElastiCache Redis#186
feat(aws): optionally provision managed ElastiCache Redis#186BimaPangestu28 wants to merge 1 commit into
Conversation
When `var.aws_provision_redis = true` and no external `redis_url` is supplied, the AWS operator module now stands up a single-node ElastiCache cluster (`cache.t3.micro`, Redis 7.1 by default), gates ingress on port 6379 to the ECS service security group, and feeds the resulting endpoint into the ECS container as `REDIS_URL`. External `redis_url` (when non-empty) still takes precedence, so existing deploys that target an outside-of-this-stack Redis keep working without any change. Why --- The bundle's state-redis pack expects a reachable Redis endpoint, but the AWS scaffold only shipped a `modules/redis/main.tf` `null_resource` stub — nothing was ever provisioned. The companion fix in greentic-demo PR #166 drops state-redis from the deep-research demo so the demo path is unblocked, but multi-instance scaling (or any future bundle that legitimately needs a shared state-kv backend) needs a real Redis. This makes that opt-in. Design notes ------------ - Resources live inside the operator module so VPC/subnet/security-group references stay local; no cross-module data flow with the redis stub. - `local.effective_redis_url` prefers an externally-supplied URL over the managed one. That preserves backward compatibility for callers that pass `redis_url` from outside (e.g. an existing ElastiCache in another stack). - Default `count = 0` keeps it strictly opt-in. The existing `modules/redis/main.tf` stub is left in place because tests in `tests/pr04_terraform_pack.rs` assert the file exists; cleanup belongs to a separate change. - `provision_redis` is propagated from the top-level `var.aws_provision_redis` so the deployer Rust side can later wire a `GREENTIC_DEPLOY_TERRAFORM_VAR_AWS_PROVISION_REDIS` env switch without touching this module. Test plan --------- - `terraform init -backend=false && terraform validate` in `fixtures/packs/aws/terraform/` is clean (only pre-existing `data.aws_region.current.name` deprecation warnings). - `cargo test --workspace` is green. - `cargo fmt --all --check` and `cargo clippy --workspace -- -D warnings` are clean. - A live AWS deploy with `TF_VAR_aws_provision_redis=true` will need ~5–10 min extra `terraform apply` for the cluster; not exercised in CI.
|
Heads-up before this lands Live-tested this PR end-to-end. ElastiCache provisioning itself works: with But the In other words: this PR is correct at the infra layer but the demo path doesn't benefit until one of these lands as a follow-up:
Marking |
Summary
Adds opt-in ElastiCache provisioning to the AWS operator module so deploys whose bundles include
state-redisactually get a working Redis endpoint without the user having to stand one up out-of-band.aws_provision_redis(bool, defaultfalse).aws_provision_redis = trueandredis_urlis empty, the operator module creates:aws_elasticache_subnet_groupin the same subnets the ECS service uses.aws_security_groupwith a single ingress on TCP/6379 from the ECS task security group.aws_elasticache_cluster(engineredis,cache.t3.micro× 1, port 6379,default.redis7parameter group).effective_redis_urlpicks the externalredis_urlwhen supplied, otherwise the managed cluster's primary endpoint. The container'sREDIS_URLenv var now reads from it.aws_redis_node_type/aws_redis_engine_versionexposed for future sizing without code change.Why
The bundle's
state-redispack reads its connection string from the runtime secrets and expects a reachable Redis. The AWS scaffold only shipped amodules/redis/main.tfnull_resourcestub — nothing was ever provisioned — so any bundle that resolved tostate-redisat runtime gotsecrets://dev/<tenant>/_/state-redis/redis_urlpointed at a host that didn't exist. Combined with the placeholder-expansion gap inruntime_secrets.rs(see #185), the deep-research demo's button-click flow surfacedpack execution failed: failed to render node input templatebecause state writes silently failed.The companion PR in greentic-demo (greenticai/greentic-demo#166) drops
state-redisfrom the deep-research AWS bundle and unblocks 3Point. This PR is the proper fix for any caller that wants a working state-redis on AWS.Design notes
redis_urlstill wins.effective_redis_url = var.redis_url != "" ? var.redis_url : local.managed_redis_urlpreserves backward compatibility for callers that already point at an outside-of-this-stack Redis.count = 0means existing deploys see no change. A separate Rust-side change can later wire aGREENTIC_DEPLOY_TERRAFORM_VAR_AWS_PROVISION_REDISenv switch when we want the deployer CLI to drive this.modules/redis/main.tf(thenull_resource) stays becausetests/pr04_terraform_pack.rsasserts the file exists in the pack. Cleanup belongs to a separate change.Test plan
terraform init -backend=false && terraform validateinfixtures/packs/aws/terraform/— clean (only pre-existingdata.aws_region.current.namedeprecation warnings).cargo test --workspace— 0 failures.cargo fmt --all --check— clean.cargo clippy --workspace -- -D warnings— clean.TF_VAR_aws_provision_redis=true. Expect: terraform apply takes ~5–10 min extra for the cluster,REDIS_URLenv on the ECS task points at the cluster endpoint, state-redis pack connects, deep-research button-click flow works end-to-end. Not exercised in CI.Out of scope
modules/redis/main.tfstub.aws_provision_redisfrom the command line.