terraform: placeholder key for computed values

This commit is contained in:
Mitchell Hashimoto 2014-06-05 11:30:48 -07:00
parent 63e1b6f6b7
commit 9018beda81
3 changed files with 42 additions and 1 deletions

View File

@ -1,5 +1,10 @@
package terraform
// ComputedPlaceholderKey is the configuration key given to Configure
// in a ResourceProvider that contains the value for the computed value
// placeholder when diffs are being done.
const ComputedPlaceholderKey = "tf_computed_placeholder"
// ResourceProvider is an interface that must be implemented by any
// resource provider: the thing that creates and manages the resources in
// a Terraform configuration.
@ -28,6 +33,14 @@ type ResourceProvider interface {
map[string]interface{}) (ResourceDiff, error)
}
// ResourceProviderCommonConfig contains the common configuration
// keys that are sent with every resource provider configuration.
// This can be used with something like mapstructure to extract
// the proper value.
type ResourceProviderCommonConfig struct {
TFComputedPlaceholder string `mapstructure:"tf_computed_placeholder"`
}
// ResourceType is a type of resource that a resource provider can manage.
type ResourceType struct {
Name string

View File

@ -1,5 +1,9 @@
package terraform
import (
"github.com/mitchellh/mapstructure"
)
// MockResourceProvider implements ResourceProvider but mocks out all the
// calls for testing purposes.
type MockResourceProvider struct {
@ -7,6 +11,7 @@ type MockResourceProvider struct {
Meta interface{}
ConfigureCalled bool
ConfigureCommonConfig ResourceProviderCommonConfig
ConfigureConfig map[string]interface{}
ConfigureReturnWarnings []string
ConfigureReturnError error
@ -23,6 +28,11 @@ type MockResourceProvider struct {
func (p *MockResourceProvider) Configure(c map[string]interface{}) ([]string, error) {
p.ConfigureCalled = true
p.ConfigureConfig = c
if err := mapstructure.Decode(&p.ConfigureCommonConfig, c); err != nil {
return nil, err
}
return p.ConfigureReturnWarnings, p.ConfigureReturnError
}

View File

@ -39,6 +39,20 @@ func TestNew(t *testing.T) {
if testProviderName(mapping["do_droplet.bar"]) != "do" {
t.Fatalf("bad: %#v", mapping)
}
/*
val := testProviderMock(mapping["aws_instance.foo"]).
ConfigureCommonConfig.TFComputedPlaceholder
if val == "" {
t.Fatal("should have computed placeholder")
}
val = testProviderMock(mapping["aws_instance.bar"]).
ConfigureCommonConfig.TFComputedPlaceholder
if val == "" {
t.Fatal("should have computed placeholder")
}
*/
}
func TestNew_graphCycle(t *testing.T) {
@ -169,8 +183,12 @@ func testProviderFunc(n string, rs []string) ResourceProviderFactory {
}
}
func testProviderMock(p ResourceProvider) *MockResourceProvider {
return p.(*MockResourceProvider)
}
func testProviderName(p ResourceProvider) string {
return p.(*MockResourceProvider).Meta.(string)
return testProviderMock(p).Meta.(string)
}
func testResourceMapping(tf *Terraform) map[string]ResourceProvider {