hashicorp/terraform — pull request #232 by ryanuber (2014-08-26 16:45:16+00:00)
Title: F resource template

After building a few small services using Terraform, I noticed that we have some opportunity to simplify resources with the same basic configs. Having a kind of "template" containing the common values could allow us to stamp out a bunch of unique resources while still maintaining just a single key-value mapping of common configs.

This seems like it could be true for many types of resources, so I took a stab at implementing a resource-agnostic way of applying a "resource template" to a resource.

Essentially, a `resource_template` item in the root-level of a config can be applied to any resource by referencing the template from within the resource. The resource template does not carry with it any special constraints and does not know which type of resource someone will try to apply it to, which I thought was the right way to leave the validation logic in the resource provider itself rather than trying to validate the templates.

Example:
```
resource_template "mytemplate" {
stack = "cedar"
config_vars {
FOO = "bar"
BAZ = "zip"
}
}

resource "heroku_app" "myapp-us" {
resource_template = "mytemplate"
region = "us"
}

resource "heroku_app" "myapp-eu" {
resource_template = "mytemplate"
region = "eu"
}
```

Generates plan:
```
+ heroku_app.myapp-eu
config_vars.#: "0" => "1"
config_vars.0.BAZ: "" => "zip"
config_vars.0.FOO: "" => "bar"
git_url: "" => ""
heroku_hostname: "" => ""
name: "" => ""
region: "" => "eu"
stack: "" => "cedar"
web_url: "" => ""

+ heroku_app.myapp-us
config_vars.#: "0" => "1"
config_vars.0.BAZ: "" => "zip"
config_vars.0.FOO: "" => "bar"
git_url: "" => ""
heroku_hostname: "" => ""
name: "" => ""
region: "" => "us"
stack: "" => "cedar"
web_url: "" => ""
```

Let me know if you think this is useful, and if you have any suggestions on the syntax, implementation, or anything else!