config: depends_on meta-parameter

This commit is contained in:
Mitchell Hashimoto 2014-07-22 17:10:17 -07:00
parent 498600d75f
commit 0699cde1d4
5 changed files with 33 additions and 10 deletions

View File

@ -42,6 +42,7 @@ type Resource struct {
Count int Count int
RawConfig *RawConfig RawConfig *RawConfig
Provisioners []*Provisioner Provisioners []*Provisioner
DependsOn []string
} }
// Provisioner is a configured provisioner step on a resource. // Provisioner is a configured provisioner step on a resource.

View File

@ -352,16 +352,11 @@ func loadResourcesLibucl(o *libucl.Object) ([]*Resource, error) {
err) err)
} }
// Remove the "count" from the config, since we treat that special // Remove the fields we handle specially
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
delete(config, "connection") delete(config, "connection")
delete(config, "count")
delete(config, "depends_on")
delete(config, "provisioner")
rawConfig, err := NewRawConfig(config) rawConfig, err := NewRawConfig(config)
if err != nil { 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 // If we have provisioners, then parse those out
var provisioners []*Provisioner var provisioners []*Provisioner
if po := r.Get("provisioner"); po != nil { if po := r.Get("provisioner"); po != nil {
@ -422,6 +431,7 @@ func loadResourcesLibucl(o *libucl.Object) ([]*Resource, error) {
Count: count, Count: count,
RawConfig: rawConfig, RawConfig: rawConfig,
Provisioners: provisioners, Provisioners: provisioners,
DependsOn: dependsOn,
}) })
} }
} }

View File

@ -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 { if len(r.RawConfig.Variables) > 0 {
result += fmt.Sprintf(" vars\n") result += fmt.Sprintf(" vars\n")
@ -479,6 +486,8 @@ do
const basicResourcesStr = ` const basicResourcesStr = `
aws_instance[db] (x1) aws_instance[db] (x1)
security_groups security_groups
dependsOn
aws_instance.web
vars vars
resource: aws_security_group.firewall.*.id resource: aws_security_group.firewall.*.id
aws_instance[web] (x1) aws_instance[web] (x1)

View File

@ -31,6 +31,8 @@ resource aws_instance "web" {
resource "aws_instance" "db" { resource "aws_instance" "db" {
security_groups = "${aws_security_group.firewall.*.id}" security_groups = "${aws_security_group.firewall.*.id}"
depends_on = ["aws_instance.web"]
} }
output "web_ip" { output "web_ip" {

View File

@ -20,7 +20,8 @@
"resource": { "resource": {
"aws_instance": { "aws_instance": {
"db": { "db": {
"security_groups": ["${aws_security_group.firewall.*.id}"] "security_groups": ["${aws_security_group.firewall.*.id}"],
"depends_on": ["aws_instance.web"]
}, },
"web": { "web": {