From 4b263992cccaa6bcf663a24fa0567e0797d0065f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 25 Jun 2014 18:13:58 -0700 Subject: [PATCH] terraform: remove unused code --- terraform/semantics.go | 3 ++ terraform/terraform.go | 50 ------------------------- terraform/terraform_test.go | 75 ------------------------------------- 3 files changed, 3 insertions(+), 125 deletions(-) diff --git a/terraform/semantics.go b/terraform/semantics.go index 9f7732a88..adafdbaa5 100644 --- a/terraform/semantics.go +++ b/terraform/semantics.go @@ -1,11 +1,13 @@ package terraform +/* import ( "fmt" "github.com/hashicorp/terraform/config" ) +/* // smcProviders matches up the resources with a provider and initializes // it. This does not call "Configure" on the ResourceProvider, since that // might actually depend on upstream resources. @@ -153,3 +155,4 @@ func smcVariables(c *Config) []error { return errs } +*/ diff --git a/terraform/terraform.go b/terraform/terraform.go index 4a8c4d907..795338ca9 100644 --- a/terraform/terraform.go +++ b/terraform/terraform.go @@ -16,15 +16,6 @@ type Terraform struct { providers map[string]ResourceProviderFactory } -// terraformProvider contains internal state information about a resource -// provider for Terraform. -type terraformProvider struct { - Provider ResourceProvider - Config *config.ProviderConfig - - sync.Once -} - // This is a function type used to implement a walker for the resource // tree internally on the Terraform structure. type genericWalkFunc func(*Resource) (map[string]string, error) @@ -32,9 +23,7 @@ type genericWalkFunc func(*Resource) (map[string]string, error) // 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 @@ -44,45 +33,6 @@ type Config struct { // 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) { - var errs []error - - if c.Config != nil { - // Validate that all required variables have values - if err := smcVariables(c); err != nil { - errs = append(errs, err...) - } - - // Match all the resources with a provider and initialize the providers - mapping, err := smcProviders(c) - if err != nil { - errs = append(errs, err...) - } - - // Validate all the configurations, once. - tps := make(map[*terraformProvider]struct{}) - for _, tp := range mapping { - if _, ok := tps[tp]; !ok { - tps[tp] = struct{}{} - } - } - for tp, _ := range tps { - var rc *ResourceConfig - if tp.Config != nil { - rc = NewResourceConfig(tp.Config.RawConfig) - } - - _, tpErrs := tp.Provider.Validate(rc) - if len(tpErrs) > 0 { - errs = append(errs, tpErrs...) - } - } - } - - // If we accumulated any errors, then return them all - if len(errs) > 0 { - return nil, &MultiError{Errors: errs} - } - return &Terraform{ providers: c.Providers, }, nil diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index a11bfd6e4..33cafc35d 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -364,73 +364,10 @@ func testProviderFuncFixed(rp ResourceProvider) ResourceProviderFactory { } } -func testProvider(tf *Terraform, n string) ResourceProvider { - /* - for r, tp := range tf.mapping { - if r.Id() == n { - return tp.Provider - } - } - */ - - return nil -} - func testProviderMock(p ResourceProvider) *MockResourceProvider { return p.(*MockResourceProvider) } -func testProviderConfig(tf *Terraform, n string) *config.ProviderConfig { - /* - for r, tp := range tf.mapping { - if r.Id() == n { - return tp.Config - } - } - */ - - return nil -} - -func testProviderName(t *testing.T, tf *Terraform, n string) string { - var p ResourceProvider - /* - for r, tp := range tf.mapping { - if r.Id() == n { - p = tp.Provider - break - } - } - */ - - if p == nil { - t.Fatalf("resource not found: %s", n) - } - - return testProviderMock(p).Meta.(string) -} - -func testTerraform(t *testing.T, name string) *Terraform { - config := testConfig(t, name) - tfConfig := &Config{ - Config: config, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFunc("aws", []string{"aws_instance"}), - "do": testProviderFunc("do", []string{"do_droplet"}), - }, - } - - tf, err := New(tfConfig) - if err != nil { - t.Fatalf("err: %s", err) - } - if tf == nil { - t.Fatal("tf should not be nil") - } - - return tf -} - func testTerraform2(t *testing.T, c *Config) *Terraform { if c == nil { c = &Config{ @@ -452,18 +389,6 @@ func testTerraform2(t *testing.T, c *Config) *Terraform { return tf } -func testTerraformProvider(tf *Terraform, n string) *terraformProvider { - /* - for r, tp := range tf.mapping { - if r.Id() == n { - return tp - } - } - */ - - return nil -} - const testTerraformApplyStr = ` aws_instance.bar: ID = foo