Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

added external_ip_address and use_external_ip_address variables #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
},
]
}
Expand Down Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down