Skip to content

Commit

Permalink
fix failure when no backend specified (terraform-google-modules#8)
Browse files Browse the repository at this point in the history
This change sets the `ports` list to [""] when `backend_params` is empty.

Ideally this would be done with an expression like:
```
"${length(var.backend_params) == 0 ? "" : element(split(",", element(var.backend_params, count.index)), 2)}"
```

But because of a limitation with HCL, it cannot be done and we've resorted
to the trick described in this issue:

hashicorp/hil#50 (comment)

The pipe `|` delimiter is used because it is not valid to use in GCP names.

Contributed according to the Google CLA.
  • Loading branch information
neomantra committed Jun 27, 2018
1 parent 3b5aa03 commit d40a0a6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ resource "google_compute_firewall" "default-hc" {

allow {
protocol = "tcp"
ports = ["${element(split(",", element(var.backend_params, count.index)), 2)}"]
ports = ["${element(split(",", element(split("|", join("", list(join("|", var.backend_params), replace(format("%*s", length(var.backend_params), ""), " ", "|")))), count.index)), 2)}"]
}
}

0 comments on commit d40a0a6

Please sign in to comment.