config: support count meta-parameter
This commit is contained in:
parent
17074e5ae6
commit
3337a625af
|
@ -31,6 +31,7 @@ type ProviderConfig struct {
|
||||||
type Resource struct {
|
type Resource struct {
|
||||||
Name string
|
Name string
|
||||||
Type string
|
Type string
|
||||||
|
Count int
|
||||||
RawConfig *RawConfig
|
RawConfig *RawConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -253,6 +253,9 @@ func loadResourcesLibucl(o *libucl.Object) ([]*Resource, error) {
|
||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove the "count" from the config, since we treat that special
|
||||||
|
delete(config, "count")
|
||||||
|
|
||||||
rawConfig, err := NewRawConfig(config)
|
rawConfig, err := NewRawConfig(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
|
@ -262,9 +265,24 @@ func loadResourcesLibucl(o *libucl.Object) ([]*Resource, error) {
|
||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we have a count, then figure it out
|
||||||
|
var count int = 1
|
||||||
|
if o := r.Get("count"); o != nil {
|
||||||
|
err = o.Decode(&count)
|
||||||
|
o.Close()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"Error parsing count for %s[%s]: %s",
|
||||||
|
t.Key(),
|
||||||
|
r.Key(),
|
||||||
|
err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result = append(result, &Resource{
|
result = append(result, &Resource{
|
||||||
Name: r.Key(),
|
Name: r.Key(),
|
||||||
Type: t.Key(),
|
Type: t.Key(),
|
||||||
|
Count: count,
|
||||||
RawConfig: rawConfig,
|
RawConfig: rawConfig,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,9 +145,10 @@ func resourcesStr(rs []*Resource) string {
|
||||||
result := ""
|
result := ""
|
||||||
for _, r := range rs {
|
for _, r := range rs {
|
||||||
result += fmt.Sprintf(
|
result += fmt.Sprintf(
|
||||||
"%s[%s]\n",
|
"%s[%s] (x%d)\n",
|
||||||
r.Type,
|
r.Type,
|
||||||
r.Name)
|
r.Name,
|
||||||
|
r.Count)
|
||||||
|
|
||||||
ks := make([]string, 0, len(r.RawConfig.Raw))
|
ks := make([]string, 0, len(r.RawConfig.Raw))
|
||||||
for k, _ := range r.RawConfig.Raw {
|
for k, _ := range r.RawConfig.Raw {
|
||||||
|
@ -229,8 +230,8 @@ do
|
||||||
`
|
`
|
||||||
|
|
||||||
const basicResourcesStr = `
|
const basicResourcesStr = `
|
||||||
aws_security_group[firewall]
|
aws_security_group[firewall] (x5)
|
||||||
aws_instance[web]
|
aws_instance[web] (x1)
|
||||||
ami
|
ami
|
||||||
network_interface
|
network_interface
|
||||||
security_groups
|
security_groups
|
||||||
|
@ -251,8 +252,8 @@ aws
|
||||||
`
|
`
|
||||||
|
|
||||||
const importResourcesStr = `
|
const importResourcesStr = `
|
||||||
aws_security_group[db]
|
aws_security_group[db] (x1)
|
||||||
aws_security_group[web]
|
aws_security_group[web] (x1)
|
||||||
`
|
`
|
||||||
|
|
||||||
const importVariablesStr = `
|
const importVariablesStr = `
|
||||||
|
|
|
@ -13,6 +13,7 @@ provider "do" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_security_group" "firewall" {
|
resource "aws_security_group" "firewall" {
|
||||||
|
count = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
resource aws_instance "web" {
|
resource aws_instance "web" {
|
||||||
|
|
Loading…
Reference in New Issue