Skip to main content
The Terraform module: the CloudFormation template’s architecture as a reusable module — ECS on EC2 (Graviton), separate detect and rehydrate services and roles, each behind its own Amazon VPC Lattice service with an AWS_IAM auth policy, an optional Aurora vault, an Object Lock audit bucket, CMK-encrypted log groups and optional VPC endpoints. No NAT, no internet route, no shared secret.

When to use it

You manage infrastructure with Terraform and want ECS. Requires Terraform ≥ 1.11 with the hashicorp/aws provider ~> 6.0 and hashicorp/time ~> 0.13. The module has no backend and no provider block — configure both in your root module.

Wire the module into a root module, plan, and stop for review before apply.

Open in Cursor

Usage

Download the module and extract it next to your configuration. Point source at the extracted folder.
Before you apply: subscribe and verify the release, use a VPC with DNS hostnames and DNS support enabled, and check your On-Demand Standard vCPU quota — each detect task fills a c9g.xlarge, so the default needs 8 vCPUs, 12 with rehydration.
main.tf

Calling the services

detect_endpoint and rehydrate_endpoint are https://<service>.vpc-lattice-svcs.<region>.on.aws. For each caller:
  1. Network. Attach lattice_client_security_group_id to the caller (ENI, Lambda, ECS task); its only egress is tcp/443 to the com.amazonaws.<region>.vpc-lattice prefix list. The caller’s VPC must be associated with the service network — the module associates vpc_id when it creates the network; with existing_service_network_arn you manage associations yourself — and listed in allowed_source_vpc_ids (default [vpc_id]).
  2. Identity policy. Attach detect_caller_policy (detect and erasure callers) or rehydrate_caller_policy to the caller’s role. A same-account caller needs this and the service auth policy; either alone is a 403.
  3. Signing. SigV4 with service vpc-lattice-svcs and x-amz-content-sha256: UNSIGNED-PAYLOAD. The tenet-pii-lattice client does this (pip install https://platform.tenetlabs.com/enterprise/current/tenet_pii_lattice.tar.gz); plain botocore SigV4Auth works, no awscrt needed. Reuse connections — each new connection pays a TLS handshake.
Routes are exact and case-sensitive: detect accepts POST /detect, /redact, /deidentify and (for erasure invokers) DELETE /sessions/{session_id}; rehydrate accepts only POST /reidentify. Anything else is a Lattice 404 or 403 and never reaches a task. With require_rehydrate_approval_tag, every /reidentify must come from a session tagged tenet-approval-id — Lattice checks it, because it doesn’t forward session tags. The break-glass role (MFA) may call /reidentify without the tag. Both roles audit to the Object Lock bucket: rehydrate under audit_prefix, detect (erasures) under erasure_audit_prefix. Lattice access logs for both services go to /<name_prefix>/lattice; join them to audit records on upstream_request_id. They record principal tags only on denied requests, so also put the approval id in the role session name. Other accounts: the module creates no RAM shares — share the service network or services yourself and add those roles to the invoker lists. The full model: Rehydration and audit.

Inputs

Outputs: detect_endpoint, rehydrate_endpoint, lattice_client_security_group_id, detect_caller_policy, rehydrate_caller_policy, service_network_arn, detect_service_arn, rehydrate_service_arn, kms_key_arn, audit_bucket, vault_endpoint, detect_task_role_arn, rehydrate_task_role_arn, break_glass_role_arn, cluster_name, deployment_id. Rehydrate outputs are null without rehydration.

Gotchas

  • A plan against a running install should be empty. The module declares the container-definition defaults ECS stores, so an unchanged apply doesn’t roll the services. If a plan replaces both task definitions without an input change, check your module version.
  • Destroy stops on the audit bucket. It has prevent_destroy — it’s an Object Lock record. For a trial: terraform state rm 'module.tenet_pii.aws_s3_bucket.audit[0]' (and its configuration resources) first, and in GOVERNANCE mode empty the bucket yourself. The KMS key is scheduled for deletion with a 30-day window.
  • Aurora with deletion protection fails terraform destroy until you apply with aurora_deletion_protection = false. vault_final_snapshot = true leaves <prefix>-vault-final for you to delete.
  • Destroy ordering is built in. The ASG depends on the VPC endpoints, their security-group rules and the instance role’s ECS attachment, so services and instances are removed while the ECS agent can still reach ECS. If a destroy still sticks, terminate the ASG’s instances, deregister them from the cluster, and run destroy again.
  • A failed apply leaves resources in state; the next apply converges. Nothing is orphaned.
  • The Aurora secret rotation and health-check notes on the CloudFormation page apply here too: tasks read PGUSER/PGPASSWORD at start.