Skip to content
This repository has been archived by the owner on Apr 7, 2020. It is now read-only.

Enable cloud-nat for GCP #379

Merged
merged 1 commit into from
Oct 24, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@ resource "google_compute_subnetwork" "subnetwork-nodes" {
region = "{{ required "google.region is required" .Values.google.region }}"
}

resource "google_compute_router" "router"{
name = "{{ required "clusterName is required" .Values.clusterName }}-cloud-router"
region = "{{ required "google.region is required" .Values.google.region }}"
network = "{{ required "vpc.name is required" .Values.vpc.name }}"

bgp {
asn = 64514
}
}

resource "google_compute_router_nat" "nat" {
name = "{{ required "clusterName is required" .Values.clusterName }}-cloud-nat"
router = "${google_compute_router.router.name}"
region = "{{ required "google.region is required" .Values.google.region }}"
nat_ip_allocate_option = "AUTO_ONLY"
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"

log_config {
enable = true
filter = "ERRORS_ONLY"
}
}

{{ if .Values.networks.internal -}}
resource "google_compute_subnetwork" "subnetwork-internal" {
name = "{{ required "clusterName is required" .Values.clusterName }}-internal"
Expand All @@ -39,6 +62,8 @@ resource "google_compute_subnetwork" "subnetwork-internal" {
region = "{{ required "google.region is required" .Values.google.region }}"
}
{{- end}}


//=====================================================================
//= Firewall
//=====================================================================
Expand Down Expand Up @@ -121,6 +146,14 @@ output "{{ .Values.outputKeys.vpcName }}" {
value = "{{ required "vpc.name is required" .Values.vpc.name }}"
}

output "{{ .Values.outputKeys.cloudRouter }}" {
value = "${google_compute_router.router.name}"
}

output "{{ .Values.outputKeys.cloudNAT }}" {
value = "${google_compute_router_nat.nat.name}"
}

output "{{ .Values.outputKeys.serviceAccountEmail }}" {
value = "${google_service_account.serviceaccount.email}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ networks:

outputKeys:
vpcName: vpc_name
cloudNAT: cloud_nat
cloudRouter: cloud_router
subnetNodes: subnet_nodes
serviceAccountEmail: service_account_email
subnetInternal: subnet_internal
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ metadata:
namespace: {{ $.Release.Namespace }}
spec:
canIpForward: {{ $machineClass.canIpForward }}
disableExternalIP: {{ $machineClass.disableExternalIP }}
deletionProtection: {{ $machineClass.deletionProtection }}
description: {{ $machineClass.description }}
disks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ machineClasses:
region: europe-west1
zone: europe-west1-b
canIpForward: true
disableExternalIP: true
deletionProtection: false
description: An optional description for machines created by that class.
disks:
Expand Down
1 change: 1 addition & 0 deletions controllers/provider-gcp/pkg/controller/worker/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error {
"region": w.worker.Spec.Region,
"zone": zone,
"canIpForward": true,
"disableExternalIP": true,
"deletionProtection": false,
"description": fmt.Sprintf("Machine of Shoot %s created by machine-controller-manager.", w.worker.Name),
"disks": []map[string]interface{}{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ var _ = Describe("Machines", func() {
var (
defaultMachineClass = map[string]interface{}{
"region": region,
"disableExternalIP": true,
"canIpForward": true,
"deletionProtection": false,
"description": fmt.Sprintf("Machine of Shoot %s created by machine-controller-manager.", name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const (

// TerraformerOutputKeyVPCName is the name of the vpc_name terraform output variable.
TerraformerOutputKeyVPCName = "vpc_name"
// TerraformOutputKeyCloudNAT is the name of the cloud_nat terraform output variable.
TerraformOutputKeyCloudNAT = "cloud_nat"
// TerraformOutputKeyCloudRouter is the name of the cloud_router terraform output variable.
TerraformOutputKeyCloudRouter = "cloud_router"
// TerraformerOutputKeyServiceAccountEmail is the name of the service_account_email terraform output variable.
TerraformerOutputKeyServiceAccountEmail = "service_account_email"
// TerraformerOutputKeySubnetNodes is the name of the subnet_nodes terraform output variable.
Expand Down Expand Up @@ -90,6 +94,8 @@ func ComputeTerraformerChartValues(
},
"outputKeys": map[string]interface{}{
"vpcName": TerraformerOutputKeyVPCName,
"cloudNAT": TerraformOutputKeyCloudNAT,
"cloudRouter": TerraformOutputKeyCloudRouter,
"serviceAccountEmail": TerraformerOutputKeyServiceAccountEmail,
"subnetNodes": TerraformerOutputKeySubnetNodes,
"subnetInternal": TerraformerOutputKeySubnetInternal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ var _ = Describe("Terraform", func() {
},
"outputKeys": map[string]interface{}{
"vpcName": TerraformerOutputKeyVPCName,
"cloudNAT": TerraformOutputKeyCloudNAT,
"cloudRouter": TerraformOutputKeyCloudRouter,
"serviceAccountEmail": TerraformerOutputKeyServiceAccountEmail,
"subnetNodes": TerraformerOutputKeySubnetNodes,
"subnetInternal": TerraformerOutputKeySubnetInternal,
Expand Down Expand Up @@ -145,6 +147,8 @@ var _ = Describe("Terraform", func() {
},
"outputKeys": map[string]interface{}{
"vpcName": TerraformerOutputKeyVPCName,
"cloudNAT": TerraformOutputKeyCloudNAT,
"cloudRouter": TerraformOutputKeyCloudRouter,
"serviceAccountEmail": TerraformerOutputKeyServiceAccountEmail,
"subnetNodes": TerraformerOutputKeySubnetNodes,
"subnetInternal": TerraformerOutputKeySubnetInternal,
Expand Down