-
Notifications
You must be signed in to change notification settings - Fork 1
/
instance-group.tf
136 lines (122 loc) · 3.41 KB
/
instance-group.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
resource "random_id" "getrandom" {
byte_length = 4
}
resource "yandex_iam_service_account" "appname-ig-sa" {
name = "appname-ig-sa"
description = "service account to manage appname_ig"
depends_on = ["yandex_vpc_subnet.subnet"]
}
resource "yandex_resourcemanager_folder_iam_binding" "appname-ig-role-iam-binding" {
folder_id = "${var.folder_id}"
role = "editor"
members = [
"serviceAccount:${yandex_iam_service_account.appname-ig-sa.id}",
]
depends_on = ["yandex_iam_service_account.appname-ig-sa", "yandex_vpc_subnet.subnet"]
}
variable "cluster_size" {
default = 3
}
resource "yandex_compute_instance_group" "appname-ig" {
# name = "test-ig"
name = "appname-ig-${lower(random_id.getrandom.hex)}"
service_account_id = "${yandex_iam_service_account.appname-ig-sa.id}"
folder_id = "${var.folder_id}"
instance_template {
# platform_id = "standard-v2"
platform_id = "standard-v1"
resources {
core_fraction = 5
memory = 1
cores = 1
}
boot_disk {
mode = "READ_WRITE"
initialize_params {
image_id = "${var.image_id}"
size = 10
}
}
network_interface {
network_id = "${yandex_vpc_network.network.id}"
subnet_ids = "${yandex_vpc_subnet.subnet.*.id}"
nat = true
}
labels = {
lastupdate = "${var.packer_buildtime}"
# skip_update_ssh_keys = true
}
metadata = {
foo = "bar"
# ssh-keys = "ubuntu:${file("~/.ssh/id_rsa.pub")}"
user-data = "${data.template_file.init.rendered}"
}
}
scale_policy {
fixed_scale {
size = "${var.cluster_size}"
}
}
allocation_policy {
# zones = ["ru-central1-a"]
zones = "${var.zones}"
}
deploy_policy {
max_unavailable = "${var.cluster_size}"
max_creating = "${var.cluster_size}"
max_expansion = "${var.cluster_size}"
max_deleting = "${var.cluster_size}"
}
health_check {
interval = "2"
timeout = "1"
healthy_threshold = "5"
unhealthy_threshold = "5"
# tcp_options = "8080"
http_options {
port = "8080"
path = "/"
}
}
load_balancer {
target_group_labels = {
service = "appname"
}
target_group_name = "appname"
}
depends_on = ["yandex_resourcemanager_folder_iam_binding.appname-ig-role-iam-binding", "yandex_iam_service_account.appname-ig-sa", "yandex_vpc_subnet.subnet"]
}
output "ig-id" {
value = yandex_compute_instance_group.appname-ig.id
}
output "listener-address" {
value = yandex_lb_network_load_balancer.appname-lb.listener.*.external_address_spec
}
resource "yandex_lb_network_load_balancer" "appname-lb" {
name = "appname-lb-${lower(random_id.getrandom.hex)}"
listener {
name = "appname-listener-8080-${lower(random_id.getrandom.hex)}"
port = 8080
external_address_spec {
ip_version = "ipv4"
}
}
listener {
name = "appname-listener-80-${lower(random_id.getrandom.hex)}"
port = 80
external_address_spec {
ip_version = "ipv4"
}
}
attached_target_group {
target_group_id = "${yandex_compute_instance_group.appname-ig.load_balancer.0.target_group_id}"
healthcheck {
name = "http"
http_options {
port = 8080
path = "/"
}
}
}
depends_on = ["yandex_compute_instance_group.appname-ig", "yandex_vpc_subnet.subnet"]
}