Provision and configure required infrastructure in GCP.
In order to execute this provisioning, you need to:
- Create GCP clean project
- Create service account, with at least roles:
Editor
andIAM Security Admin
- Add and download json key
Environment variables expected to be set:
GOOGLE_APPLICATION_CREDENTIALS
path to json key fileTF_VAR_project
GCP project idTF_VAR_dns_zone
DNS zone, used to create records with Cloud DNS. Default:nachor22.tk
- Terraform installed
- Above env vars defined
- Run
terraform init
- Run
terraform apply
- When you are done
terraform destroy
- Load Balancer IP
- Nameservers to point your DNS Zone
Installation, configuration, etc inside the instances is done using user-data at launch.
The app is deployed using Docker.
Docker image was built (see data/Dockerfile
) and pushed to https://hub.docker.com/r/nachor22/toggl_api/
Autoscale is configured based on CPU utilization.
Region us-central1
and zone us-central1
are used by default to create resources.
Beacuse of the IN_USE_ADDRESS
quota that limits to 4 IPs, the consul cluster is created in zone us-east1-b
GCP apis cloudresourcemanager.googleapis.com
iam.googleapis.com
compute.googleapis.com
dns.googleapis.com
are required to be enabled. Since it's an async action, it may fail the first time. You can enable them manually.
Postgres 9.6 deployed using Docker.
Creates DB, user and pass for api.
Accesible via IP (terraform output) or domain (toggl_test.example.com)\
- Static content served from bucket
/
redirects to/index.html
/api/*
routed to API servers/ui/
routed to Consul UI
Consul cluster with 3 servers.
DB and API instances run client agents and register services with healthchecks.
Members join the cluster using Cloud Auto-Join
Creates toggl_test.{dns_zone} record, pointing to the Load Balancer IP.
Set TF_VAR_dns_zone
and point your zone NS to the shown in outputs.
By default toggl_test.nachor22.tk
Many decisions or configurations where made considering this is a test and in order to keep it simple.