Reputation: 876
I'm trying tell terraform the resource is dependent on other one. The problem is the resources are in separate modules. The dependent resource looks like that:
variable dependency {
type = "list"
default = []
}
resource "docker_container" "web" {
depends_on = "${var.dependency}"
...
Then I 'call' the module:
module "wordpress" {
source = "../modules/wordpress"
dependency = [ "${module.provision.res}" ]
}
And I got error:
on ../modules/wordpress/main.tf line 11, in resource "docker_container" "web":
11: depends_on = "${var.dependency}"
A static list expression is required.
It looks like I cannot use variable in 'depends_on'. How to create dependency between modules?
PS: The resource I depend on is a null_resource which provides some some provisioning. I need to rebuild some stuff every time it changes.
Upvotes: 4
Views: 3103
Reputation: 1045
To solve the error: "A static list expression is required."
You need to wrap the var.dependency with []:
resource "docker_container" "web" {
depends_on = ["${var.dependency}"]
...
Update: The syntax above is for terraform<0.12. For terraform >=0.12, as @Maciej Wawrzyńczuk points out, [var.dependency] will just work in this case. ["${var.dependency}"] will also work in 0.12 as backward compatibility but if you run tf 0.12 you probably want to do it the new way.
Upvotes: 8