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

Д3№6 YC&Terraform_1 #6

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b92d500
Д3№4 Основные сервисы YaCl
DEN93168 Jun 8, 2023
51dc94c
Д3№4 Основные сервисы YaCl
DEN93168 Jun 8, 2023
4f0c064
Д3№4 Основные сервисы YaCl
DEN93168 Jun 8, 2023
2b48a0e
Д3№4 Основные сервисы YaCl
DEN93168 Jun 8, 2023
38a93ea
Д3№5 Подготовка образа VM&Packer.
DEN93168 Jun 9, 2023
0279816
Д3№5 Подготовка образа VM&Packer.
DEN93168 Jun 9, 2023
acbea31
Д3№5 Подготовка образа VM&Packer.
DEN93168 Jun 9, 2023
d511974
Д3№5 Подготовка образа VM&Packer.
DEN93168 Jun 9, 2023
c2f3d98
Д3№5 Подготовка образа VM&Packer.
DEN93168 Jun 9, 2023
c020b34
Д3№5 Подготовка образа VM&Packer.
DEN93168 Jun 9, 2023
2e3e7e5
Д3№5 Подготовка образа VM&Packer.
DEN93168 Jun 9, 2023
57f95ab
Д3№5 Подготовка образа VM&Packer.
DEN93168 Jun 9, 2023
3b5e3ba
Д3№5 Подготовка образа VM&Packer.
DEN93168 Jun 9, 2023
9a5e09e
Д3№6 YC&Terraform_1
DEN93168 Jun 10, 2023
6614c64
Д3№6 YC&Terraform_1
DEN93168 Jun 10, 2023
1319a38
Д3№6 YC&Terraform_1
DEN93168 Jun 10, 2023
00b5665
Д3№6 YC&Terraform_1
DEN93168 Jun 10, 2023
d41ed80
Д3№6 YC&Terraform_1
DEN93168 Jun 10, 2023
b5966bf
Д3№6 YC&Terraform_1
DEN93168 Jun 10, 2023
5a6b2b5
Д3№6 YC&Terraform_1
DEN93168 Jun 10, 2023
9591500
Д3№6 YC&Terraform_1
DEN93168 Jun 10, 2023
3b4fd86
Д3№6 YC&Terraform_1
DEN93168 Jun 10, 2023
7b4a5d8
Д3№6 YC&Terraform_1
DEN93168 Jun 10, 2023
a05bb49
Д3№6 YC&Terraform_1
DEN93168 Jun 10, 2023
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.tfstate
*.tfstate.*.backup
*.tfstate.backup
*.tfvars
.terraform/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
bastion_IP = 51.250.11.249
someinternalhost_IP = 10.128.0.14
testapp_IP = 62.84.118.237
testapp_port = 9292
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions configscripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
git clone -b monolith https://github.com/express42/reddit.git
cd reddit && bundle install
puma -d
5 changes: 5 additions & 0 deletions configscripts/install_mongodb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
apt-get update
apt-get install -y mongodb-org
3 changes: 3 additions & 0 deletions configscripts/install_ruby.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
apt update
apt install -y ruby-full ruby-bundler build-essential
4 changes: 4 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
git clone -b monolith https://github.com/express42/reddit.git
cd reddit && bundle install
puma -d
5 changes: 5 additions & 0 deletions install_mongodb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
apt-get update
apt-get install -y mongodb-org
3 changes: 3 additions & 0 deletions install_ruby.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
apt update
apt install -y ruby-full ruby-bundler build-essential
8 changes: 8 additions & 0 deletions packer/key.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "ajeutlkkq1j5e7cvvfj2",
"service_account_id": "aje0epias37pu9ft7vlf",
"created_at": "2023-06-09T10:50:14.856252065Z",
"key_algorithm": "RSA_2048",
"public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr02dGkqhgL+zztwIdP8L\nIH6RNMxaSKKuMittwODLnOK1+xBKl+lGJ4ixbPWgbfP29YOMeucLlSUxaHBXVMk8\nBVXJ9ncsvD2FIAL9vjsOX+YLFxy3z65CRWa9sKRkNJxuxxZYAIHdE4xLEPbK37Ld\ngYVLkD/9IygO2FllIbiMqcoGRj6Mun1zpODV2cF4mTefDlYbM1uyE3/nEo88+uZK\neAcYsshP7IVDp84SBpj6ga7F45qS8WKK+Qc9q9yAXDjfitkKg6RtmI1DC93ciORc\nxsvrKMjDF+iVi6Y3+AKtIeyQT9u3fR9GbKYSCtz6pUauC5xIUq+MWCzq8ZCMHNhY\n2QIDAQAB\n-----END PUBLIC KEY-----\n",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCvTZ0aSqGAv7PO\n3Ah0/wsgfpE0zFpIoq4yK23A4Muc4rX7EEqX6UYniLFs9aBt8/b1g4x65wuVJTFo\nc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5FKOsB1GDC9Py+V1ORsbtFDkvrIwnKV3ZtcVl\n/BJopPSH5tS8Yh5h7mm/x0hOOvHqkohsKkexqZ4VEOQ5sPfoGQrtO4FnPwKBgQCq\nHxdB+BulBMGv8pQHiL8hTSkUB8U6HpM3w2tqNQt9MXrTqH//rv5v6rrIlRYzeL2/\ngqc7fJg3Mux+7Vy1hoCzZ5sBzSXxvcKgG6TjCm1LaZjcFDrZHOAzt9/rysIZLAVD\n/Qg+j1Hov3iHmuw8dKXKZwqiBMU/UYxQDXnaHU3IgwKBgD7j1R0ObzJA/HVzIPRJ\nYgFgMRsuMuKgorjHzYSHgaU2UVoAQEWSj8mkviWQzHYTEAEkkQRNTC8eB4bZBc9k\nt1pCNgk2H+xuzOxva+/eww5kRqd5CQuPDeLLgrQSi1siPA1cnzUJpSiviYlZ3gq9\nXx454O4qontikJBy3op/xmR1\n-----END PRIVATE KEY-----\n"
}
7 changes: 7 additions & 0 deletions packer/scripts/install_mongodb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
wget -qO - https://www.mongodb.org/static/pgp/server-3.2.asc | sudo apt-key add -
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
apt-get update
apt install -y mongodb-org
systemctl start mongod
systemctl enable mongod
3 changes: 3 additions & 0 deletions packer/scripts/install_ruby.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
apt update
apt install -y ruby-full ruby-bundler build-essential
33 changes: 33 additions & 0 deletions packer/ubuntu16.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"variables": {
"service_account_key_file": "",
"folder_id": "",
"source_image_family": "",
"ssh_username": ""
},
"builders": [
{
"type": "yandex",
"service_account_key_file": "{{user `service_account_key_file`}}",
"folder_id": "{{user `folder_id`}}",
"source_image_family": "{{user `source_image_family`}}",
"image_name": "reddit-base-{{timestamp}}",
"image_family": "reddit-base",
"ssh_username": "{{user `ssh_username`}}",
"use_ipv4_nat": "true",
"platform_id": "standard-v1"
}
],
"provisioners": [
{
"type": "shell",
"script": "scripts/install_ruby.sh",
"execute_command": "sudo {{.Path}}"
},
{
"type": "shell",
"script": "scripts/install_mongodb.sh",
"execute_command": "sudo {{.Path}}"
}
]
}
6 changes: 6 additions & 0 deletions packer/variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"folder_id": "b1gnilmohmvq9fboq85r",
"source_image_family": "ubuntu-1604-lts",
"service_account_key_file": "key.json",
"ssh_username": "ubuntu"
}
6 changes: 6 additions & 0 deletions packer/variables.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"folder_id": "b1gnilmohmvq9fboq85r",
"source_image_family": "ubuntu-1604-lts",
"service_account_key_file": "key.json",
"ssh_username": "ubuntu"
}
23 changes: 23 additions & 0 deletions terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions terraform/files/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e
APP_DIR=${1:-$HOME}
sudo apt-get install -y git
git clone -b monolith https://github.com/express42/reddit.git $APP_DIR/reddit
cd $APP_DIR/reddit
bundle install
sudo mv /tmp/puma.service /etc/systemd/system/puma.service
sudo systemctl start puma
sudo systemctl enable puma
13 changes: 13 additions & 0 deletions terraform/files/puma.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Puma HTTP Server
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/reddit
ExecStart=/bin/bash -lc 'puma'
Restart=always

[Install]
WantedBy=multi-user.target
8 changes: 8 additions & 0 deletions terraform/key.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "ajeutlkkq1j5e7cvvfj2",
"service_account_id": "aje0epias37pu9ft7vlf",
"created_at": "2023-06-09T10:50:14.856252065Z",
"key_algorithm": "RSA_2048",
"public_key": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr02dGkqhgL+zztwIdP8L\nIH6RNMxaSKKuMittwODLnOK1+xBKl+lGJ4ixbPWgbfP29YOMeucLlSUxaHBXVMk8\nBVXJ9ncsvD2FIAL9vjsOX+YLFxy3z65CRWa9sKRkNJxuxxZYAIHdE4xLEPbK37Ld\ngYVLkD/9IygO2FllIbiMqcoGRj6Mun1zpODV2cF4mTefDlYbM1uyE3/nEo88+uZK\neAcYsshP7IVDp84SBpj6ga7F45qS8WKK+Qc9q9yAXDjfitkKg6RtmI1DC93ciORc\nxsvrKMjDF+iVi6Y3+AKtIeyQT9u3fR9GbKYSCtz6pUauC5xIUq+MWCzq8ZCMHNhY\n2QIDAQAB\n-----END PUBLIC KEY-----\n",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCvTZ0aSqGAv7PO\n3Ah0/wsgfpE0zFpIoq4yK23A4Muc4rX7EEqX6UYniLFs9aBt8/b1g4x65wuVJTFo\ncFdUyTwFVcn2dyy8PYUgAv2+Ow5f5gsXHLfPrkJFZr2wpGQ0nG7HFlgAgd0TjEsQ\n9srfst2BhUuQP/0jKA7YWWUhuIypygZGPoy6fXOk4NXZwXiZN58OVhszW7ITf+cS\njzz65kp4BxiyyE/shUOnzhIGmPqBrsXjmpLxYor5Bz2r3IBcON+K2QqDpG2YjUML\n3dyI5FzGy+soyMMX6JWLpjf4Aq0h7JBP27d9H0ZsphIK3PqlRq4LnEhSr4xYLOrx\nkIwc2FjZAgMBAAECggEANx8BeiXjWHdu02mOYzNazVHe2Ko07Ufx3CaZsR8+Bsum\nixYZTmD0RTQPDgLB+jDPA23kuzRxCOmT+pHwc+F+tPK/uXbJozr45BLstGcfYvoT\nnKXUCkJx5h6jIKrgM0bI8mLNMwOifyYK6H+hV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cnzUJpSiviYlZ3gq9\nXx454O4qontikJBy3op/xmR1\n-----END PRIVATE KEY-----\n"
}
63 changes: 63 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#terraform {
# required_providers {
# yandex = {
# source = "yandex-cloud/yandex"
# version = "0.89.0"
# }
# }
#}

provider "yandex" {
# token = "y0_AgAAAAAWejyQAATuwQAAAADk_g5kVSxJNM-1Ttqui1ssPSNIkVtIdRg"
service_account_key_file = var.service_account_key_file
cloud_id = var.cloud_id
folder_id = var.folder_id
zone = var.zone
}

resource "yandex_compute_instance" "app" {
name = "reddit-app"

resources {
cores = 2
memory = 4
core_fraction = 20
}

metadata = {
ssh-keys = "ubuntu:${file(var.public_key_path)}"
}

boot_disk {
initialize_params {
# Указать id образа созданного в предыдущем домашем задании
image_id = var.image_id
}
}

network_interface {
# Указан id подсети default-ru-central1-a
subnet_id = var.subnet_id
nat = true
}

connection {
type = "ssh"
host = yandex_compute_instance.app.network_interface.0.nat_ip_address
user = "ubuntu"
agent = false
# путь до приватного ключа
private_key = file(var.private_key_path)
}

provisioner "file" {
source = "files/puma.service"
destination = "/tmp/puma.service"
}

provisioner "remote-exec" {
script = "files/deploy.sh"
}


}
3 changes: 3 additions & 0 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "external_ip_address_app" {
value = yandex_compute_instance.app.network_interface.0.nat_ip_address
}
8 changes: 8 additions & 0 deletions terraform/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cloud_id = "b1g"
folder_id = "b1g"
zone = "ru-central1-a"
image_id = "fd8"
public_key_path = "~/.ssh/ubuntu.pub"
subnet_id = "e9bg"
service_account_key_file = "key.json"
private_key_path = "~/.ssh/ubuntu"
28 changes: 28 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
variable cloud_id{
description = "Cloud"
}
variable folder_id {
description = "Folder"
}
variable zone {
description = "Zone"
# Значение по умолчанию
default = "ru-central1-a"
}
variable public_key_path {
# Описание переменной
description = "Path to the public key used for ssh access"
}
variable image_id {
description = "Disk image"
}
variable subnet_id{
description = "Subnet"
}
variable service_account_key_file{
description = "key.json"
}
variable private_key_path {
# Описание переменной
description = "Path to the public key used for ssh access"
}