Skip to content

Commit 5a20cb7

Browse files
added networking
1 parent f17b7ff commit 5a20cb7

File tree

3 files changed

+77
-22
lines changed

3 files changed

+77
-22
lines changed

_example/example.tf

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,52 @@ provider "google" {
44
zone = var.gcp_zone
55
}
66

7+
module "vpc" {
8+
source = "clouddrove/vpc/gcp"
9+
version = "1.0.0"
10+
11+
name = "vpc"
12+
environment = var.environment
13+
label_order = var.label_order
14+
google_compute_network_enabled = true
15+
enable_ula_internal_ipv6 = true
16+
internal_ipv6_range = "fd20:222:dd14:0:0:0:0:0/48"
17+
}
18+
19+
module "subnet" {
20+
source = "clouddrove/subnet/gcp"
21+
version = "1.0.1"
22+
23+
name = "subnet"
24+
environment = var.environment
25+
label_order = var.label_order
26+
27+
google_compute_subnetwork_enabled = true
28+
google_compute_firewall_enabled = true
29+
google_compute_router_nat_enabled = true
30+
module_enabled = true
31+
ipv6_access_type = "EXTERNAL"
32+
network = module.vpc.vpc_id
33+
project_id = "clouddrove"
34+
private_ip_google_access = true
35+
allow = [{ "protocol" : "tcp", "ports" : ["1-65535"] }]
36+
source_ranges = ["10.10.0.0/16"]
37+
asn = 64514
38+
nat_ip_allocate_option = "MANUAL_ONLY"
39+
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
40+
filter = "ERRORS_ONLY"
41+
dest_range = "0.0.0.0/0"
42+
next_hop_gateway = "default-internet-gateway"
43+
priority = 1000
44+
secondary_ip_ranges = [{ "range_name" : "services", "ip_cidr_range" : "10.1.0.0/16" }, { "range_name" : "pods", "ip_cidr_range" : "10.3.0.0/16" }]
45+
}
46+
747
module "Service-account" {
848
source = "clouddrove/Service-account/gcp"
949
version = "1.0.0"
1050

1151

12-
name = "test"
52+
name = "Service-account"
1353
environment = var.environment
1454
label_order = var.label_order
1555

@@ -19,11 +59,17 @@ module "Service-account" {
1959
module "gke" {
2060
source = "../"
2161

22-
name = "test-gke"
62+
name = "gke"
63+
environment = var.environment
64+
label_order = var.label_order
65+
66+
network = module.vpc.vpc_id
67+
subnetwork = module.subnet.id
2368
module_enabled = true
2469
google_container_cluster_enabled = true
2570
location = "europe-west3"
26-
remove_default_node_pool = true
71+
remove_default_node_pool = false
72+
gke_version = "1.25.6-gke.1000"
2773
initial_node_count = 1
2874
google_container_node_pool_enabled = true
2975
node_count = 1

main.tf

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ module "labels" {
1010
resource "google_container_cluster" "primary" {
1111
count = var.google_container_cluster_enabled && var.module_enabled ? 1 : 0
1212

13-
1413
name = module.labels.id
1514
location = var.location
1615

16+
network = var.network
17+
subnetwork = var.subnetwork
1718
remove_default_node_pool = var.remove_default_node_pool
1819
initial_node_count = var.initial_node_count
20+
min_master_version = var.gke_version
1921
}
2022

2123
resource "google_container_node_pool" "node_pool" {
@@ -38,27 +40,18 @@ resource "google_container_node_pool" "node_pool" {
3840
auto_upgrade = var.auto_upgrade
3941
}
4042

41-
4243
node_config {
43-
image_type = var.image_type
44-
machine_type = var.machine_type
45-
44+
image_type = var.image_type
45+
machine_type = var.machine_type
4646
service_account = var.service_account
47-
48-
49-
50-
51-
disk_size_gb = var.disk_size_gb
52-
disk_type = var.disk_type
53-
preemptible = var.preemptible
54-
55-
47+
disk_size_gb = var.disk_size_gb
48+
disk_type = var.disk_type
49+
preemptible = var.preemptible
5650
}
5751

5852
lifecycle {
5953
ignore_changes = [initial_node_count]
6054
create_before_destroy = false
61-
6255
}
6356

6457
timeouts {
@@ -76,8 +69,5 @@ resource "null_resource" "configure_kubectl" {
7669
KUBECONFIG = var.kubectl_config_path != "" ? var.kubectl_config_path : ""
7770
}
7871
}
79-
8072
depends_on = [google_container_node_pool.node_pool]
81-
}
82-
83-
73+
}

variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,22 @@ variable "region" {
169169
default = ""
170170
description = "Google Cloud region"
171171
}
172+
variable "network" {
173+
type = string
174+
default = ""
175+
description = "A reference (self link) to the VPC network to host the cluster in"
176+
177+
}
178+
179+
variable "subnetwork" {
180+
type = string
181+
default = ""
182+
description = "A reference (self link) to the subnetwork to host the cluster in"
183+
184+
}
185+
variable "gke_version" {
186+
type = string
187+
default = ""
188+
description = "The minimum version of the master. "
189+
190+
}

0 commit comments

Comments
 (0)