An example collaborative microservices architecture for Heroku, based on two Terraform patterns:
- Confluent's Terraform config with S3 state storage
- Deploy Heroku apps from pipelines using Terraform
Terraform config | Web UI | API |
---|---|---|
infrastructure (this repo) | front-end app | backend app |
- Heroku
- install command-line tools (CLI)
- an account
- a team
- install git
- install Terraform
- install AWS CLI
- with Homebrew on macOS:
brew install awscli
- with Homebrew on macOS:
- if adapting this example for your own project, then use your own fork of this repo wherever this repo's URL appears
- instead of
https://github.com/mars/tinyrobot-science-terraform
usehttps://github.com/$GITHUB_USERNAME/tinyrobot-science-terraform
- instead of
Setup Terraform's remote state store with Amazon S3 & DynamoDB, so that team members may collaborate free of conflicts:
-
Create AWS IAM user with AmazonS3FullAccess & AmazonDynamoDBFullAccess
-
Run
aws configure
to set the key & secret credentials for that new IAM user- ensure Default region name is set to same as the AWS provider region in other environments
-
Run the following shell commands:
βοΈ If adapting this example for your own project, first set your own unique names/values for the resources in
dev-tfstate/main.tf
&dev/backend.tf
git clone https://github.com/mars/tinyrobot-science-terraform cd tinyrobot-science-terraform/environments/dev-tfstate terraform init terraform apply git commit terraform.tfstate* -m 'Terraform S3 backend state'
-
Create AWS IAM user with full access to the bucket named in
dev-tfstate/main.tf
-
Run
aws configure
to set the key & secret credentials for that new IAM user -
Run the following shell commands:
git clone https://github.com/mars/tinyrobot-science-terraform cd tinyrobot-science-terraform/
Once the setup is complete, we'll now switch to the application's Terraform environment, which will use the remote state store for persistence, but is otherwise independent:
-
Set Heroku auth as local environment variables:
heroku authorizations:create --description tinyrobot-science --short export HEROKU_API_KEY=xxxxx
-
Identify the build pipeline for each app. Pipeline UUIDs can be found by visiting each pipeline used to build the slugs in the Heroku Dashboard and copying them from the page address/URL:
export \ BUILD_PIPELINE_API=2f557b76-d685-452a-8651-9a6295a2a032 \ BUILD_PIPELINE_WEB_UI=26a3ecbf-8188-43ae-b0fe-be2d9e9fe26f
-
Setup the unique identifiers for the apps. The team name & DNS host names must already exist:
βοΈ Modify these Heroku team & DNS host names for your own unqiue deployment. Host names must be at a domain that is registered & under your control.
export \ TF_VAR_heroku_team_name=tinyrobot \ TF_VAR_api_host_name=api.tinyrobot.science \ TF_VAR_ui_host_name=tinyrobot.science
-
Provision the configuration:
cd environments/dev terraform init # Capture the pipelines' current Slug IDs source ../../bin/pipeline-slug-ids terraform apply
-
Output includes the DNS CNAME targets for the host names. To resolve them, please set these in DNS for each corresponding host name.
β±π Automated SSL/TLS certficates for custom domains may take a few minutes to provision or more if there is a DNS misconfiguration.
β οΈ Set low TTL values (less than five minutes) on these DNS records to avoid delays if problems are encountered.