Skip to content

Terraforming πŸŒ±β†’πŸ€–πŸ”¬ tinyrobot.science

Notifications You must be signed in to change notification settings

mars/tinyrobot-science-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Terraforming πŸŒ±β†’πŸ€–πŸ”¬ tinyrobot.science

An example collaborative microservices architecture for Heroku, based on two Terraform patterns:

Part of a reference suite

Terraform config Web UI API
infrastructure (this repo) front-end app backend app

Requirements

  • Heroku
  • install git
  • install Terraform
  • install AWS CLI
    • with Homebrew on macOS: brew install awscli
  • 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 use https://github.com/$GITHUB_USERNAME/tinyrobot-science-terraform

Setup

Initial

Setup Terraform's remote state store with Amazon S3 & DynamoDB, so that team members may collaborate free of conflicts:

  1. Create AWS IAM user with AmazonS3FullAccess & AmazonDynamoDBFullAccess

  2. 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
  3. 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'

Additional collaborators

  1. Create AWS IAM user with full access to the bucket named in dev-tfstate/main.tf

  2. Run aws configure to set the key & secret credentials for that new IAM user

  3. Run the following shell commands:

    git clone https://github.com/mars/tinyrobot-science-terraform
    cd tinyrobot-science-terraform/

Usage

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.

About

Terraforming πŸŒ±β†’πŸ€–πŸ”¬ tinyrobot.science

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages