terraform: remove unused code

This commit is contained in:
Mitchell Hashimoto 2014-06-25 18:13:58 -07:00
parent 0f2d7f430c
commit 4b263992cc
3 changed files with 3 additions and 125 deletions

View File

@ -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
}
*/

View File

@ -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

View File

@ -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