config: ProviderConfigName shouldn't be on Resource

This commit is contained in:
Mitchell Hashimoto 2014-06-24 13:29:07 -07:00
parent 9d8c2790fa
commit 9acb9535ad
2 changed files with 10 additions and 15 deletions

View File

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

View File

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