我想通过terraform连接我的“专用”网络(没有外部IP的实例)。
任务:将经典方案从AWS迁移到GCP:一个VPC网络,公共网络中的堡垒主机,专用网络中的所有计算机,无需外部IP。将NAT网关用于专用网络。
resource "google_compute_router" "router" {
name = "my-router1"
network = "${var.gcp_project_name}-net"
bgp {
asn = 64514
}
}
resource "google_compute_router_nat" "advanced-nat" {
name = "nat-1"
router = "${google_compute_router.router.name}"
region = "us-west2"
nat_ip_allocate_option = "MANUAL_ONLY"
nat_ips = ["10.0.0.0/16"]
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
subnetwork {
name = "${var.gcp_project_name}-${var.gcp_region_name}-private-subnet"
}
}
答案 0 :(得分:0)
# VPC
resource "google_compute_network" "gcp_project_name" {
name = "${var.gcp_project_name}-net"
auto_create_subnetworks = "false"
}
# PRIVATE SUBNET
resource "google_compute_subnetwork" "gcp_project_name_private_subnet" {
name = "${var.gcp_project_name}-${var.gcp_region_name}-private-subnet"
ip_cidr_range = "10.0.0.0/16"
network = "${google_compute_network.gcp_project_name.self_link}"
region = "${var.gcp_region_name}"
}
# PUBLIC SUBNET
resource "google_compute_subnetwork" "gcp_project_name_public_subnet" {
name = "${var.gcp_project_name}-${var.gcp_region_name}-public-subnet"
ip_cidr_range = "10.8.0.0/16"
network = "${google_compute_network.gcp_project_name.self_link}"
region = "${var.gcp_region_name}"
}
resource "google_compute_router" "router" {
name = "${var.gcp_router_name}"
network = "${var.gcp_project_name}-net"
region = "${var.gcp_region_name}"
}
resource "google_compute_router_nat" "advanced-nat" {
name = "${var.gcp_nat_name}"
router = "${var.gcp_router_name}"
region = "${var.gcp_region_name}"
nat_ip_allocate_option = "AUTO_ONLY"
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
subnetwork {
name = "${google_compute_subnetwork.gcp_project_name_private_subnet.self_link}"
}
}