From 68b00e67e33e1f826d77ccfa744413939190cc86 Mon Sep 17 00:00:00 2001 From: Dan Isla Date: Thu, 10 Jan 2019 14:18:37 -0800 Subject: [PATCH] added external_ip_address and use_external_ip_address variables --- main.tf | 4 ++-- outputs.tf | 2 +- variables.tf | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index c229c7b..6f5be9f 100644 --- a/main.tf +++ b/main.tf @@ -85,7 +85,7 @@ module "nat-gateway" { access_config = [ { - nat_ip = "${element(concat(google_compute_address.default.*.address, data.google_compute_address.default.*.address, list("")), 0)}" + nat_ip = "${element(concat(google_compute_address.default.*.address, data.google_compute_address.default.*.address, list(var.external_ip_address)), 0)}" }, ] } @@ -117,7 +117,7 @@ resource "google_compute_firewall" "nat-gateway" { } resource "google_compute_address" "default" { - count = "${var.module_enabled && var.ip_address_name == "" ? 1 : 0}" + count = "${var.module_enabled && var.ip_address_name == "" && var.use_external_ip_address != "true" ? 1 : 0}" name = "${local.zonal_tag}" project = "${var.project}" region = "${var.region}" diff --git a/outputs.tf b/outputs.tf index 87302fe..5d40b38 100644 --- a/outputs.tf +++ b/outputs.tf @@ -31,7 +31,7 @@ output instance { output external_ip { description = "The external IP address of the NAT gateway instance." - value = "${element(concat(google_compute_address.default.*.address, data.google_compute_address.default.*.address, list("")), 0)}" + value = "${element(concat(google_compute_address.default.*.address, data.google_compute_address.default.*.address, list(var.external_ip_address)), 0)}" } output routing_tag_regional { diff --git a/variables.tf b/variables.tf index f5017ab..d923d75 100644 --- a/variables.tf +++ b/variables.tf @@ -58,6 +58,16 @@ variable ip_address_name { default = "" } +variable external_ip_address { + description = "Address of existing IP reservation to use." + default = "" +} + +variable use_external_ip_address { + description = "Set to true when ip_address input variable is set." + default = "false" +} + variable tags { description = "Additional compute instance network tags to apply route to." type = "list"