-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
123 lines (94 loc) · 2.51 KB
/
main.tf
File metadata and controls
123 lines (94 loc) · 2.51 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
terraform {
required_providers {
yandex = {
source = "yandex-cloud/yandex"
}
}
required_version = ">= 0.13"
}
provider "yandex" {
zone = "ru-central1-a"
}
resource "yandex_compute_image" "ubuntu_2004" {
source_family = "ubuntu-2004-lts"
}
resource "yandex_compute_image" "centos-7" {
source_family = "centos-7"
}
#Create VM-1, установка nginx средставми ansible
resource "yandex_compute_instance" "node-1-ubuntu" {
name = "ubuntu"
resources {
cores = 1
memory = 2
}
boot_disk {
initialize_params {
image_id = yandex_compute_image.ubuntu_2004.id
}
}
network_interface {
subnet_id = yandex_vpc_subnet.subnet-1.id
nat = true
}
metadata = {
ssh-keys = "ubuntu:${file("~/.ssh/id_rsa.pub")}"
}
connection {
type = "ssh"
user = "ubuntu"
private_key = file("~/.ssh/id_rsa")
host = yandex_compute_instance.node-1-ubuntu.network_interface.0.nat_ip_address
}
provisioner "remote-exec" {
inline = ["echo 'Im ready!'"]
}
provisioner "local-exec" {
command = "ansible-playbook -u ubuntu -i '${self.network_interface.0.nat_ip_address},' --private-key ~/.ssh/id_rsa nginx.yml"
}
}
resource "yandex_vpc_network" "network-1" {
name = "network1"
}
resource "yandex_vpc_subnet" "subnet-1" {
name = "subnet-1"
zone = "ru-central1-a"
network_id = yandex_vpc_network.network-1.id
v4_cidr_blocks = ["192.168.10.0/24"]
}
#Create VM-2, установка nginx стредставми Cloudinit
resource "yandex_compute_instance" "node-2-centos" {
name = "centos"
resources {
cores = 2
memory = 2
}
boot_disk {
initialize_params {
image_id = yandex_compute_image.centos-7.id
}
}
network_interface {
subnet_id = yandex_vpc_subnet.subnet-1.id
nat = true
}
metadata = {
#ssh-keys = "centos:${file("~/.ssh/id_rsa.pub")}"
user-data = "${file("user-data.yml")}"
}
}
output "internal_ip_address_node_1_ubuntu" {
value = yandex_compute_instance.node-1-ubuntu.network_interface.0.ip_address
}
output "internal_ip_address_ndeo_2_centos" {
value = yandex_compute_instance.node-2-centos.network_interface.0.ip_address
}
output "external_ip_address_node_1_ubuntu" {
value = yandex_compute_instance.node-1-ubuntu.network_interface.0.nat_ip_address
}
output "external_ip_address_ndeo_2_centos" {
value = yandex_compute_instance.node-2-centos.network_interface.0.nat_ip_address
}
output "subnet-1" {
value = yandex_vpc_subnet.subnet-1.id
}