mirror of
https://github.com/Dannecron/netology-devops.git
synced 2025-12-26 07:42:36 +03:00
homework 15.2: partially complete part 2 from task 1
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
---
|
||||
write_files:
|
||||
- content: |
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Cute cat image test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>You can see cute cat below</h1>
|
||||
<div>
|
||||
<img
|
||||
src="https://os-netology-bucket.storage.yandexcloud.net/cute-cat"
|
||||
alt="cute-cat"
|
||||
style="max-height: 600px"
|
||||
/>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
path: "/var/www/html/index.html"
|
||||
owner: ubuntu:www-data
|
||||
permissions: '0774'
|
||||
73
src/homework/15-cloud-providers/15.2/terraform/lamp.tf
Normal file
73
src/homework/15-cloud-providers/15.2/terraform/lamp.tf
Normal file
@@ -0,0 +1,73 @@
|
||||
// Назначение ролей сервисному аккаунту
|
||||
resource "yandex_resourcemanager_folder_iam_member" "os-vpc-user" {
|
||||
folder_id = var.yandex_folder_id
|
||||
role = "vpc.user"
|
||||
member = "serviceAccount:${yandex_iam_service_account.os-service-account.id}"
|
||||
}
|
||||
|
||||
resource "yandex_resourcemanager_folder_iam_member" "os-global-editor" {
|
||||
folder_id = var.yandex_folder_id
|
||||
role = "editor"
|
||||
member = "serviceAccount:${yandex_iam_service_account.os-service-account.id}"
|
||||
}
|
||||
|
||||
resource "yandex_compute_instance_group" "os-lamp-group" {
|
||||
name = "os-lamp-group"
|
||||
service_account_id = yandex_iam_service_account.os-service-account.id
|
||||
deletion_protection = false
|
||||
|
||||
allocation_policy {
|
||||
zones = ["ru-central1-a"]
|
||||
}
|
||||
|
||||
deploy_policy {
|
||||
max_expansion = 0
|
||||
max_unavailable = 1
|
||||
}
|
||||
|
||||
scale_policy {
|
||||
fixed_scale {
|
||||
size = 3
|
||||
}
|
||||
}
|
||||
|
||||
instance_template {
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image_id = "fd827b91d99psvq5fjit" # lamp-1579613975
|
||||
size = "10"
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
subnet_ids = [yandex_vpc_subnet.os-subnet.id]
|
||||
}
|
||||
|
||||
resources {
|
||||
cores = 2
|
||||
memory = 2
|
||||
}
|
||||
|
||||
metadata = {
|
||||
ssh-keys = "ubuntu:${file("~/.ssh/id_rsa.pub")}"
|
||||
user-data = file("./cloud-config.yaml")
|
||||
}
|
||||
}
|
||||
|
||||
health_check {
|
||||
interval = 5
|
||||
timeout = 3
|
||||
healthy_threshold = 2
|
||||
unhealthy_threshold = 2
|
||||
http_options {
|
||||
path = "/index.html"
|
||||
port = 80
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output "ips" {
|
||||
value = {
|
||||
internalLamp = yandex_compute_instance_group.os-lamp-group.instances.*.network_interface.0.ip_address
|
||||
}
|
||||
}
|
||||
@@ -14,57 +14,17 @@ provider "yandex" {
|
||||
zone = "ru-central1-a"
|
||||
}
|
||||
|
||||
resource "yandex_vpc_network" "os-network" {
|
||||
name = "os-network"
|
||||
}
|
||||
|
||||
resource "yandex_vpc_subnet" "os-subnet" {
|
||||
name = "os-subnet"
|
||||
zone = "ru-central1-a"
|
||||
network_id = yandex_vpc_network.os-network.id
|
||||
v4_cidr_blocks = ["192.168.10.0/24"]
|
||||
}
|
||||
|
||||
resource "yandex_iam_service_account" "os-service-account" {
|
||||
name = "s3-service-account"
|
||||
name = "os-service-account"
|
||||
}
|
||||
|
||||
// Назначение роли сервисному аккаунту
|
||||
resource "yandex_resourcemanager_folder_iam_member" "os-editor" {
|
||||
folder_id = var.yandex_folder_id
|
||||
role = "storage.editor"
|
||||
member = "serviceAccount:${yandex_iam_service_account.os-service-account.id}"
|
||||
}
|
||||
|
||||
// Создание статического ключа доступа
|
||||
resource "yandex_iam_service_account_static_access_key" "os-static-key" {
|
||||
service_account_id = yandex_iam_service_account.os-service-account.id
|
||||
description = "static access key for object storage"
|
||||
}
|
||||
|
||||
// Создание бакета с использованием ключа
|
||||
resource "yandex_storage_bucket" "os-netology-bucket" {
|
||||
access_key = yandex_iam_service_account_static_access_key.os-static-key.access_key
|
||||
secret_key = yandex_iam_service_account_static_access_key.os-static-key.secret_key
|
||||
bucket = "os-netology-bucket"
|
||||
|
||||
anonymous_access_flags {
|
||||
read = true
|
||||
list = false
|
||||
}
|
||||
}
|
||||
|
||||
resource "yandex_storage_object" "cute-cat-picture" {
|
||||
bucket = yandex_storage_bucket.os-netology-bucket.bucket
|
||||
access_key = yandex_iam_service_account_static_access_key.os-static-key.access_key
|
||||
secret_key = yandex_iam_service_account_static_access_key.os-static-key.secret_key
|
||||
key = "cute-cat"
|
||||
source = "./static/cute_cat.jpg"
|
||||
content_type = "image/jpg"
|
||||
acl = "public-read"
|
||||
}
|
||||
|
||||
output "os" {
|
||||
value = {
|
||||
"staticUrl": "https://${yandex_storage_bucket.os-netology-bucket.bucket}.storage.yandexcloud.net/${yandex_storage_object.cute-cat-picture.key}"
|
||||
}
|
||||
}
|
||||
|
||||
#resource "yandex_vpc_network" "network-vpc" {
|
||||
# name = "network-vpc"
|
||||
#}
|
||||
|
||||
#output "ips" {
|
||||
# value = {
|
||||
#
|
||||
# }
|
||||
#}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// Назначение роли сервисному аккаунту
|
||||
resource "yandex_resourcemanager_folder_iam_member" "os-editor" {
|
||||
folder_id = var.yandex_folder_id
|
||||
role = "storage.editor"
|
||||
member = "serviceAccount:${yandex_iam_service_account.os-service-account.id}"
|
||||
}
|
||||
|
||||
// Создание статического ключа доступа
|
||||
resource "yandex_iam_service_account_static_access_key" "os-static-key" {
|
||||
service_account_id = yandex_iam_service_account.os-service-account.id
|
||||
description = "static access key for object storage"
|
||||
}
|
||||
|
||||
// Создание бакета с использованием ключа
|
||||
resource "yandex_storage_bucket" "os-netology-bucket" {
|
||||
access_key = yandex_iam_service_account_static_access_key.os-static-key.access_key
|
||||
secret_key = yandex_iam_service_account_static_access_key.os-static-key.secret_key
|
||||
bucket = "os-netology-bucket"
|
||||
|
||||
anonymous_access_flags {
|
||||
read = true
|
||||
list = false
|
||||
}
|
||||
}
|
||||
|
||||
resource "yandex_storage_object" "cute-cat-picture" {
|
||||
bucket = yandex_storage_bucket.os-netology-bucket.bucket
|
||||
access_key = yandex_iam_service_account_static_access_key.os-static-key.access_key
|
||||
secret_key = yandex_iam_service_account_static_access_key.os-static-key.secret_key
|
||||
key = "cute-cat"
|
||||
source = "./static/cute_cat.jpg"
|
||||
content_type = "image/jpg"
|
||||
acl = "public-read"
|
||||
}
|
||||
|
||||
output "os" {
|
||||
value = {
|
||||
"staticUrl": "https://${yandex_storage_bucket.os-netology-bucket.bucket}.storage.yandexcloud.net/${yandex_storage_object.cute-cat-picture.key}"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user