config: ProviderConfigName shouldn't be on Resource
This commit is contained in:
parent
9d8c2790fa
commit
9acb9535ad
|
@ -70,18 +70,13 @@ type UserVariable struct {
|
||||||
key string
|
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
|
// ProviderConfigName returns the name of the provider configuration in
|
||||||
// the given mapping that maps to the proper provider configuration
|
// the given mapping that maps to the proper provider configuration
|
||||||
// for this resource.
|
// for this resource.
|
||||||
func (r *Resource) ProviderConfigName(pcs map[string]*ProviderConfig) string {
|
func ProviderConfigName(t string, pcs map[string]*ProviderConfig) string {
|
||||||
lk := ""
|
lk := ""
|
||||||
for k, _ := range pcs {
|
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
|
lk = k
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +84,11 @@ func (r *Resource) ProviderConfigName(pcs map[string]*ProviderConfig) string {
|
||||||
return lk
|
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
|
// Graph returns a dependency graph of the resources from this
|
||||||
// Terraform configuration.
|
// Terraform configuration.
|
||||||
//
|
//
|
||||||
|
@ -151,7 +151,7 @@ func (c *Config) Graph() *depgraph.Graph {
|
||||||
if r, ok := noun.Meta.(*Resource); ok {
|
if r, ok := noun.Meta.(*Resource); ok {
|
||||||
// If there is a provider config that matches this resource
|
// If there is a provider config that matches this resource
|
||||||
// then we add that as a dependency.
|
// 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]
|
pcNoun, ok := pcNouns[pcName]
|
||||||
if !ok {
|
if !ok {
|
||||||
pcNoun = &depgraph.Noun{
|
pcNoun = &depgraph.Noun{
|
||||||
|
|
|
@ -75,12 +75,7 @@ func TestNewUserVariable(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResourceProviderConfigName(t *testing.T) {
|
func TestProviderConfigName(t *testing.T) {
|
||||||
r := &Resource{
|
|
||||||
Name: "foo",
|
|
||||||
Type: "aws_instance",
|
|
||||||
}
|
|
||||||
|
|
||||||
pcs := map[string]*ProviderConfig{
|
pcs := map[string]*ProviderConfig{
|
||||||
"aw": new(ProviderConfig),
|
"aw": new(ProviderConfig),
|
||||||
"aws": new(ProviderConfig),
|
"aws": new(ProviderConfig),
|
||||||
|
@ -88,7 +83,7 @@ func TestResourceProviderConfigName(t *testing.T) {
|
||||||
"gce_": new(ProviderConfig),
|
"gce_": new(ProviderConfig),
|
||||||
}
|
}
|
||||||
|
|
||||||
n := r.ProviderConfigName(pcs)
|
n := ProviderConfigName("aws_instance", pcs)
|
||||||
if n != "aws" {
|
if n != "aws" {
|
||||||
t.Fatalf("bad: %s", n)
|
t.Fatalf("bad: %s", n)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue