Skip to content

Commit 25328e3

Browse files
adrienthebomorgante
authored andcommitted
Add dependencies between subnets and dat sources
Without an explicit dependency between the `created_subnets` data source and the `subnetwork` resource, the data source may be fetched before subnets are created, causing stale information to be provided. This commit resolves the issue by using resource attributes within the data source, creating the necessary dependency.
1 parent 0040e64 commit 25328e3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ resource "google_compute_subnetwork" "subnetwork" {
5252
data "google_compute_subnetwork" "created_subnets" {
5353
count = "${length(var.subnets)}"
5454

55-
name = "${lookup(var.subnets[count.index], "subnet_name")}"
56-
region = "${lookup(var.subnets[count.index], "subnet_region")}"
55+
name = "${element(google_compute_subnetwork.subnetwork.*.name, count.index)}"
56+
region = "${element(google_compute_subnetwork.subnetwork.*.region, count.index)}"
5757
project = "${var.project_id}"
5858
}
5959

0 commit comments

Comments
 (0)