diff --git a/config/config.go b/config/config.go index 9744577dc..63700650a 100644 --- a/config/config.go +++ b/config/config.go @@ -70,18 +70,13 @@ type UserVariable struct { key string } -// A unique identifier for this resource. -func (r *Resource) Id() string { - return fmt.Sprintf("%s.%s", r.Type, r.Name) -} - // ProviderConfigName returns the name of the provider configuration in // the given mapping that maps to the proper provider configuration // for this resource. -func (r *Resource) ProviderConfigName(pcs map[string]*ProviderConfig) string { +func ProviderConfigName(t string, pcs map[string]*ProviderConfig) string { lk := "" for k, _ := range pcs { - if strings.HasPrefix(r.Type, k) && len(k) > len(lk) { + if strings.HasPrefix(t, k) && len(k) > len(lk) { lk = k } } @@ -89,6 +84,11 @@ func (r *Resource) ProviderConfigName(pcs map[string]*ProviderConfig) string { return lk } +// A unique identifier for this resource. +func (r *Resource) Id() string { + return fmt.Sprintf("%s.%s", r.Type, r.Name) +} + // Graph returns a dependency graph of the resources from this // Terraform configuration. // @@ -151,7 +151,7 @@ func (c *Config) Graph() *depgraph.Graph { if r, ok := noun.Meta.(*Resource); ok { // If there is a provider config that matches this resource // then we add that as a dependency. - if pcName := r.ProviderConfigName(c.ProviderConfigs); pcName != "" { + if pcName := ProviderConfigName(r.Type, c.ProviderConfigs); pcName != "" { pcNoun, ok := pcNouns[pcName] if !ok { pcNoun = &depgraph.Noun{ diff --git a/config/config_test.go b/config/config_test.go index 341987c99..b47cb08ea 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -75,12 +75,7 @@ func TestNewUserVariable(t *testing.T) { } } -func TestResourceProviderConfigName(t *testing.T) { - r := &Resource{ - Name: "foo", - Type: "aws_instance", - } - +func TestProviderConfigName(t *testing.T) { pcs := map[string]*ProviderConfig{ "aw": new(ProviderConfig), "aws": new(ProviderConfig), @@ -88,7 +83,7 @@ func TestResourceProviderConfigName(t *testing.T) { "gce_": new(ProviderConfig), } - n := r.ProviderConfigName(pcs) + n := ProviderConfigName("aws_instance", pcs) if n != "aws" { t.Fatalf("bad: %s", n) }