hashicorp/terraform — pull request #201 by mitchellh (2014-08-19 16:35:16+00:00)
Title: High-Level Framework for Writing Providers and Resources

This introduces the `helper/schema` package, which is actually a high-level framework for easily implementing new providers and resources.

The motivation behind this was that during development of Terraform 0.1.0 we identified that writing providers/resources was _very_ tedious and error-prone, and qualitatively painful. We agreed that the low-level API of the `terraform.ResourceProvider` interface was correct and enabled maximum flexibility, but writing directly to it is a mess. `helper/resource` was a first attempt at fixing this, but writing providers remained painful. `helper/schema` (this PR) is our next attempt, and so far it feels great.

Look at the Heroku provider in the diff to see the differences. The high-level improvements:

* `helper/schema.Provider` implements the `terraform.ResourceProvider` interface, masking away that complexity and making it easy to add resources.

* `helper/schema.Provider.InternalValidate` can be called in unit tests to verify the structure and schema of all providers and resources. This is super helpful in identifying issues before runtime.

* `helper/schema.Resource` defines all properties of a resource. A single schema is used to describe both the validation and diff generation.

* `helper/schema.Resource` breaks down resource operations into CRUD (create, read, update, delete). You just implement those callbacks and `helper/schema` handles the rest of the lifecycle.

* Reading/setting configuration and attributes is all done via the `helper/schema.ResourceData` structure. Much easier than juggling `ResourceState` and `ResourceDiff`.