mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-03 12:20:28 -06:00
config: ProviderConfigName on Resource
This commit is contained in:
parent
4397c566a0
commit
e2fa7094bd
@ -82,6 +82,20 @@ func (r *Resource) Id() string {
|
|||||||
return fmt.Sprintf("%s.%s", r.Type, r.Name)
|
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 {
|
||||||
|
lk := ""
|
||||||
|
for k, _ := range pcs {
|
||||||
|
if strings.HasPrefix(r.Type, k) && len(k) > len(lk) {
|
||||||
|
lk = k
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lk
|
||||||
|
}
|
||||||
|
|
||||||
// ReplaceVariables replaces the variables in the configuration
|
// ReplaceVariables replaces the variables in the configuration
|
||||||
// with the given values.
|
// with the given values.
|
||||||
//
|
//
|
||||||
|
@ -64,6 +64,25 @@ func TestNewUserVariable(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResourceProviderConfigName(t *testing.T) {
|
||||||
|
r := &Resource{
|
||||||
|
Name: "foo",
|
||||||
|
Type: "aws_instance",
|
||||||
|
}
|
||||||
|
|
||||||
|
pcs := map[string]*ProviderConfig{
|
||||||
|
"aw": new(ProviderConfig),
|
||||||
|
"aws": new(ProviderConfig),
|
||||||
|
"a": new(ProviderConfig),
|
||||||
|
"gce_": new(ProviderConfig),
|
||||||
|
}
|
||||||
|
|
||||||
|
n := r.ProviderConfigName(pcs)
|
||||||
|
if n != "aws" {
|
||||||
|
t.Fatalf("bad: %s", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestResourceReplaceVariables(t *testing.T) {
|
func TestResourceReplaceVariables(t *testing.T) {
|
||||||
r := &Resource{
|
r := &Resource{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
Loading…
Reference in New Issue
Block a user