Skip to content

Commit 0699cde

Browse files
committed
config: depends_on meta-parameter
1 parent 498600d commit 0699cde

5 files changed

Lines changed: 32 additions & 9 deletions

File tree

‎config/config.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type Resource struct {
4242
Count int
4343
RawConfig *RawConfig
4444
Provisioners []*Provisioner
45+
DependsOn []string
4546
}
4647

4748
// Provisioner is a configured provisioner step on a resource.

‎config/loader_libucl.go‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,12 @@ func loadResourcesLibucl(o *libucl.Object) ([]*Resource, error) {
352352
err)
353353
}
354354

355-
// Remove the "count" from the config, since we treat that special
355+
// Remove the fields we handle specially
356+
delete(config, "connection")
356357
delete(config, "count")
357-
358-
// Delete the "provisioner" section from the config since
359-
// that is treated specially.
358+
delete(config, "depends_on")
360359
delete(config, "provisioner")
361360

362-
// Delete the "connection" section since we handle that
363-
// seperately
364-
delete(config, "connection")
365-
366361
rawConfig, err := NewRawConfig(config)
367362
if err != nil {
368363
return nil, fmt.Errorf(
@@ -401,6 +396,20 @@ func loadResourcesLibucl(o *libucl.Object) ([]*Resource, error) {
401396
}
402397
}
403398

399+
// If we have depends fields, then add those in
400+
var dependsOn []string
401+
if deps := r.Get("depends_on"); deps != nil {
402+
err := deps.Decode(&dependsOn)
403+
deps.Close()
404+
if err != nil {
405+
return nil, fmt.Errorf(
406+
"Error reading depends_on for %s[%s]: %s",
407+
t.Key(),
408+
r.Key(),
409+
err)
410+
}
411+
}
412+
404413
// If we have provisioners, then parse those out
405414
var provisioners []*Provisioner
406415
if po := r.Get("provisioner"); po != nil {
@@ -422,6 +431,7 @@ func loadResourcesLibucl(o *libucl.Object) ([]*Resource, error) {
422431
Count: count,
423432
RawConfig: rawConfig,
424433
Provisioners: provisioners,
434+
DependsOn: dependsOn,
425435
})
426436
}
427437
}

‎config/loader_test.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ func resourcesStr(rs []*Resource) string {
393393
}
394394
}
395395

396+
if len(r.DependsOn) > 0 {
397+
result += fmt.Sprintf(" dependsOn\n")
398+
for _, d := range r.DependsOn {
399+
result += fmt.Sprintf(" %s\n", d)
400+
}
401+
}
402+
396403
if len(r.RawConfig.Variables) > 0 {
397404
result += fmt.Sprintf(" vars\n")
398405

@@ -479,6 +486,8 @@ do
479486
const basicResourcesStr = `
480487
aws_instance[db] (x1)
481488
security_groups
489+
dependsOn
490+
aws_instance.web
482491
vars
483492
resource: aws_security_group.firewall.*.id
484493
aws_instance[web] (x1)

‎config/test-fixtures/basic.tf‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ resource aws_instance "web" {
3131

3232
resource "aws_instance" "db" {
3333
security_groups = "${aws_security_group.firewall.*.id}"
34+
35+
depends_on = ["aws_instance.web"]
3436
}
3537

3638
output "web_ip" {

‎config/test-fixtures/basic.tf.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"resource": {
2121
"aws_instance": {
2222
"db": {
23-
"security_groups": ["${aws_security_group.firewall.*.id}"]
23+
"security_groups": ["${aws_security_group.firewall.*.id}"],
24+
"depends_on": ["aws_instance.web"]
2425
},
2526

2627
"web": {

0 commit comments

Comments
 (0)