-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
99 lines (83 loc) · 2.12 KB
/
main.tf
File metadata and controls
99 lines (83 loc) · 2.12 KB
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
terraform {
required_version = "~> 1.1.0"
required_providers {
yandex = {
source = "yandex-cloud/yandex"
version = "0.61.0"
}
}
backend "s3" {
endpoint = "storage.yandexcloud.net"
region = "ru-central1"
key = "s3/terraform.tfstate"
skip_region_validation = true
skip_credentials_validation = true
}
}
provider "yandex" {
token = var.auth_token
cloud_id = var.cloud_id
folder_id = var.folder_id
zone = "ru-central1-a"
}
# Create VPC network
resource "yandex_vpc_network" "lab_net" {
name = "lab-network"
}
# Create VPC subnet-1
resource "yandex_vpc_subnet" "lab_subnet_a" {
v4_cidr_blocks = ["192.168.10.0/28"]
zone = "ru-central1-a"
network_id = yandex_vpc_network.lab_net.id
name = "lab-subnet-a"
}
# Create VPC subnet-2
resource "yandex_vpc_subnet" "lab_subnet_b" {
v4_cidr_blocks = ["192.168.11.0/28"]
zone = "ru-central1-b"
network_id = yandex_vpc_network.lab_net.id
name = "lab-subnet-b"
}
# Create lemp instance
module "ya_instance_1" {
source = "./modules/instance"
instance_family_image = "lemp"
vpc_subnet_id = yandex_vpc_subnet.lab_subnet_a.id
instance_zone = "ru-central1-a"
}
# Create lamp instance
module "ya_instance_2" {
source = "./modules/instance"
vpc_subnet_id = yandex_vpc_subnet.lab_subnet_b.id
instance_zone = "ru-central1-b"
}
# Create target group
resource "yandex_lb_target_group" "tg" {
name = "lb-group"
target {
subnet_id = yandex_vpc_subnet.lab_subnet_a.id
address = module.ya_instance_1.internal_ip_address
}
target {
subnet_id = yandex_vpc_subnet.lab_subnet_b.id
address = module.ya_instance_2.internal_ip_address
}
}
# Create network load balancer
resource "yandex_lb_network_load_balancer" "lb" {
name = "network-load-balancer"
region_id = "ru-central1"
listener {
name = "listener"
port = 80
}
attached_target_group {
target_group_id = yandex_lb_target_group.tg.id
healthcheck {
name = "http"
http_options {
port = 80
}
}
}
}