Skip to content

Commit

Permalink
Terraform 0.12 (#5)
Browse files Browse the repository at this point in the history
* Use Terraform 0.12 Beta 1

* Upgrade to config to HCL2 and Heroku provider 1.8.0-dev (included)

* Configure & ensure the workspace exists

* 📚 0.12 Beta 1 info
  • Loading branch information
mars authored Mar 1, 2019
1 parent 1beb806 commit 6fdc0ff
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .profile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file not shown.
Binary file not shown.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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
------
Expand Down Expand 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 [email protected]
Expand All @@ -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
```
7 changes: 6 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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
}
}
}
15 changes: 8 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
terraform {
backend "pg" {}
backend "pg" {
}
}

provider "heroku" {
version = "~> 1.7"
}

variable "example_app_name" {
description = "Name of the Heroku app provisioned as an example"
}

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/"
}
}

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" {
value = "https://${heroku_app.example.name}.herokuapp.com"
}

output "example_app_build_log_url" {
value = "${heroku_build.example.output_stream_url}"
value = heroku_build.example.output_stream_url
}

4 changes: 4 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}

0 comments on commit 6fdc0ff

Please sign in to comment.