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