Skip to content

Commit

Permalink
Don't create loadbalancer or floating_ip if droplet count is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
pysysops committed Jan 23, 2019
1 parent 5ab85b0 commit 2e204d4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ resource "digitalocean_volume_attachment" "volume_attachment" {

// Floating IP
resource "digitalocean_floating_ip" "floating_ip" {
count = "${var.floating_ip > 0 ? coalesce(var.floating_ip_count, var.droplet_count) : 0}"
count = "${var.floating_ip > 0 && var.droplet_count > 0 ? coalesce(var.floating_ip_count, var.droplet_count) : 0}"
region = "${var.region}"
}

// Floating IP assignment
resource "digitalocean_floating_ip_assignment" "floating_ip_assignment" {
count = "${var.floating_ip > 0 && var.floating_ip_assign > 0 ? coalesce(var.floating_ip_count, var.droplet_count) : 0}"
count = "${var.floating_ip > 0 && var.floating_ip_assign > 0 && var.droplet_count > 0 ? coalesce(var.floating_ip_count, var.droplet_count) : 0}"

ip_address = "${element(digitalocean_floating_ip.floating_ip.*.id, count.index)}"
droplet_id = "${element(digitalocean_droplet.droplet.*.id, count.index)}"
}

// Loadbalancer
resource "digitalocean_loadbalancer" "loadbalancer" {
count = "${var.loadbalancer > 0 ? 1 : 0}"
count = "${var.loadbalancer > 0 && var.droplet_count > 0 ? 1 : 0}"

name = "${coalesce(var.loadbalancer_name, format("%s-lb", var.droplet_name))}"
region = "${var.region}"
Expand Down

0 comments on commit 2e204d4

Please sign in to comment.