config: depends_on meta-parameter
This commit is contained in:
parent
498600d75f
commit
0699cde1d4
|
@ -42,6 +42,7 @@ type Resource struct {
|
|||
Count int
|
||||
RawConfig *RawConfig
|
||||
Provisioners []*Provisioner
|
||||
DependsOn []string
|
||||
}
|
||||
|
||||
// Provisioner is a configured provisioner step on a resource.
|
||||
|
|
|
@ -352,16 +352,11 @@ func loadResourcesLibucl(o *libucl.Object) ([]*Resource, error) {
|
|||
err)
|
||||
}
|
||||
|
||||
// Remove the "count" from the config, since we treat that special
|
||||
delete(config, "count")
|
||||
|
||||
// Delete the "provisioner" section from the config since
|
||||
// that is treated specially.
|
||||
delete(config, "provisioner")
|
||||
|
||||
// Delete the "connection" section since we handle that
|
||||
// seperately
|
||||
// Remove the fields we handle specially
|
||||
delete(config, "connection")
|
||||
delete(config, "count")
|
||||
delete(config, "depends_on")
|
||||
delete(config, "provisioner")
|
||||
|
||||
rawConfig, err := NewRawConfig(config)
|
||||
if err != nil {
|
||||
|
@ -401,6 +396,20 @@ func loadResourcesLibucl(o *libucl.Object) ([]*Resource, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// If we have depends fields, then add those in
|
||||
var dependsOn []string
|
||||
if deps := r.Get("depends_on"); deps != nil {
|
||||
err := deps.Decode(&dependsOn)
|
||||
deps.Close()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"Error reading depends_on for %s[%s]: %s",
|
||||
t.Key(),
|
||||
r.Key(),
|
||||
err)
|
||||
}
|
||||
}
|
||||
|
||||
// If we have provisioners, then parse those out
|
||||
var provisioners []*Provisioner
|
||||
if po := r.Get("provisioner"); po != nil {
|
||||
|
@ -422,6 +431,7 @@ func loadResourcesLibucl(o *libucl.Object) ([]*Resource, error) {
|
|||
Count: count,
|
||||
RawConfig: rawConfig,
|
||||
Provisioners: provisioners,
|
||||
DependsOn: dependsOn,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -393,6 +393,13 @@ func resourcesStr(rs []*Resource) string {
|
|||
}
|
||||
}
|
||||
|
||||
if len(r.DependsOn) > 0 {
|
||||
result += fmt.Sprintf(" dependsOn\n")
|
||||
for _, d := range r.DependsOn {
|
||||
result += fmt.Sprintf(" %s\n", d)
|
||||
}
|
||||
}
|
||||
|
||||
if len(r.RawConfig.Variables) > 0 {
|
||||
result += fmt.Sprintf(" vars\n")
|
||||
|
||||
|
@ -479,6 +486,8 @@ do
|
|||
const basicResourcesStr = `
|
||||
aws_instance[db] (x1)
|
||||
security_groups
|
||||
dependsOn
|
||||
aws_instance.web
|
||||
vars
|
||||
resource: aws_security_group.firewall.*.id
|
||||
aws_instance[web] (x1)
|
||||
|
|
|
@ -31,6 +31,8 @@ resource aws_instance "web" {
|
|||
|
||||
resource "aws_instance" "db" {
|
||||
security_groups = "${aws_security_group.firewall.*.id}"
|
||||
|
||||
depends_on = ["aws_instance.web"]
|
||||
}
|
||||
|
||||
output "web_ip" {
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
"resource": {
|
||||
"aws_instance": {
|
||||
"db": {
|
||||
"security_groups": ["${aws_security_group.firewall.*.id}"]
|
||||
"security_groups": ["${aws_security_group.firewall.*.id}"],
|
||||
"depends_on": ["aws_instance.web"]
|
||||
},
|
||||
|
||||
"web": {
|
||||
|
|
Loading…
Reference in New Issue