Skip to main content

Terraform variables

Both topologies read their settings from terraform.tfvars. The example files infrastructure/microservices/terraform/aws/terraform.tfvars.example and infrastructure/monolith/terraform/aws-monolith/terraform.tfvars.example show the values you must provide.

# Microservices
cd infrastructure/microservices/terraform/aws
cp terraform.tfvars.example terraform.tfvars

# Monolith
cd infrastructure/monolith/terraform/aws-monolith
cp terraform.tfvars.example terraform.tfvars

terraform.tfvars is gitignored because it contains secrets. Never commit it.

Required variables​

These variables have no default and the stack cannot be applied without them.

VariableExample valueWhy it is required
db_passwordchange-meMaster password for the RDS PostgreSQL instances. Used by Terraform to create the databases and by the backend tasks to connect.
acm_certificate_arnarn:aws:acm:us-east-1:...The ALB listeners on 443 and 8443 need this imported server certificate. Generate it with the certificate scripts and copy the ARN.
mtls_trust_bundle_path../../../resources/fnmt-client-trust-bundle.pemLocal path to the FNMT CA bundle. Terraform uploads it to S3 and attaches it to the ALB trust store used by the mTLS listener.
backend_project_dir/path/to/model-city-back-endAbsolute path to the Maven backend project. The deploy script reads this from Terraform outputs and builds Docker images from it.
frontend_project_dir/path/to/model-city-front-endAbsolute path to the Next.js frontend project. The deploy script reads this from Terraform outputs and builds the frontend Docker image.

Common overrides​

These variables have defaults but you will usually override them per city.

VariableDefaultWhy override it
aws_regionus-east-1AWS region where everything is created. ACM certificates and ALBs must be in the same region.
domainmodel-city.example.orgPublic domain served by the ALB. Must match the ACM certificate and the DNS record you point at the ALB.
auth0_domainunir-software-engineering.eu.auth0.comAuth0 tenant domain (no protocol). Used by the Spring Security OAuth2 resource server and the Next.js frontend.
auth0_audiencehttps://model-city.aranjuez.esAuth0 API audience identifier used to validate JWT access tokens.
monolith_db_namemodelcityMonolith only. Name of the single logical database created on the shared RDS instance.

Backend runtime config​

VariableDefaultWhy it is needed
auth0_db_connectionUsername-Password-AuthenticationAuth0 database connection used by the core vertical when provisioning local users.
mail_hostsmtp.gmail.comSMTP server host for transactional emails sent by the core vertical.
mail_port587SMTP server port (587 is STARTTLS).
mail_city_nameAyuntamiento de Model CityDisplay name of the city/authority in outgoing emails.
mail_addressPlaza Mayor, 1. 00000 Model CityPostal address shown in outgoing emails.

Secrets and integrations​

These variables are optional in the sense that the stack will deploy if they are empty, but the matching features will not work.

VariableWhy it is needed
auth0_mgmt_client_id / auth0_mgmt_client_secretAuth0 Management API credentials used by the core vertical to invite back-office users and agents.
auth0_client_id / auth0_client_secretAuth0 application credentials for the Next.js frontend.
mail_username / mail_passwordSMTP credentials for sending transactional emails.
stripe_secret_keyStripe secret key used by the leisure and mobility verticals for payments.
stripe_publishable_keyStripe publishable key embedded in the Next.js bundle at build time.
stripe_webhook_secret_leisure / stripe_webhook_secret_mobilityStripe webhook endpoint secrets used to validate incoming webhooks.
stripe_parking_product_idStripe product identifier used by the mobility parking flow.
nextauth_secretSession encryption secret for NextAuth.js / Auth0 SDK. Generate with openssl rand -base64 32.
gemini_api_keyGoogle Gemini API key used by the Next.js frontend for server-side AI features.

Auth0 roles and certificate secrets​

VariableWhy it is needed
auth0_backoffice_role_idRole assigned by the core vertical when inviting back-office users.
auth0_operator_role_idRole assigned when inviting operators.
auth0_mobility_agent_role_idRole assigned when inviting mobility agents.
cert_dni_pepperSecret pepper used when hashing DNI values during the FNMT certificate verification flow.
cert_token_secretSecret used to sign certificate-verification tokens.

Other variables with defaults​

These are defined in variables.tf and can be left alone for a first AWS Academy deployment.

VariableDefaultPurpose
envacademyName suffix for most resources.
projectmodelcityPrefix for resource names and ECR repository paths.
lab_role_nameLabRolePre-existing IAM role used as ECS execution and task role. See AWS deployment.
vpc_cidr10.20.0.0/16VPC CIDR block.
public_subnet_cidrs["10.20.0.0/24", "10.20.1.0/24"]Public subnet CIDRs.
private_subnet_cidrs["10.20.10.0/24", "10.20.11.0/24"]Private subnet CIDRs.
db_engine_version16.14PostgreSQL engine version for RDS.
db_instance_classdb.t3.microRDS instance class.
db_allocated_storage20Allocated storage in GiB.
db_usernamemodelcityMaster database username.
image_taglatestDocker image tag pushed and deployed.
create_elasticachetrueCreate the ElastiCache Valkey replication group. Set to false if ElastiCache is not available in the lab session.
monolith_cpu1024Monolith only. Fargate CPU units for the monolith task.
monolith_memory2048Monolith only. Fargate memory (MiB) for the monolith task.

Reading the variables from the deploy scripts​

Both deploy scripts read backend_project_dir and frontend_project_dir from Terraform outputs so they do not need to parse terraform.tfvars themselves:

cd "$TERRAFORM_DIR"
BACKEND_DIR=$(terraform output -raw backend_project_dir 2>/dev/null || true)
FRONTEND_DIR=$(terraform output -raw frontend_project_dir 2>/dev/null || true)

You can override those paths at runtime with environment variables if you want to build a different checkout without changing the Terraform state:

export BACKEND_PROJECT_DIR=/path/to/backend
export FRONTEND_PROJECT_DIR=/path/to/frontend
./deploy.sh