Auto-generated
This page is generated by terraform-docs at build time from the infra/ repo. Do not edit manually.
Admin Portal (cha)¶
ECS service for the internal admin application (cookiehub-com/admin, Next.js),
deployed behind the PUBLIC ALB on its own hostname (cha.authenticate-oidc action in front of it (IS-36). Access control is SSO
at the load balancer, not the network layer: the VPN route was dropped
because it blocks mobile access. The app additionally keeps its own
password + 2FA login against the core database.
Mirrors the core-api / core-portal service shape: own ECR repository, bridge-mode EC2 task with dynamic port mapping, target group on traffic-port, host-header listener rule, Route53 alias, GitHub Actions OIDC deploy role.
SSO (Entra ID)¶
The ALB speaks OIDC directly to the Entra tenant — no Cognito in between.
One app registration per environment (Web platform) with redirect URI
https://<hostname>/oauth2/idpresponse and "Assignment required" ON so only
the assigned staff group(s) get through. The tenant and client ID are plain
Terraform inputs (PR-reviewed); the client secret is read from the SSM
SecureString this module creates as a placeholder — set the real value, then
re-apply so the listener rule picks it up. ALB health checks hit the target
directly and bypass the OIDC action.
Secrets and optional integrations¶
Every credential is an SSM SecureString created with a placeholder value and
ignore_changes = [value]. The optional integrations (Borgun payments,
ChartMogul metrics, DK Plus, SMTP mail) are wired into the task ONLY when enabled: the
app treats an unset variable as "feature off" but would treat a placeholder
string as a real credential and fail at the point of use.
Database connectivity rides on the ECS→3306 ingress rule the core-api module already adds to the MariaDB security group (same ECS security group, same cluster), so this module manages no security-group rules.
Deploys vs. Terraform¶
Application deploys register new task-definition revisions (new image tag)
and update the service; Terraform owns the task shape (CPU/memory, env,
secrets, log config). The service tracks the newest ACTIVE revision of the
family, so a deploy is never rolled back by an apply, and a Terraform change
to the task rolls out immediately under whatever image_tag says.
Requirements¶
| Name | Version |
|---|---|
| terraform | >= 1.6.0 |
| aws | ~> 6.0 |
Providers¶
| Name | Version |
|---|---|
| aws | ~> 6.0 |
Modules¶
No modules.
Resources¶
| Name | Type |
|---|---|
| aws_cloudwatch_log_group.admin_portal | resource |
| aws_ecr_lifecycle_policy.admin_portal | resource |
| aws_ecr_repository.admin_portal | resource |
| aws_ecs_service.admin_portal | resource |
| aws_ecs_task_definition.admin_portal | resource |
| aws_iam_policy.read_ssm | resource |
| aws_iam_role.execution_role | resource |
| aws_iam_role.gh_deploy | resource |
| aws_iam_role.task_role | resource |
| aws_iam_role_policy.gh_deploy | resource |
| aws_iam_role_policy_attachment.execution_read_ssm | resource |
| aws_iam_role_policy_attachment.execution_role_policy | resource |
| aws_lb_listener_rule.admin_portal | resource |
| aws_lb_target_group.admin_portal | resource |
| aws_route53_record.admin_portal | resource |
| aws_ssm_parameter.secret | resource |
| aws_ecs_task_definition.admin_portal | data source |
| aws_iam_openid_connect_provider.github | data source |
| aws_iam_policy_document.ecs_assume_role | data source |
| aws_ssm_parameter.oidc_client_secret | data source |
Inputs¶
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| alb_dns_name | DNS name of the public ALB (for the Route53 alias target) | string |
n/a | yes |
| alb_https_listener_arn | ARN of the public ALB HTTPS listener the SSO-gated host rule is attached to | string |
n/a | yes |
| alb_zone_id | Canonical hosted zone ID of the public ALB (for the Route53 alias) | string |
n/a | yes |
| base_tags | Base tags applied to all resources | map(string) |
n/a | yes |
| borgun_enabled | Wire the Borgun/Teya RPG payment gateway (BORGUN_URL, BORGUN_TRANSACTION_TYPE and both private keys from SSM) into the task. Off, the invoice page hides its Pay Now button and nothing else changes. | bool |
false |
no |
| borgun_transaction_type | Borgun/Teya RPG transaction type | string |
"Sale" |
no |
| borgun_url | Borgun/Teya RPG API base URL. Keep the test endpoint until the environment is meant to move real money. | string |
"https://test.borgun.is/rpg/api/" |
no |
| cdn_default | Base URL of the default public CDN host, the same value core-api's cdn_default carries. The admin shows reseller logos from {cdn_default}/reseller-logos/{name} (CH-251), where core-api stores them. Not defaulted: stage and prod differ. Empty leaves CDN_DEFAULT out of the task, and the reseller-request screen then names the logo file instead. |
string |
"" |
no |
| chartmogul_enabled | Wire the ChartMogul API key from SSM into the task for the dashboard metrics box. Off, the box reports 'not connected' and nothing else changes. | bool |
false |
no |
| cluster_name | ECS cluster name to deploy the service into (the core cluster) | string |
n/a | yes |
| container_port | Port the container listens on (Next.js next start honours PORT) |
number |
3000 |
no |
| deployment_maximum_percent | ECS rolling-deploy maximum percent. Default 200. Pair with minimum_healthy_percent=0 and set to 100 for stop-before-start on capacity-constrained instances. | number |
200 |
no |
| deployment_minimum_healthy_percent | ECS rolling-deploy minimum healthy percent. Default 100 (zero-downtime start-before-stop). Set to 0 where the cluster cannot fit a second task alongside co-tenants, allowing stop-before-start. | number |
100 |
no |
| desired_count | Desired number of ECS tasks. 0 keeps the service, target group, rule and task definition defined with nothing running. | number |
1 |
no |
| dkplus_enabled | Wire the DK Plus API token (DKPLUS_API_TOKEN) from SSM into the task. Set the real value of /core/ |
bool |
false |
no |
| entra_tenant_id | Entra ID (Azure AD) tenant ID. The v2.0 issuer, authorization and token endpoints are derived from it. | string |
n/a | yes |
| environment | Environment name (used in the SSM parameter path /core/ |
string |
n/a | yes |
| github_oidc_refs | Subject conditions for the deploy role's trust policy, each appended to repo:<org>/<repo>:. A list rather than a string because a job that declares an environment: presents environment:<name> as its subject instead of ref:<git ref>, so a role fronting a gated production deploy has to trust both forms or the assume-role fails. Stage deploys present ref:refs/heads/main (a workflow_run job always reports the default branch); prod release deploys present ref:refs/tags/v*. |
list(string) |
[ |
no |
| github_repo | GitHub repository (org/repo) allowed to push images and deploy via OIDC | string |
"cookiehub-com/admin" |
no |
| github_repo_immutable | The repository's immutable-ID OIDC sub prefix (org@org_id/repo@repo_id) for repos created since GitHub's immutable-ID rollout. Read it from gh api repos/<org>/<repo>/actions/oidc/customization/sub. Empty skips the extra trust entry; cookiehub-com/admin sends the classic form. |
string |
"" |
no |
| health_check_matcher | HTTP codes the ALB health check accepts. The liveness probe answers a plain 200; anything else (a login redirect, a 5xx) should mark the target unhealthy. | string |
"200" |
no |
| health_check_path | ALB health-check path. The app's liveness probe is /api/health (app/api/health/route.ts): answers 200 with no session and no database, and proxy.ts lets it through without the login redirect. | string |
"/api/health" |
no |
| hostname | Public-facing hostname (e.g. 'cha.stage.cookiehub.net'). Must be covered by a certificate already on the HTTPS listener — this module attaches none. Also the host of the OIDC redirect URI, https:// |
string |
n/a | yes |
| image_tag | ECR image tag Terraform's task-definition revision references. Deploys register their own revisions via the GitHub OIDC role and the service follows the newest one, so this only matters for the first deploy and for revisions Terraform registers after a task change. | string |
"latest" |
no |
| listener_rule_priority | Priority of the host-header listener rule. Null lets the provider pick the next free priority, which is fine for a host-only rule that shares its hostname with nothing else. | number |
null |
no |
| log_retention_days | CloudWatch Logs retention for the task's log group | number |
30 |
no |
| mail_driver | Outbound mail driver: 'smtp' delivers through SES and wires MAIL_HOST/PORT/ENCRYPTION plus the SMTP credentials from SSM into the task; 'log' writes the message to the task log and sends nothing. | string |
"log" |
no |
| mail_encryption | SMTP encryption mode; 'tls' is what SES requires (used only when mail_driver = smtp) | string |
"tls" |
no |
| mail_from_address | From address on outbound mail | string |
"support@cookiehub.com" |
no |
| mail_from_name | From display name on outbound mail | string |
"CookieHub" |
no |
| mail_host | SES SMTP endpoint (used only when mail_driver = smtp) | string |
"email-smtp.eu-central-1.amazonaws.com" |
no |
| mail_port | SES SMTP port: 587 is STARTTLS, 465 implicit TLS (used only when mail_driver = smtp) | number |
587 |
no |
| name_prefix | Prefix for resource names (e.g. 'stage-euc1-core') | string |
n/a | yes |
| oidc_client_id | Application (client) ID of the Entra app registration for this environment's hostname. The matching client secret is read from the SSM parameter /core/ |
string |
n/a | yes |
| oidc_session_timeout | Lifetime in seconds of the ALB authentication session cookie before the user is sent back to Entra. Default 8 hours. | number |
28800 |
no |
| region | AWS region | string |
n/a | yes |
| task_cpu | CPU units for the ECS task | number |
512 |
no |
| task_memory | Memory in MB for the ECS task (hard limit) | number |
512 |
no |
| vpc_id | VPC ID (used for the ALB target group) | string |
n/a | yes |
| zone_id | Route53 hosted zone ID the hostname is created in | string |
n/a | yes |
Outputs¶
| Name | Description |
|---|---|
| ecr_repository_url | ECR repository URL for admin-portal |
| gh_deploy_role_arn | ARN of the GitHub Actions OIDC deploy role for cookiehub-com/admin |
| oidc_redirect_uri | Redirect URI to register on the Entra app registration for this environment |
| service_name | ECS service name (for monitoring alarms) |
| ssm_parameter_names | SSM SecureString parameter names created as placeholders, keyed by secret. Set the real values out of band. |
| target_group_arn | ARN of the ALB target group |
| target_group_arn_suffix | ARN suffix of the ALB target group (TargetGroup CloudWatch dimension), for monitoring alarms |