-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcfssl.tf
148 lines (116 loc) · 3.37 KB
/
cfssl.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// IAM and Service Account
resource "google_service_account" "cfssl" {
account_id = "cfssl-${var.cluster_name}"
display_name = "service account for cfssl instance"
}
// Volume
resource "google_compute_disk" "cfssl-data" {
name = "cfssl-data-${var.cluster_name}"
zone = var.available_zones[0]
size = 5
type = "pd-standard"
lifecycle {
prevent_destroy = true
}
// The value can only contain lowercase letters, numeric characters, underscores and dashes
labels = {
name = "cfssl-${var.cluster_name}-data-vol-0"
component = "${var.cluster_name}-cfssl"
cluster = var.cluster_name
}
}
resource "random_string" "cfssl_suffix" {
length = 4
special = false
upper = false
keepers = {
userdata = var.cfssl_user_data
}
}
// reserve IP address
resource "google_compute_address" "cfssl_server_address" {
name = "cfssl-server-address-0-${var.cluster_name}"
address_type = "INTERNAL"
subnetwork = var.subnetwork_link
address = var.cfssl_server_address
}
// Instance
resource "google_compute_instance" "cfssl" {
name = "cfssl-${var.cluster_name}-${random_string.cfssl_suffix.result}"
description = "cfssl box"
machine_type = var.cfssl_machine_type
zone = var.available_zones[0]
allow_stopping_for_update = true
boot_disk {
initialize_params {
image = var.container_linux_image
}
auto_delete = true
}
lifecycle {
ignore_changes = [boot_disk.0.initialize_params.0.image]
}
attached_disk {
source = google_compute_disk.cfssl-data.self_link
mode = "READ_WRITE"
device_name = var.cfssl_data_volume_id
}
network_interface {
subnetwork = var.subnetwork_link
network_ip = google_compute_address.cfssl_server_address.address
}
tags = concat(["cfssl-${var.cluster_name}"], var.cluster_instance_tags)
labels = {
cluster = var.cluster_name
name = "${var.cluster_name}-cfssl"
}
metadata = {
user-data = var.cfssl_user_data
}
service_account {
email = google_service_account.cfssl.email
scopes = []
}
}
// Firewall Rules
resource "google_compute_firewall" "allow-etcd-to-cfssl" {
name = "allow-etcd-to-cfssl-${var.cluster_name}"
network = var.network_link
allow {
protocol = "tcp"
ports = ["8888"]
}
source_tags = ["etcd-${var.cluster_name}"]
direction = "INGRESS"
target_tags = ["cfssl-${var.cluster_name}"]
}
resource "google_compute_firewall" "allow-masters-to-cfssl" {
name = "allow-masters-to-cfssl-${var.cluster_name}"
network = var.network_link
allow {
protocol = "tcp"
ports = ["8888", "8889"]
}
source_tags = ["master-${var.cluster_name}"]
direction = "INGRESS"
target_tags = ["cfssl-${var.cluster_name}"]
}
resource "google_compute_firewall" "allow-workers-to-cfssl" {
name = "allow-workers-to-cfssl-${var.cluster_name}"
network = var.network_link
// 9080 for promtail, 8888-9 for certs, 9100 for node exporter
allow {
protocol = "tcp"
ports = ["9080", "8888", "8889", "9100"]
}
source_tags = ["worker-${var.cluster_name}"]
direction = "INGRESS"
target_tags = ["cfssl-${var.cluster_name}"]
}
resource "google_dns_record_set" "cfssl" {
name = "cfssl.${var.dns_domain}."
type = "A"
ttl = 30
managed_zone = var.dns_zone
rrdatas = [google_compute_instance.cfssl.network_interface[0].network_ip]
}