GCP just introduced a new Cloud NAT. - https://cloud.google.com/nat/docs/overview
Would be nice to have support for it in Terraform along with all our other resources we already have.
resource "google_cloud_router" "primary" {
name = "primary-router"
network = google_compute_network.default.name
region = "asia-east1"
}
resource "google_cloud_nat" "primary" {
name = "primary-nat"
network = google_compute_network.default.name
region = "asia-east1"
router = google_cloud_router.primary.name
nat_mapping {
source = "both" // or "primary" / "secondary"
ip_address = google_compute_address.nat.address // omit to have ip be automatic
}
settings {
min_ports = 64
timeouts {
udp = 30
tcp_established = 1200
tcp_transitory = 30
icmp = 30
}
}
}
Looking at https://cloud.google.com/nat/docs/apis#rest_api, it looks like all the operations are meant to be performed on the Router API resource, so it may make more sense to have this be a sub-block within Router. Maybe. It could be a candidate for fine-grained resourcehood.
@paddycarver Yup, the sample terraform script was designed based on the currently google UI, but under the hood, I suspect they are just making one API request. Either way, being able to import/configure the cloud NATs in terraform would be great.
API wise, this should be very similar to google_compute_router_interface. Creating this as a google_compute_router_nat should be relatively straightforward:
resource "google_compute_router_nat" "nat-gateway" {
name = "nat-gateway"
router = "router-1"
region = "us-central1"
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
nat_ip_allocate_option = "AUTO_ONLY"
min_ports_per_vm = 64
tcp_establishedIdle_timeout_sec = 1200
udp_itle_timeout_sec = 30
}
API fields described in https://cloud.google.com/compute/docs/reference/rest/beta/routers/insert
Just stumbled upon this one while terraforming private Kubernetes clusters (in isolated VPCs). In this case the Kubernetes nodes needs outbound connectivity for fetching container images. I created a Cloud NAT manually and everything works as expected then.
The possibility to integrate that into my terraform workflow as well would be superb. Looking forward to see this resource landing in the google-beta provider ๐
@akoenig, if all your container images are hosted on gcr.io, you can fetch them with Private Google Access, which is free.
@drebes Yap, I know that. The setup uses images from other registries like quay.io (e.g. nginx-ingress, etc.) Unfortunately, this is not an option, but thanks for mentioning it. ๐
This should be done within the month of November, folks, and released as soon after completion as is feasible. :) Thanks for your patience.
I've download google-beta plugin and still get error
google_compute_router_nat.cloud-nat: Provider doesn't support resource: google_compute_router_nat
plugin version
terraform-provider-google-beta_v1.19.0_x4
Router NAT isn't in 1.19, which was released in early october. It'll be in 1.20, to be released soon.
In the meantime, you will need to compile the plug-in yourself and put it in .terraform/plugins/YOUR_ARCHITECTURE/ for so that it gets used.
thanks for advice
Just a heads up that 1.20.0 has been released. ๐
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error ๐ค ๐ , please reach out to my human friends ๐ [email protected]. Thanks!
Most helpful comment
This should be done within the month of November, folks, and released as soon after completion as is feasible. :) Thanks for your patience.