Skip to content

A rate-limiting proxy to Heroku Platform API (intended to allow testing client rate limits without harming the Platform API)

License

Notifications You must be signed in to change notification settings

mars/terraform-api-rate-limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A rate-limiting proxy to Heroku Platform API

Terraform as a Heroku app.

Run Terraform CLI in the cloud:

heroku run terraform apply

🔬🚧 This is a community proof-of-concept, MIT license, provided "as is", without warranty of any kind.

🌲🔥 To enable Heroku Postgres as the Terraform backend, this app uses the terraform binary built from an unmerged pull request to Terraform (see: hashicorp/terraform #19070).

Set-up

Create Heroku Team

Terraform works best with Heroku when contained by a team.

▶️ Create a team or use an existing team.

Create Heroku "Machine" Account

Terraform uses an authorization token (secret key) access the Heroku API.

Terraform's access can be isolated from your main user account by creating a separate Heroku account & authorization token, and inviting the new account to the team.

▶️ Sign-up for another account. Set the first & last name to "Terraform" & "app"

▶️ Create an Authorization for Terraform. Set its description to terraforming-app. Note the generated Authorization token.

▶️ Invite the new account to the team. Set its role to admin, so that it can fully manage apps and other resources.

Deploy Terraform for Team

Create a new app for Terraform by clicking the "Deploy" button below. On the form that appears, set:

  • App name to something like teamname-terraform
  • App owner to the team name created above
  • HEROKU_API_KEY to the Authorization token generated above
  • HEROKU_EMAIL to the email of the separate account created above

Deploy to Heroku

Connect source code

Create a local working copy of the Heroku app, to begin committing & applying Terraform configurations.

✏️ Replace $APP_NAME with the value of the App name created above, like teamname-terraform

git clone https://github.com/mars/terraforming-app.git $APP_NAME
cd $APP_NAME
heroku git:remote --app $APP_NAME

Usage

Once set-up is complete, you can begin using Terraform!

Create your Terraform config

Use the Heroku provider and others to build-up configuration in *.tf files.

The included main.tf is required to deploy successfully. The buildpack will not work without main.tf. You can replace its content as needed.

Push your changes

git add .
git commit -m 'Initial configuration'
git push heroku master

⏳ Wait for the push to complete.

Run Terraform

Use interactively in one-off dynos:

heroku run terraform plan
heroku run terraform apply

Dev Notes 📓

Manual setup

export APP_NAME=my-app
git clone https://github.com/mars/terraforming-app
cd terraforming-app/

heroku create $APP_NAME --buildpack mars/terraforming
heroku addons:create heroku-postgresql

# Use our fork of Terraform that supports Postgres backend
# https://github.com/hashicorp/terraform/pull/19070
# 
heroku config:set TERRAFORM_BIN_URL=https://terraforming-buildpack.s3.amazonaws.com/terraform_0.11.9-pg.02_linux_amd64.zip

# Set credentials for the Terraform Heroku provider
heroku config:set HEROKU_API_KEY=xxxxx HEROKU_EMAIL=x@example.com

# Set Terraform input variables
heroku config:set TF_VAR_example_app_name=$APP_NAME-example

git push heroku master

Run Terraform locally w/ Heroku Postgres backend

🌲🔥 Requires local terraform binary built from the Postgres backend PR (hashicorp/terraform #19070).

# First-time for each terminal
export DATABASE_URL=`heroku config:get DATABASE_URL`
$GOPATH/src/github.com/hashicorp/terraform/pkg/darwin_amd64/terraform init -backend-config="conn_str=$DATABASE_URL"

# Continue using Terraform with the Heroku app's Postgres backend
$GOPATH/src/github.com/hashicorp/terraform/pkg/darwin_amd64/terraform plan
$GOPATH/src/github.com/hashicorp/terraform/pkg/darwin_amd64/terraform apply

About

A rate-limiting proxy to Heroku Platform API (intended to allow testing client rate limits without harming the Platform API)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published