From 1b5dfa043bda8b9ca0ace2fb3927e35137948062 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 28 May 2014 13:56:43 -0700 Subject: [PATCH] terraform: some files laying out an API --- terraform/diff.go | 16 +++++++++++++ terraform/resource_provider.go | 4 ++++ terraform/state.go | 20 ++++++++++++++++ terraform/terraform.go | 43 ++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 terraform/diff.go create mode 100644 terraform/state.go create mode 100644 terraform/terraform.go diff --git a/terraform/diff.go b/terraform/diff.go new file mode 100644 index 000000000..725800d2f --- /dev/null +++ b/terraform/diff.go @@ -0,0 +1,16 @@ +package terraform + +// Diff tracks the differences between resources to apply. +type Diff struct { + resources map[string]map[string]*resourceDiff +} + +// resourceDiff is the diff of a single attribute of a resource. +// +// This tracks the old value, the new value, and whether the change of this +// value actually requires an entirely new resource. +type resourceDiff struct { + Old string + New string + RequiresNew bool +} diff --git a/terraform/resource_provider.go b/terraform/resource_provider.go index 2440d9c36..365764794 100644 --- a/terraform/resource_provider.go +++ b/terraform/resource_provider.go @@ -19,3 +19,7 @@ type ResourceProvider interface { type ResourceType struct { Name string } + +// ResourceProviderFactory is a function type that creates a new instance +// of a resource provider. +type ResourceProviderFactory func() (ResourceProvider, error) diff --git a/terraform/state.go b/terraform/state.go new file mode 100644 index 000000000..812b1133e --- /dev/null +++ b/terraform/state.go @@ -0,0 +1,20 @@ +package terraform + +// State keeps track of a snapshot state-of-the-world that Terraform +// can use to keep track of what real world resources it is actually +// managing. +type State struct { + resources map[string]resourceState +} + +// resourceState is the state of a single resource. +// +// The ID is required and is some opaque string used to recognize +// the realized resource. +// +// Extra is arbitrary extra metadata that the resource provider returns +// that is sent back into the resource provider when it is needed. +type resourceState struct { + ID string + Extra map[string]interface{} +} diff --git a/terraform/terraform.go b/terraform/terraform.go new file mode 100644 index 000000000..f1cd66b2c --- /dev/null +++ b/terraform/terraform.go @@ -0,0 +1,43 @@ +package terraform + +import ( + "github.com/hashicorp/terraform/config" +) + +// Terraform is the primary structure that is used to interact with +// Terraform from code, and can perform operations such as returning +// all resources, a resource tree, a specific resource, etc. +type Terraform struct { + config *config.Config + providers []ResourceProvider +} + +// Config is the configuration that must be given to instantiate +// a Terraform structure. +type Config struct { + Config *config.Config + Providers map[string]ResourceProviderFactory + Variables map[string]string +} + +// New creates a new Terraform structure, initializes resource providers +// for the given configuration, etc. +// +// Semantic checks of the entire configuration structure are done at this +// time, as well as richer checks such as verifying that the resource providers +// can be properly initialized, can be configured, etc. +func New(c *Config) (*Terraform, error) { + return nil, nil +} + +func (t *Terraform) Apply(*State, *Diff) (*State, error) { + return nil, nil +} + +func (t *Terraform) Diff(*State) (*Diff, error) { + return nil, nil +} + +func (t *Terraform) Refresh(*State) (*State, error) { + return nil, nil +}