Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #23

Open
wants to merge 102 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
7819013
Update hw-02.md
borbul2007 Sep 2, 2024
c15772a
Update hw-02.md
borbul2007 Sep 2, 2024
8046b34
Update variables.tf
borbul2007 Sep 2, 2024
2629556
Update variables.tf
borbul2007 Sep 2, 2024
8e197da
Update variables.tf
borbul2007 Sep 2, 2024
9f6b458
Update README.md
Sep 2, 2024
3428736
Update hw-02.md
borbul2007 Sep 2, 2024
a2e4d97
Update main.tf
borbul2007 Sep 2, 2024
2339ab5
Update variables.tf
borbul2007 Sep 2, 2024
95404f7
Update variables.tf
borbul2007 Sep 2, 2024
c908c8e
Update README.md
Sep 2, 2024
ed31ce6
Update main.tf
borbul2007 Sep 2, 2024
565efd2
Update vms_platform.tf
borbul2007 Sep 2, 2024
fa8ece2
Update main.tf
borbul2007 Sep 2, 2024
6ec1d62
Update main.tf
borbul2007 Sep 2, 2024
acbcee8
Update main.tf
borbul2007 Sep 2, 2024
87df691
Update vms_platform.tf
borbul2007 Sep 2, 2024
33ff8f3
Update main.tf
borbul2007 Sep 2, 2024
28b3c84
Update variables.tf
borbul2007 Sep 2, 2024
1ac0888
Update vms_platform.tf
borbul2007 Sep 2, 2024
aa49589
Update variables.tf
borbul2007 Sep 2, 2024
336c1e7
Update main.tf
borbul2007 Sep 2, 2024
c3be8f2
Update providers.tf
borbul2007 Sep 2, 2024
ec5b07e
Update main.tf
borbul2007 Sep 2, 2024
b690625
Update main.tf
borbul2007 Sep 2, 2024
00193d4
Update vms_platform.tf
borbul2007 Sep 2, 2024
cc512aa
Update main.tf
borbul2007 Sep 2, 2024
a7152aa
Update main.tf
borbul2007 Sep 2, 2024
88314db
Update main.tf
borbul2007 Sep 2, 2024
aead6ea
Update main.tf
borbul2007 Sep 2, 2024
c4cca15
Update vms_platform.tf
borbul2007 Sep 2, 2024
d6ac021
Update main.tf
borbul2007 Sep 2, 2024
880d09d
Update vms_platform.tf
borbul2007 Sep 2, 2024
5df32e0
Update main.tf
borbul2007 Sep 2, 2024
fb7a3fd
Update main.tf
borbul2007 Sep 3, 2024
43ea244
Update vms_platform.tf
borbul2007 Sep 3, 2024
73ea610
Update providers.tf
borbul2007 Sep 3, 2024
8b6c15d
Update vms_platform.tf
borbul2007 Sep 3, 2024
2244816
Update main.tf
borbul2007 Sep 3, 2024
a7e4a0c
Update vms_platform.tf
borbul2007 Sep 3, 2024
ebbdfa9
Update main.tf
borbul2007 Sep 3, 2024
d4c5968
Update hw-02.md
borbul2007 Sep 3, 2024
c324846
Update outputs.tf
borbul2007 Sep 3, 2024
183161e
Update outputs.tf
borbul2007 Sep 3, 2024
20eaa33
Update outputs.tf
borbul2007 Sep 3, 2024
efe2dc2
Update outputs.tf
borbul2007 Sep 3, 2024
f5c013c
Update outputs.tf
borbul2007 Sep 3, 2024
06b3b99
Update
borbul2007 Sep 3, 2024
04c9da0
Update
borbul2007 Sep 3, 2024
ac659c6
Update
borbul2007 Sep 3, 2024
c43bc7b
U
borbul2007 Sep 3, 2024
2859069
U
borbul2007 Sep 3, 2024
e3fee8e
u
borbul2007 Sep 3, 2024
676d9c0
u
borbul2007 Sep 3, 2024
61a41ba
u
borbul2007 Sep 3, 2024
abf3313
u
borbul2007 Sep 3, 2024
a321c00
u
borbul2007 Sep 3, 2024
11d1b7f
u
borbul2007 Sep 3, 2024
ed6bd67
u
borbul2007 Sep 3, 2024
0036e2b
u
borbul2007 Sep 3, 2024
9636a36
u
borbul2007 Sep 3, 2024
3f94bfc
uu
borbul2007 Sep 3, 2024
111bb63
u
borbul2007 Sep 3, 2024
8f62b3f
u
borbul2007 Sep 3, 2024
b5313e6
u
borbul2007 Sep 3, 2024
f97409b
u
borbul2007 Sep 3, 2024
5dd588e
u
borbul2007 Sep 3, 2024
8778ae1
u
borbul2007 Sep 3, 2024
42da085
u
borbul2007 Sep 3, 2024
ba5edf2
u
borbul2007 Sep 3, 2024
2d859b0
u
borbul2007 Sep 3, 2024
2fe2b3e
uu
borbul2007 Sep 3, 2024
0ed0fc7
Update vms_platform.tf
borbul2007 Sep 3, 2024
ab424ee
h
borbul2007 Sep 3, 2024
2ed4861
f
borbul2007 Sep 3, 2024
4d92e56
g
borbul2007 Sep 3, 2024
97e9311
t
borbul2007 Sep 3, 2024
2f96cc3
h
borbul2007 Sep 3, 2024
a962403
yy
borbul2007 Sep 3, 2024
782b820
rr
borbul2007 Sep 3, 2024
4d2716b
dd
borbul2007 Sep 3, 2024
db243ab
ff
borbul2007 Sep 3, 2024
bbad660
f
borbul2007 Sep 3, 2024
4812353
t
borbul2007 Sep 3, 2024
d1909d9
dd
borbul2007 Sep 3, 2024
746d9fb
dsas
borbul2007 Sep 3, 2024
4974b3e
Update
borbul2007 Sep 3, 2024
4370f51
ff
borbul2007 Sep 3, 2024
4c53119
d
borbul2007 Sep 3, 2024
3063627
p
borbul2007 Sep 3, 2024
dff9cce
h
borbul2007 Sep 3, 2024
a6216ef
f
borbul2007 Sep 3, 2024
962ad14
c
borbul2007 Sep 3, 2024
652c6d8
fdgfdg
borbul2007 Sep 3, 2024
d42024f
f
borbul2007 Sep 3, 2024
8d58485
df
borbul2007 Sep 3, 2024
f7c3d92
sa
borbul2007 Sep 3, 2024
c810147
sdsa
borbul2007 Sep 3, 2024
50d905d
Update
borbul2007 Sep 3, 2024
5636264
Upadate
borbul2007 Sep 3, 2024
596a8a6
Update hw-02.md
borbul2007 Sep 3, 2024
a4840a8
Update hw-05.md
borbul2007 Sep 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions 02/hw-02.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@
2. Создайте сервисный аккаунт и ключ. [service_account_key_file](https://terraform-provider.yandexcloud.net).
4. Сгенерируйте новый или используйте свой текущий ssh-ключ. Запишите его открытую(public) часть в переменную **vms_ssh_public_root_key**.
5. Инициализируйте проект, выполните код. Исправьте намеренно допущенные синтаксические ошибки. Ищите внимательно, посимвольно. Ответьте, в чём заключается их суть.
6. Подключитесь к консоли ВМ через ssh и выполните команду ``` curl ifconfig.me```.
> В большенстве своём параметры либо не указаны, либо указаны не верно.
7. Подключитесь к консоли ВМ через ssh и выполните команду ``` curl ifconfig.me```.
Примечание: К OS ubuntu "out of a box, те из коробки" необходимо подключаться под пользователем ubuntu: ```"ssh ubuntu@vm_ip_address"```. Предварительно убедитесь, что ваш ключ добавлен в ssh-агент: ```eval $(ssh-agent) && ssh-add``` Вы познакомитесь с тем как при создании ВМ создать своего пользователя в блоке metadata в следующей лекции.;
8. Ответьте, как в процессе обучения могут пригодиться параметры ```preemptible = true``` и ```core_fraction=5``` в параметрах ВМ.

В качестве решения приложите:

- скриншот ЛК Yandex Cloud с созданной ВМ, где видно внешний ip-адрес;
- скриншот консоли, curl должен отобразить тот же внешний ip-адрес;
- скриншот ЛК Yandex Cloud с созданной ВМ, где видно внешний ip-адрес;\
![ter-homeworks-02-task1-1](https://github.com/user-attachments/assets/fafd6433-e136-4a02-b293-701592d40cd6) \
- скриншот консоли, curl должен отобразить тот же внешний ip-адрес;\
![ter-homeworks-02-task1-2](https://github.com/user-attachments/assets/2100b261-82ed-4ea1-b03f-937dc845ced5) \
- ответы на вопросы.


> Прерываемые виртуальные машины, могут быть принудительно остановлены в любой момент. Гарантированная доля CPU, остальное предоставляется по возможности. Эти параметры помогает экономить финансы.
### Задание 2

1. Замените все хардкод-**значения** для ресурсов **yandex_compute_image** и **yandex_compute_instance** на **отдельные** переменные. К названиям переменных ВМ добавьте в начало префикс **vm_web_** . Пример: **vm_web_name**.
Expand All @@ -61,6 +63,8 @@
2. Примените изменения.

В качестве решения приложите вывод значений ip-адресов команды ```terraform output```.
![ter-homeworks-02-task4](https://github.com/user-attachments/assets/a8bb6758-6090-43b5-a144-d73f2546bff4)



### Задание 5
Expand Down
3 changes: 3 additions & 0 deletions 02/src/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
name = "${ var.project }-${ var.env }-platform"
}
65 changes: 49 additions & 16 deletions 02/src/main.tf
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
resource "yandex_vpc_network" "develop" {
name = var.vpc_name
}
resource "yandex_vpc_subnet" "develop" {
name = var.vpc_name
zone = var.default_zone

resource "yandex_vpc_subnet" "develop-a" {
name = var.name_zone-a
zone = var.default_zone-a
network_id = yandex_vpc_network.develop.id
v4_cidr_blocks = var.default_cidr
v4_cidr_blocks = var.default_cidr-zone-a
}
resource "yandex_vpc_subnet" "develop-b" {
name = var.name_zone-b
zone = var.default_zone-b
network_id = yandex_vpc_network.develop.id
v4_cidr_blocks = var.default_cidr-zone-b
}


data "yandex_compute_image" "ubuntu" {
family = "ubuntu-2004-lts"
family = var.vm_yandex_compute_image_family
}
resource "yandex_compute_instance" "platform" {
name = "netology-develop-platform-web"
platform_id = "standart-v4"

resource "yandex_compute_instance" "platform-web" {
name = "${local.name}-web"
platform_id = var.vm_web_yandex_compute_instance_platform_id
zone = var.default_zone-a
resources {
cores = 1
memory = 1
core_fraction = 5
cores = var.vms_resources.web.cores
memory = var.vms_resources.web.memory
core_fraction = var.vms_resources.web.core_fraction
}
boot_disk {
initialize_params {
Expand All @@ -29,13 +37,38 @@ resource "yandex_compute_instance" "platform" {
preemptible = true
}
network_interface {
subnet_id = yandex_vpc_subnet.develop.id
subnet_id = yandex_vpc_subnet.develop-a.id
nat = true
}

metadata = {
serial-port-enable = 1
ssh-keys = "ubuntu:${var.vms_ssh_root_key}"
serial-port-enable = var.metadata.vm.serial-port-enable
ssh-keys = var.metadata.vm.ssh-keys
}
}

resource "yandex_compute_instance" "platform-db" {
name = "${local.name}-db"
platform_id = var.vm_db_yandex_compute_instance_platform_id
zone = var.default_zone-b
resources {
cores = var.vms_resources.db.cores
memory = var.vms_resources.db.memory
core_fraction = var.vms_resources.db.core_fraction
}
boot_disk {
initialize_params {
image_id = data.yandex_compute_image.ubuntu.image_id
}
}
scheduling_policy {
preemptible = true
}
network_interface {
subnet_id = yandex_vpc_subnet.develop-b.id
nat = true
}
metadata = {
serial-port-enable = var.metadata.vm.serial-port-enable
ssh-keys = var.metadata.vm.ssh-keys
}
}
28 changes: 28 additions & 0 deletions 02/src/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
output "develop" {
value = [
{ instance_name = [yandex_compute_instance.platform-web.name, yandex_compute_instance.platform-db.name] },
{ external_ip = [yandex_compute_instance.platform-web.network_interface.0.nat_ip_address, yandex_compute_instance.platform-db.network_interface.0.nat_ip_address] },
{ fqdn = [yandex_compute_instance.platform-web.fqdn, yandex_compute_instance.platform-db.fqdn] }
]
}

/*
output "platform_web_fqdn" {
value = yandex_compute_instance.platform-web.fqdn
}

output "platform_web_external_ip" {
value = yandex_compute_instance.platform-web.network_interface.0.nat_ip_address
}

output "platform_db_instance_name" {
value = yandex_compute_instance.platform-db.name
}

output "platform_db_fqdn" {
value = yandex_compute_instance.platform-db.fqdn
}

output "platform_db_external_ip" {
value = yandex_compute_instance.platform-db.network_interface.0.nat_ip_address
*/
4 changes: 2 additions & 2 deletions 02/src/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ provider "yandex" {
# token = var.token
cloud_id = var.cloud_id
folder_id = var.folder_id
zone = var.default_zone
service_account_key_file = file("~/.authorized_key.json")
zone = var.default_zone-a
service_account_key_file = file("~/key.json")
}
34 changes: 32 additions & 2 deletions 02/src/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ variable "default_zone" {
default = "ru-central1-a"
description = "https://cloud.yandex.ru/docs/overview/concepts/geo-scope"
}

variable "default_cidr" {
type = list(string)
default = ["10.0.1.0/24"]
Expand All @@ -32,10 +33,39 @@ variable "vpc_name" {
}


###ssh vars
variable "vm_web_yandex_compute_image_family" {
type = string
default = "ubuntu-2004-lts"
}

variable "vm_web_yandex_compute_instance_name" {
type = string
default = "netology-develop-platform-web"
}

variable "vm_web_yandex_compute_instance_platform_id" {
type = string
default = "standard-v1"
}

variable "vm_web_yandex_compute_instance_resources_cores" {
type = number
default = 2
}

variable "vm_web_yandex_compute_instance_resources_memory" {
type = number
default = 1
}

variable "vm_web_yandex_compute_instance_resources_core_fraction" {
type = number
default = 5
}

###ssh vars
variable "vms_ssh_root_key" {
type = string
default = "<your_ssh_ed25519_key>"
default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJbFQwlXpyF5D6x8yiptgTG/Are3CfQ94MRINvltKRs2 [email protected]"
description = "ssh-keygen -t ed25519"
}
152 changes: 152 additions & 0 deletions 02/src/vms_platform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
###cloud vars
variable "token" {
type = string
description = "OAuth-token; https://cloud.yandex.ru/docs/iam/concepts/authorization/oauth-token"
}
variable "cloud_id" {
type = string
description = "https://cloud.yandex.ru/docs/resource-manager/operations/cloud/get-id"
}
variable "folder_id" {
type = string
description = "https://cloud.yandex.ru/docs/resource-manager/operations/folder/get-id"
}

variable "vpc_name" {
type = string
default = "develop"
description = "VPC network & subnet name"
}
variable "name_zone-a" {
type = string
default = "develop-ru-central1-a"
description = "https://cloud.yandex.ru/docs/overview/concepts/geo-scope"
}
variable "default_zone-a" {
type = string
default = "ru-central1-a"
description = "https://cloud.yandex.ru/docs/overview/concepts/geo-scope"
}
variable "default_cidr-zone-a" {
type = list(string)
default = ["10.0.1.0/24"]
description = "https://cloud.yandex.ru/docs/vpc/operations/subnet-create"
}

variable "name_zone-b" {
type = string
default = "develop-ru-central1-b"
description = "https://cloud.yandex.ru/docs/overview/concepts/geo-scope"
}
variable "default_zone-b" {
type = string
default = "ru-central1-b"
description = "https://cloud.yandex.ru/docs/overview/concepts/geo-scope"
}
variable "default_cidr-zone-b" {
type = list(string)
default = ["10.0.2.0/24"]
description = "https://cloud.yandex.ru/docs/vpc/operations/subnet-create"
}

variable "vm_yandex_compute_image_family" {
type = string
default = "ubuntu-2004-lts"
}

variable "project" {
type = string
default = "netology"
}
variable "env" {
type = string
default = "develop"
}

variable "vms_resources" {
type = map(object({
cores = number
memory = number
core_fraction = number
}))
default = {
"web" = {
cores = 2
memory = 1
core_fraction = 5
}
"db" = {
cores = 2
memory = 2
core_fraction = 20
}
}
}

variable "vm_web_yandex_compute_instance_name" {
type = string
default = "netology-develop-platform-web"
}
variable "vm_web_yandex_compute_instance_platform_id" {
type = string
default = "standard-v1"
}

/*variable "vm_web_yandex_compute_instance_resources_cores" {
type = number
default = 2
}
variable "vm_web_yandex_compute_instance_resources_memory" {
type = number
default = 1
}
variable "vm_web_yandex_compute_instance_resources_core_fraction" {
type = number
default = 5
}
*/

variable "vm_db_yandex_compute_instance_name" {
type = string
default = "netology-develop-platform-db"
}
variable "vm_db_yandex_compute_instance_platform_id" {
type = string
default = "standard-v1"
}
/*variable "vm_db_yandex_compute_instance_resources_cores" {
type = number
default = 2
}
variable "vm_db_yandex_compute_instance_resources_memory" {
type = number
default = 2
}
variable "vm_db_yandex_compute_instance_resources_core_fraction" {
type = number
default = 20
}
*/

variable "metadata" {
type = map(object({
serial-port-enable = number
ssh-keys = string
}))
default = {
"vm" = {
serial-port-enable = 1
ssh-keys = "ubuntu:ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJbFQwlXpyF5D6x8yiptgTG/Are3CfQ94MRINvltKRs2 [email protected]"
}
}
description = "metadata"
}

/*
###ssh vars
variable "vms_ssh_root_key" {
type = string
default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJbFQwlXpyF5D6x8yiptgTG/Are3CfQ94MRINvltKRs2 [email protected]"
description = "ssh-keygen -t ed25519"
}
*/
9 changes: 8 additions & 1 deletion 05/hw-05.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@
- из [демо к лекции 4](https://github.com/netology-code/ter-homeworks/tree/main/04/demonstration1).
2. Проверьте код с помощью tflint и checkov. Вам не нужно инициализировать этот проект.
3. Перечислите, какие **типы** ошибок обнаружены в проекте (без дублей).

```
TFLINT
Warning: Missing version constraint for provider "yandex" in `required_providers`
Warning: [Fixable] variable "..." is declared but not used
Checkov
Check: CKV_TF_1: "Ensure Terraform module sources use a commit hash"
Check: CKV_TF_2: "Ensure Terraform module sources use a tag with a version number"
```
------

### Задание 2
Expand Down