-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcp.tf
82 lines (71 loc) · 2.96 KB
/
gcp.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
resource "google_compute_network" "vpc_gke" {
name = var.name_vpc_gke
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "subnet1" {
name = var.name_subnet_gke
ip_cidr_range = "10.141.0.0/20"
region = var.region
private_ip_google_access = true
network = google_compute_network.vpc_gke.id
}
resource "google_container_cluster" "gke" {
name = var.gke_cluster_name
location = var.region
initial_node_count = 1
remove_default_node_pool = true
network = var.name_vpc_gke
subnetwork = var.name_subnet_gke
master_auth {
username = var.usergke
password = var.passgke
client_certificate_config {
issue_client_certificate = true
}
}
depends_on = [ google_compute_subnetwork.subnet1 ]
}
resource "google_container_node_pool" "node_pool" {
name = var.gke_nodepool_name
location = var.region
cluster = var.gke_cluster_name
node_count = 1
node_config {
image_type = "cos_containerd"
preemptible = true
machine_type = "n1-standard-1"
labels = {
database = "rds"
}
metadata = {
disable-legacy-endpoints = "true"
}
}
depends_on = [ google_container_cluster.gke ]
}
data "google_compute_instance_group" "gcig_0" {
// regex for retrieving the name of the instance group from the link
name = "${regex("([^/]+)/?$" , "${google_container_node_pool.node_pool.instance_group_urls.0}").0}"
// regex for retrieving the zone of the instance group fomr the link
zone = "${regex("${var.region}-?[abc]" , "${google_container_node_pool.node_pool.instance_group_urls.0}")}"
}
data "google_compute_instance_group" "gcig_1" {
name = "${regex("([^/]+)/?$" , "${google_container_node_pool.node_pool.instance_group_urls.1}").0}"
zone = "${regex("${var.region}-?[abc]" , "${google_container_node_pool.node_pool.instance_group_urls.1}")}"
}
data "google_compute_instance_group" "gcig_2" {
name = "${regex("([^/]+)/?$" , "${google_container_node_pool.node_pool.instance_group_urls.2}").0}"
zone = "${regex("${var.region}-?[abc]" , "${google_container_node_pool.node_pool.instance_group_urls.2}")}"
}
data "google_compute_instance" "node1" {
self_link = "${sort(data.google_compute_instance_group.gcig_0.instances)[0]}"
zone = "${regex("${var.region}-?[abc]" , "${google_container_node_pool.node_pool.instance_group_urls.0}")}"
}
data "google_compute_instance" "node2" {
self_link = "${sort(data.google_compute_instance_group.gcig_1.instances)[0]}"
zone = "${regex("${var.region}-?[abc]" , "${google_container_node_pool.node_pool.instance_group_urls.1}")}"
}
data "google_compute_instance" "node3" {
self_link = "${sort(data.google_compute_instance_group.gcig_2.instances)[0]}"
zone = "${regex("${var.region}-?[abc]" , "${google_container_node_pool.node_pool.instance_group_urls.2}")}"
}