diff --git a/.profile b/.profile index 1eb29e4..b20d3f5 100644 --- a/.profile +++ b/.profile @@ -9,3 +9,7 @@ then cat terraform_init_output.log exit 1 fi + +# Ensure the workspace exists +TERRAFORM_WORKSPACE_NAME="${TERRAFORM_WORKSPACE_NAME:-default}" +terraform workspace new $TERRAFORM_WORKSPACE_NAME diff --git a/.terraform.d/plugins/darwin_amd64/terraform-provider-heroku_v1.8.0-dev20190216H00-dev_x4 b/.terraform.d/plugins/darwin_amd64/terraform-provider-heroku_v1.8.0-dev20190216H00-dev_x4 new file mode 100755 index 0000000..6e70874 Binary files /dev/null and b/.terraform.d/plugins/darwin_amd64/terraform-provider-heroku_v1.8.0-dev20190216H00-dev_x4 differ diff --git a/.terraform.d/plugins/linux_amd64/terraform-provider-heroku_v1.8.0-dev20190216H00-dev_x4 b/.terraform.d/plugins/linux_amd64/terraform-provider-heroku_v1.8.0-dev20190216H00-dev_x4 new file mode 100755 index 0000000..42a5277 Binary files /dev/null and b/.terraform.d/plugins/linux_amd64/terraform-provider-heroku_v1.8.0-dev20190216H00-dev_x4 differ diff --git a/README.md b/README.md index eef2f1c..cfffc9a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ Terraforming 🌱 Heroku app =========================== -[Terraform](https://www.terraform.io/) as a [Heroku](https://www.heroku.com/) app. +[Terraform](https://www.terraform.io/) [0.12 Beta 1](https://www.hashicorp.com/blog/announcing-terraform-0-1-2-beta1) as a [Heroku](https://www.heroku.com/) app. + +Includes a [0.12 dev snapshot](http://terraform-0.12.0-dev-snapshots.s3-website-us-west-2.amazonaws.com/terraform-provider-heroku/) of [Heroku Provider version 1.8.0](https://www.terraform.io/docs/providers/heroku/index.html). Run Terraform CLI in the cloud: @@ -11,7 +13,7 @@ heroku run terraform apply πŸ”¬πŸš§ This is a community proof-of-concept, [MIT license](LICENSE), provided "as is", without warranty of any kind. -🌲πŸ”₯ To enable the [Postgres backend](https://github.com/mars/terraform/blob/v0.11.9-pg.02/website/docs/backends/types/pg.html.md) for Terraform, this app uses the `terraform` binary built from an unmerged pull request to Terraform (see: [hashicorp/terraform #19070](https://github.com/hashicorp/terraform/pull/19070)). +🌲πŸ”₯ To enable the [Postgres backend](https://github.com/mars/terraform/blob/postgres-backend/website/docs/backends/types/pg.html.md) for Terraform, this app uses the [`terraform` 0.12 Beta binary](https://releases.hashicorp.com/terraform/0.12.0-beta1/), which includes this new feature (see: [hashicorp/terraform #19070](https://github.com/hashicorp/terraform/pull/19070)). Set-up ------ @@ -170,10 +172,10 @@ cd terraforming-app/ heroku create $APP_NAME --buildpack mars/terraforming heroku addons:create heroku-postgresql -# Use our fork of Terraform that supports Postgres backend +# Use 0.12 Beta 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 +heroku config:set TERRAFORM_BIN_URL=https://releases.hashicorp.com/terraform/0.12.0-beta1/terraform_0.12.0-beta1_linux_amd64.zip # Set credentials for the Terraform Heroku provider heroku config:set HEROKU_API_KEY=xxxxx HEROKU_EMAIL=x@example.com @@ -186,14 +188,16 @@ git push heroku master ### Run Terraform locally w/ Heroku Postgres backend -🌲πŸ”₯ Requires local `terraform` binary built with the [pre-release Postgres backend](https://github.com/mars/terraform/releases/tag/v0.11.9-pg.02). +🌲πŸ”₯ Requires using [Terraform 0.12 Beta](https://www.hashicorp.com/blog/announcing-terraform-0-1-2-beta1). ```bash # 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" +terraform init -backend-config="conn_str=$DATABASE_URL" +# …or use a local database with SSL disabled +terraform init -backend-config="conn_str=postgres://localhost/terraform_backend?sslmode=disable" # 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 +terraform plan +terraform apply ``` diff --git a/app.json b/app.json index 7b91f96..b6b6f01 100644 --- a/app.json +++ b/app.json @@ -18,7 +18,7 @@ "env": { "TERRAFORM_BIN_URL": { "description": "The source URL for the terraform binary (preset for Postgres backend support)", - "value": "https://terraforming-buildpack.s3.amazonaws.com/terraform_0.11.9-pg.02_linux_amd64.zip", + "value": "https://releases.hashicorp.com/terraform/0.12.0-beta1/terraform_0.12.0-beta1_linux_amd64.zip", "required": false }, "HEROKU_API_KEY": { @@ -32,6 +32,11 @@ "TF_VAR_example_app_name": { "description": "Name of app created by the example config in `main.tf`", "required": false + }, + "TERRAFORM_WORKSPACE_NAME": { + "description": "Name of the Terraform workspace to store state", + "value": "default", + "required": true } } } diff --git a/main.tf b/main.tf index 0f33d79..556d38a 100644 --- a/main.tf +++ b/main.tf @@ -1,9 +1,9 @@ terraform { - backend "pg" {} + backend "pg" { + } } provider "heroku" { - version = "~> 1.7" } variable "example_app_name" { @@ -11,12 +11,12 @@ variable "example_app_name" { } resource "heroku_app" "example" { - name = "${var.example_app_name}" + name = var.example_app_name region = "us" } resource "heroku_build" "example" { - app = "${heroku_app.example.name}" + app = heroku_app.example.name source = { path = "app/" @@ -24,11 +24,11 @@ resource "heroku_build" "example" { } resource "heroku_formation" "example" { - app = "${heroku_app.example.name}" + app = heroku_app.example.name type = "web" quantity = 1 size = "Standard-1x" - depends_on = ["heroku_build.example"] + depends_on = [heroku_build.example] } output "example_app_url" { @@ -36,5 +36,6 @@ output "example_app_url" { } output "example_app_build_log_url" { - value = "${heroku_build.example.output_stream_url}" + value = heroku_build.example.output_stream_url } + diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +}