From 7d867b6bc7a99d85390baa0ad29eac17882e50cb Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Thu, 1 Feb 2024 23:02:00 +0300 Subject: [PATCH 01/13] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D0=BA=D1=80=D1=83=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20v=5Fansible=20=D0=B2=20.gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 ansible/.gitignore diff --git a/ansible/.gitignore b/ansible/.gitignore new file mode 100644 index 0000000..8d4e0cf --- /dev/null +++ b/ansible/.gitignore @@ -0,0 +1 @@ +v_ansible/ From 63049968d26ebaac8787f70a16a93e2493ca851a Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 4 Feb 2024 13:26:12 +0300 Subject: [PATCH 02/13] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=20v1=5Fansible=20?= =?UTF-8?q?=D0=B2=20=D0=B8=D0=B3=D0=BD=D0=BE=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/ansible/.gitignore b/ansible/.gitignore index 8d4e0cf..a82d5a5 100644 --- a/ansible/.gitignore +++ b/ansible/.gitignore @@ -1 +1,2 @@ v_ansible/ +v1_ansible/ From 0f0d6eb8e68fbf068364b72ec1034788703b7f46 Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 18 Feb 2024 11:59:25 +0300 Subject: [PATCH 03/13] =?UTF-8?q?HW=E2=84=968=20=D0=B2=D1=8B=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D0=B5=D0=BD=D0=BE=20=D0=94=D0=97=20ansible=20ansib?= =?UTF-8?q?le-1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 26 +++++++++++++++++++++++ ansible/.gitignore | 1 + ansible/ansible.cfg | 6 ++++++ ansible/clone.yml | 7 +++++++ ansible/inventory | 5 +++++ ansible/inventory.json | 12 +++++++++++ ansible/inventory.sh | 28 +++++++++++++++++++++++++ ansible/inventory.yml | 16 ++++++++++++++ ansible/requirements.txt | 3 ++- terraform/main.tf | 39 ----------------------------------- terraform/modules/app/main.tf | 5 +++-- terraform/modules/db/main.tf | 5 +++-- terraform/outputs.tf | 2 ++ terraform/stage/backend.tf | 9 ++++---- terraform/stage/main.tf | 5 +++-- terraform/stage/variables.tf | 4 ++++ terraform/storage-bucket.tf | 39 +++++++++++++++++++---------------- terraform/variables.tf | 10 +++++++++ 18 files changed, 153 insertions(+), 69 deletions(-) create mode 100644 ansible/ansible.cfg create mode 100644 ansible/clone.yml create mode 100644 ansible/inventory create mode 100644 ansible/inventory.json create mode 100755 ansible/inventory.sh create mode 100644 ansible/inventory.yml delete mode 100644 terraform/main.tf diff --git a/README.md b/README.md index 4727efb..f6c1061 100644 --- a/README.md +++ b/README.md @@ -46,3 +46,29 @@ external_ip_address_db = "51.250.89.190" создал инфраструктуру для окружений stage и prod проверил оба окружения добавил описание backend для stage и prod + +HW_8. Ansible-1 +создал окружение и установил ansible с помощью pip +поднял инфраструктуру контура stage +external_ip_address_app = "158.160.55.243" +external_ip_address_db = "62.84.127.171" +создал inventory, проверил ддоступность хостов для ansible +проверил рабооту инвентори в разных вариациях, создал inventory.yml +проверил inventory.yml, проверил модули command, shell, service, git +Создан и протестирован плейбук clone.yml +успешный пинг ansible all -m ping -i inventory +проверка динамического инвентори: ansible all -m ping -i inventory.sh +158.160.55.243 | SUCCESS => { + "ansible_facts": { + "discovered_interpreter_python": "/usr/bin/python3" + }, + "changed": false, + "ping": "pong" +} +62.84.127.171 | SUCCESS => { + "ansible_facts": { + "discovered_interpreter_python": "/usr/bin/python3" + }, + "changed": false, + "ping": "pong" +} diff --git a/ansible/.gitignore b/ansible/.gitignore index a82d5a5..1f38ab4 100644 --- a/ansible/.gitignore +++ b/ansible/.gitignore @@ -1,2 +1,3 @@ v_ansible/ v1_ansible/ +*.old diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..c408d6a --- /dev/null +++ b/ansible/ansible.cfg @@ -0,0 +1,6 @@ +[defaults] +inventory = ./inventory.json +remote_user = ubuntu +private_key_file = ~/.ssh/ubuntu +host_key_checking = False +retry_files_enabled = False diff --git a/ansible/clone.yml b/ansible/clone.yml new file mode 100644 index 0000000..bdf1469 --- /dev/null +++ b/ansible/clone.yml @@ -0,0 +1,7 @@ +- name: Clone + hosts: app + tasks: + - name: Clone repo + git: + repo: https://github.com/express42/reddit.git + dest: /home/ubuntu/reddit diff --git a/ansible/inventory b/ansible/inventory new file mode 100644 index 0000000..07db95a --- /dev/null +++ b/ansible/inventory @@ -0,0 +1,5 @@ +[app] +appserver ansible_host=158.160.55.243 + +[db] +dbserver ansible_host=62.84.127.171 diff --git a/ansible/inventory.json b/ansible/inventory.json new file mode 100644 index 0000000..1fa795f --- /dev/null +++ b/ansible/inventory.json @@ -0,0 +1,12 @@ +{ + "app": { + "hosts": { + "158.160.55.243": null + } + }, + "db": { + "hosts": { + "62.84.127.171": null + } + } +} diff --git a/ansible/inventory.sh b/ansible/inventory.sh new file mode 100755 index 0000000..89ca0d8 --- /dev/null +++ b/ansible/inventory.sh @@ -0,0 +1,28 @@ +#!/bin/bash +#yc compute instances list | tail -n +4 | head -n -2 | awk -F '|' '{print "["$3"]\n" $3 "-server" "%ansible_host="$6}' | tr -d '[:blank:]' | sed 's/%/ /g' | sed 's/reddit-//g' > inventory +#ansible-inventory -i inventory --list > inventory.json + + if [[ $1 == "--list" ]]; then + +app=158.160.55.243 +db=62.84.127.171 + + cat <=2.4 +ansible==2.10.7 +#python=3.5.2 diff --git a/terraform/main.tf b/terraform/main.tf deleted file mode 100644 index c6e7af4..0000000 --- a/terraform/main.tf +++ /dev/null @@ -1,39 +0,0 @@ -/* -terraform { - required_version = ">= 1.0.0" - required_providers { - yandex = { - source = "yandex-cloud/yandex" - version = ">= 0.103.0" - } - } -} -*/ - -provider "yandex" { - service_account_key_file = var.service_account_key_file - cloud_id = var.cloud_id - folder_id = var.folder_id - zone = var.zone -} - -module "app" { -source = "./modules/app" -public_key_path = var.public_key_path -subnet_id = var.subnet_id -folder_id = var.folder_id -app_disk_image = var.app_disk_image -zone = var.zone -cloud_id = var.cloud_id -service_account_key_file = var.service_account_key_file -} -module "db" { -source = "./modules/db" -public_key_path = var.public_key_path -subnet_id = var.subnet_id -folder_id = var.folder_id -db_disk_image = var.db_disk_image -zone = var.zone -cloud_id = var.cloud_id -service_account_key_file = var.service_account_key_file -} diff --git a/terraform/modules/app/main.tf b/terraform/modules/app/main.tf index ce0a8e9..ecde1ff 100644 --- a/terraform/modules/app/main.tf +++ b/terraform/modules/app/main.tf @@ -10,8 +10,9 @@ resource "yandex_compute_instance" "app" { tags = "reddit-app" } resources { - cores = 2 - memory = 2 + core_fraction = 20 + cores = 2 + memory = 2 } boot_disk { initialize_params { diff --git a/terraform/modules/db/main.tf b/terraform/modules/db/main.tf index b217155..bc76a79 100644 --- a/terraform/modules/db/main.tf +++ b/terraform/modules/db/main.tf @@ -12,8 +12,9 @@ resource "yandex_compute_instance" "db" { } resources { - cores = 2 - memory = 2 + core_fraction = 20 + cores = 2 + memory = 2 } boot_disk { diff --git a/terraform/outputs.tf b/terraform/outputs.tf index 2f94927..b80a2f7 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -1,6 +1,8 @@ +/* output "external_ip_address_app" { value = module.app.external_ip_address_app } output "external_ip_address_db" { value = module.db.external_ip_address_db } +*/ diff --git a/terraform/stage/backend.tf b/terraform/stage/backend.tf index dee5bbe..6b84709 100644 --- a/terraform/stage/backend.tf +++ b/terraform/stage/backend.tf @@ -5,15 +5,14 @@ backend "s3" { endpoints = { s3 = "https://storage.yandexcloud.net" } - bucket = "terraform.test" - region = "ru-central1-a" - key = "states/stage/terraform.tfstate" -access_key = "YCAJEireu83n8xxxxxxxxxxxx]" -secret_key = "YCONJPmCQ9JJ08-BgswJT6Wgxxxxxxxxxxxx" + bucket = "test-states" + region = "ru-central1" + key = "stage/stage.tfstate" skip_region_validation = true skip_credentials_validation = true skip_requesting_account_id = true + skip_s3_checksum = true } } diff --git a/terraform/stage/main.tf b/terraform/stage/main.tf index 92b3a3e..842d8ab 100644 --- a/terraform/stage/main.tf +++ b/terraform/stage/main.tf @@ -1,4 +1,4 @@ -/* + terraform { required_version = ">= 1.0.0" required_providers { @@ -8,10 +8,11 @@ terraform { } } } -*/ + provider "yandex" { service_account_key_file = var.service_account_key_file + token = var.yc_token access_key = var.access_key secret_key = var.secret_key cloud_id = var.cloud_id diff --git a/terraform/stage/variables.tf b/terraform/stage/variables.tf index b707f9d..cb89185 100644 --- a/terraform/stage/variables.tf +++ b/terraform/stage/variables.tf @@ -42,3 +42,7 @@ variable "access_key" { variable secret_key { description = "secret for s3 bucket" } +variable yc_token { + type = string + description = "yc_token" +} diff --git a/terraform/storage-bucket.tf b/terraform/storage-bucket.tf index 58bb877..6e50fb5 100644 --- a/terraform/storage-bucket.tf +++ b/terraform/storage-bucket.tf @@ -1,31 +1,34 @@ terraform { -# required_providers { -# yandex = { -# source = "yandex-cloud/yandex" -# } -# } -# required_version = ">= 0.13" + required_version = ">= 1.0.0" + required_providers { + yandex = { + source = "yandex-cloud/yandex" + version = ">= 0.103.0" + } + } backend "s3" { endpoints = { s3 = "https://storage.yandexcloud.net" } - bucket = "terraform.test" - region = "ru-central1-a" - key = "states/terraform.tfstate" -access_key = "YCAJEireu83n8xxxxxxxxxxxx]" -secret_key = "YCONJPmCQ9JJ08-BgswJT6Wgxxxxxxxxxxxx" + bucket = "test-states" + region = "ru-central1" + key = "main/main.tfstate" + skip_region_validation = true skip_credentials_validation = true skip_requesting_account_id = true + skip_s3_checksum = true } } - -#provider "yandex" { -# service_account_key_file = var.service_account_key_file - #cloud_id = var.cloud_id - #folder_id = var.folder_id - #zone = var.zone -#} +provider "yandex" { + # access_key = var.access_key + # secret_key = var.secret_key + token = var.yc_token + service_account_key_file = var.service_account_key_file + cloud_id = var.cloud_id + folder_id = var.folder_id + zone = var.zone +} diff --git a/terraform/variables.tf b/terraform/variables.tf index 2129625..d07c743 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -33,3 +33,13 @@ variable db_disk_image { description = "Disk image for reddit db" default = "reddit-db-base" } +variable "access_key" { + description = "key for s3 bucket" +} +variable secret_key { + description = "secret for s3 bucket" +} +variable yc_token { + type = string + description = "yc_token" +} From 270c7359fe6dc483708fc4729fd779b5131b773c Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 18 Feb 2024 12:17:33 +0300 Subject: [PATCH 04/13] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=20=D1=82=D0=B5?= =?UTF-8?q?=D1=80=D1=80=D0=B0=D1=84=D0=BE=D1=80=D0=BC=20=D0=BF=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=B0=D0=B2=D1=82=D0=BE=D1=82=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- terraform/storage-bucket.tf | 17 +++++++++-------- terraform/terraform.tfvars.example | 3 +++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/terraform/storage-bucket.tf b/terraform/storage-bucket.tf index 6e50fb5..b0523cf 100644 --- a/terraform/storage-bucket.tf +++ b/terraform/storage-bucket.tf @@ -1,11 +1,12 @@ -terraform { - required_version = ">= 1.0.0" - required_providers { - yandex = { - source = "yandex-cloud/yandex" - version = ">= 0.103.0" - } - } +#terraform { +# required_version = ">= 1.0.0" +# required_providers { +# yandex = { +# source = "yandex-cloud/yandex" +# version = ">= 0.103.0" +# } +# } + backend "s3" { endpoints = { s3 = "https://storage.yandexcloud.net" diff --git a/terraform/terraform.tfvars.example b/terraform/terraform.tfvars.example index bf082c2..3df14ed 100644 --- a/terraform/terraform.tfvars.example +++ b/terraform/terraform.tfvars.example @@ -1,3 +1,4 @@ +yc_token = "y0_AgAAAABnLd1xAATuwxxxxxxxxxxxxxxxxxxxxxxxxxxx" cloud_id = "b1gulp4hfrunfqk3lttb" folder_id = "b1gsnn20hr06bqfra90t" zone = "ru-central1-a" @@ -8,3 +9,5 @@ image_id = "fd8an808ivtptq6jemm6" subnet_id = "e9b4tphlh2sjr6g0j2cq" app_disk_image = "fd8atnk3t60s5fmiaqil" db_disk_image = "fd8u6gsncuov2n36bcrt" +access_key = "YCAJEHdVd2Qxxxxxxxxxxxxx" +secret_key = "YCNOs05Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" From e4215805df7d397607fd2f6c8c4068d3aa57f9d5 Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 18 Feb 2024 13:46:04 +0300 Subject: [PATCH 05/13] =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D1=81=D1=8F,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20../terrafom/=20=D0=B2=20=D0=B8=D0=B3=D0=BD=D0=BE=D1=80?= =?UTF-8?q?,=20=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D0=B8=D0=B7=20=D0=B8?= =?UTF-8?q?=D0=BD=D0=B4=D0=B5=D0=BA=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/ansible/.gitignore b/ansible/.gitignore index 1f38ab4..d974a92 100644 --- a/ansible/.gitignore +++ b/ansible/.gitignore @@ -1,3 +1,4 @@ v_ansible/ v1_ansible/ *.old +../terraform/ From 482be930831746da190b78d58fb0998a756ca5f3 Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 18 Feb 2024 13:50:08 +0300 Subject: [PATCH 06/13] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20.g?= =?UTF-8?q?itignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ansible/.gitignore b/ansible/.gitignore index d974a92..6403eea 100644 --- a/ansible/.gitignore +++ b/ansible/.gitignore @@ -2,3 +2,5 @@ v_ansible/ v1_ansible/ *.old ../terraform/ +./terraform/ +terraform/ From 0f16a6b028208b3d21fc3f155eafb122215aa9c6 Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 18 Feb 2024 13:55:46 +0300 Subject: [PATCH 07/13] edit .gitignore *.tf* --- ansible/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/ansible/.gitignore b/ansible/.gitignore index 6403eea..f247b3e 100644 --- a/ansible/.gitignore +++ b/ansible/.gitignore @@ -4,3 +4,4 @@ v1_ansible/ ../terraform/ ./terraform/ terraform/ +*.tf* From 1c0f9a60f829693dea69aa72a00aed9ef4b05194 Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 18 Feb 2024 19:14:21 +0300 Subject: [PATCH 08/13] .gitignore --- ansible/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/.gitignore b/ansible/.gitignore index f247b3e..c83a790 100644 --- a/ansible/.gitignore +++ b/ansible/.gitignore @@ -4,4 +4,4 @@ v1_ansible/ ../terraform/ ./terraform/ terraform/ -*.tf* +*.tf From 333b62d2b2546606d6ce90d1824edb0705539e62 Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 18 Feb 2024 20:21:17 +0300 Subject: [PATCH 09/13] HW#8 Ansible-1, rm terraform from index --- terraform/.gitignore | 9 ----- terraform/.terraform.lock.hcl | 10 ----- terraform/files/deploy.sh | 12 ------ terraform/files/puma.service | 13 ------- terraform/modules/app/main.tf | 29 -------------- terraform/modules/app/outputs.tf | 3 -- terraform/modules/app/variables.tf | 25 ------------ terraform/modules/db/main.tf | 34 ----------------- terraform/modules/db/outputs.tf | 5 --- terraform/modules/db/variables.tf | 25 ------------ terraform/modules/vpc/vpc.tf | 9 ----- terraform/outputs.tf | 8 ---- terraform/prod/.terraform.lock.hcl | 10 ----- terraform/prod/backend.tf | 19 ---------- terraform/prod/main.tf | 39 ------------------- terraform/prod/outputs.tf | 6 --- terraform/prod/terraform.tfvars.example | 11 ------ terraform/prod/variables.tf | 44 ---------------------- terraform/stage/.terraform.lock.hcl | 10 ----- terraform/stage/backend.tf | 18 --------- terraform/stage/main.tf | 42 --------------------- terraform/stage/outputs.tf | 6 --- terraform/stage/terraform.tfvars.example | 11 ------ terraform/stage/variables.tf | 48 ------------------------ terraform/storage-bucket.tf | 35 ----------------- terraform/terraform.tfvars.example | 13 ------- terraform/variables.tf | 45 ---------------------- 27 files changed, 539 deletions(-) delete mode 100644 terraform/.gitignore delete mode 100644 terraform/.terraform.lock.hcl delete mode 100644 terraform/files/deploy.sh delete mode 100644 terraform/files/puma.service delete mode 100644 terraform/modules/app/main.tf delete mode 100644 terraform/modules/app/outputs.tf delete mode 100644 terraform/modules/app/variables.tf delete mode 100644 terraform/modules/db/main.tf delete mode 100644 terraform/modules/db/outputs.tf delete mode 100644 terraform/modules/db/variables.tf delete mode 100644 terraform/modules/vpc/vpc.tf delete mode 100644 terraform/outputs.tf delete mode 100644 terraform/prod/.terraform.lock.hcl delete mode 100644 terraform/prod/backend.tf delete mode 100644 terraform/prod/main.tf delete mode 100644 terraform/prod/outputs.tf delete mode 100644 terraform/prod/terraform.tfvars.example delete mode 100644 terraform/prod/variables.tf delete mode 100644 terraform/stage/.terraform.lock.hcl delete mode 100644 terraform/stage/backend.tf delete mode 100644 terraform/stage/main.tf delete mode 100644 terraform/stage/outputs.tf delete mode 100644 terraform/stage/terraform.tfvars.example delete mode 100644 terraform/stage/variables.tf delete mode 100644 terraform/storage-bucket.tf delete mode 100644 terraform/terraform.tfvars.example delete mode 100644 terraform/variables.tf diff --git a/terraform/.gitignore b/terraform/.gitignore deleted file mode 100644 index 9bc02e4..0000000 --- a/terraform/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -*.tfstate -*.tfstate.*.backup -*.tfstate.backup -*.tfvars -.terraform/ -.terraform.old/ -*.old -*.OLD -provider.tf diff --git a/terraform/.terraform.lock.hcl b/terraform/.terraform.lock.hcl deleted file mode 100644 index 4fb754e..0000000 --- a/terraform/.terraform.lock.hcl +++ /dev/null @@ -1,10 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/yandex-cloud/yandex" { - version = "0.105.0" - constraints = ">= 0.103.0" - hashes = [ - "h1:nXr/z9uAYs4H6VROlWJjcr7s68abwBqstlIzu6/6PaU=", - ] -} diff --git a/terraform/files/deploy.sh b/terraform/files/deploy.sh deleted file mode 100644 index 8d531d9..0000000 --- a/terraform/files/deploy.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -sleep 2m -set -e -APP_DIR=${1:-$HOME} -sudo apt-get install -y git -# задержка либо строка ниже: -# sudo DEBIAN_FRONTEND=noninteractive 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 diff --git a/terraform/files/puma.service b/terraform/files/puma.service deleted file mode 100644 index b3f6b58..0000000 --- a/terraform/files/puma.service +++ /dev/null @@ -1,13 +0,0 @@ - -[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] diff --git a/terraform/modules/app/main.tf b/terraform/modules/app/main.tf deleted file mode 100644 index ecde1ff..0000000 --- a/terraform/modules/app/main.tf +++ /dev/null @@ -1,29 +0,0 @@ -provider "yandex" { - 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" - labels = { - tags = "reddit-app" - } - resources { - core_fraction = 20 - cores = 2 - memory = 2 - } - boot_disk { - initialize_params { - image_id = var.app_disk_image - } - } - network_interface { - subnet_id = var.subnet_id - nat = true - } - metadata = { - ssh-keys = "ubuntu:${file(var.public_key_path)}" - } -} diff --git a/terraform/modules/app/outputs.tf b/terraform/modules/app/outputs.tf deleted file mode 100644 index 5e66420..0000000 --- a/terraform/modules/app/outputs.tf +++ /dev/null @@ -1,3 +0,0 @@ -output "external_ip_address_app" { -value = yandex_compute_instance.app.network_interface.0.nat_ip_address -} diff --git a/terraform/modules/app/variables.tf b/terraform/modules/app/variables.tf deleted file mode 100644 index 4f119e2..0000000 --- a/terraform/modules/app/variables.tf +++ /dev/null @@ -1,25 +0,0 @@ -variable "public_key_path" { - # Описание переменной - description = "Path to the public key used for ssh access" -} -variable "subnet_id" { - description = "Subnet" -} -variable app_disk_image { -description = "Disk image for reddit app" -default = "reddit-app-base" -} -variable "zone" { - description = "Zone" - # Значение по умолчанию - default = "ru-central1-a" -} -variable "cloud_id" { - description = "Cloud" -} -variable "service_account_key_file" { - description = "key.json" -} -variable "folder_id" { - description = "Folder" -} diff --git a/terraform/modules/db/main.tf b/terraform/modules/db/main.tf deleted file mode 100644 index bc76a79..0000000 --- a/terraform/modules/db/main.tf +++ /dev/null @@ -1,34 +0,0 @@ -provider "yandex" { - 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" "db" { - name = "reddit-db" - labels = { - tags = "reddit-db" - } - - resources { - core_fraction = 20 - cores = 2 - memory = 2 - } - - boot_disk { - initialize_params { - image_id = var.db_disk_image - } - } - - network_interface { - subnet_id = var.subnet_id - nat = true - } - - metadata = { - ssh-keys = "ubuntu:${file(var.public_key_path)}" - } -} diff --git a/terraform/modules/db/outputs.tf b/terraform/modules/db/outputs.tf deleted file mode 100644 index 2415f62..0000000 --- a/terraform/modules/db/outputs.tf +++ /dev/null @@ -1,5 +0,0 @@ -output "external_ip_address_db" { -value = yandex_compute_instance.db.network_interface.0.nat_ip_address -} -#value = yandex_compute_instance.db.*.network_interface.0.ip_address -#} diff --git a/terraform/modules/db/variables.tf b/terraform/modules/db/variables.tf deleted file mode 100644 index d1f3774..0000000 --- a/terraform/modules/db/variables.tf +++ /dev/null @@ -1,25 +0,0 @@ -variable "public_key_path" { - # Описание переменной - description = "Path to the public key used for ssh access" -} -variable "subnet_id" { - description = "Subnet" -} -variable db_disk_image { -description = "Disk image for reddit db" -default = "reddit-db-base" -} -variable "zone" { - description = "Zone" - # Значение по умолчанию - default = "ru-central1-a" -} -variable "cloud_id" { - description = "Cloud" -} -variable "service_account_key_file" { - description = "key.json" -} -variable "folder_id" { - description = "Folder" -} diff --git a/terraform/modules/vpc/vpc.tf b/terraform/modules/vpc/vpc.tf deleted file mode 100644 index 602fc8c..0000000 --- a/terraform/modules/vpc/vpc.tf +++ /dev/null @@ -1,9 +0,0 @@ -resource "yandex_vpc_network" "app-network" { -name = "app-network" -} -resource "yandex_vpc_subnet" "app-subnet" { -name = "app-subnet" -zone = "ru-central1-a" -network_id = "${yandex_vpc_network.app-network.id}" -v4_cidr_blocks = ["192.168.10.0/24"] -} diff --git a/terraform/outputs.tf b/terraform/outputs.tf deleted file mode 100644 index b80a2f7..0000000 --- a/terraform/outputs.tf +++ /dev/null @@ -1,8 +0,0 @@ -/* -output "external_ip_address_app" { - value = module.app.external_ip_address_app -} -output "external_ip_address_db" { - value = module.db.external_ip_address_db -} -*/ diff --git a/terraform/prod/.terraform.lock.hcl b/terraform/prod/.terraform.lock.hcl deleted file mode 100644 index 5754d2e..0000000 --- a/terraform/prod/.terraform.lock.hcl +++ /dev/null @@ -1,10 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/yandex-cloud/yandex" { - version = "0.106.0" - constraints = ">= 0.103.0" - hashes = [ - "h1:jHMQuc/PzkR31x8qgm5sM6D5yhN0X/NwkbNJCZZjWPE=", - ] -} diff --git a/terraform/prod/backend.tf b/terraform/prod/backend.tf deleted file mode 100644 index b34d84f..0000000 --- a/terraform/prod/backend.tf +++ /dev/null @@ -1,19 +0,0 @@ - -terraform { - -backend "s3" { - endpoints = { - s3 = "https://storage.yandexcloud.net" - } - bucket = "terraform.test" - region = "ru-central1-a" - key = "states/stage/terraform.tfstate" -access_key = "YCAJEireu83n8xxxxxxxxxxxx]" -secret_key = "YCONJPmCQ9JJ08-BgswJT6Wgxxxxxxxxxxxx" - - skip_region_validation = true - skip_credentials_validation = true - skip_requesting_account_id = true - - } -} diff --git a/terraform/prod/main.tf b/terraform/prod/main.tf deleted file mode 100644 index 6d4ef8e..0000000 --- a/terraform/prod/main.tf +++ /dev/null @@ -1,39 +0,0 @@ -/* -terraform { - required_version = ">= 1.0.0" - required_providers { - yandex = { - source = "yandex-cloud/yandex" - version = ">= 0.103.0" - } - } -} -*/ - -provider "yandex" { - service_account_key_file = var.service_account_key_file - cloud_id = var.cloud_id - folder_id = var.folder_id - zone = var.zone -} - -module "app" { -source = "../modules/app" -public_key_path = var.public_key_path -subnet_id = var.subnet_id -folder_id = var.folder_id -app_disk_image = var.app_disk_image -zone = var.zone -cloud_id = var.cloud_id -service_account_key_file = var.service_account_key_file -} -module "db" { -source = "../modules/db" -public_key_path = var.public_key_path -subnet_id = var.subnet_id -folder_id = var.folder_id -db_disk_image = var.db_disk_image -zone = var.zone -cloud_id = var.cloud_id -service_account_key_file = var.service_account_key_file -} diff --git a/terraform/prod/outputs.tf b/terraform/prod/outputs.tf deleted file mode 100644 index 2f94927..0000000 --- a/terraform/prod/outputs.tf +++ /dev/null @@ -1,6 +0,0 @@ -output "external_ip_address_app" { - value = module.app.external_ip_address_app -} -output "external_ip_address_db" { - value = module.db.external_ip_address_db -} diff --git a/terraform/prod/terraform.tfvars.example b/terraform/prod/terraform.tfvars.example deleted file mode 100644 index 6a6807b..0000000 --- a/terraform/prod/terraform.tfvars.example +++ /dev/null @@ -1,11 +0,0 @@ -cloud_id = "b1gulp4hfrunfqk3lttb" -folder_id = "b1gsnn20hr06bqfra90t" -zone = "ru-central1-a" -service_account_key_file = "xxxxxxxxx/key.json" -public_key_path = "xxxxxxxxx/ubuntu.pub" -private_key_path = "xxxxxxxxx/ubuntu" -image_id = "fd8an808ivtptq6jemm6" -subnet_id = "e9b4tphlh2sjr6g0j2cq" -app_disk_image = "fd8atnk3t60s5fmiaqil" -db_disk_image = "fd8u6gsncuov2n36bcrt" -environment_space = "prod" diff --git a/terraform/prod/variables.tf b/terraform/prod/variables.tf deleted file mode 100644 index 5db084a..0000000 --- a/terraform/prod/variables.tf +++ /dev/null @@ -1,44 +0,0 @@ -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 private key used for ssh access" -} -variable "app_disk_image" { -description = "Disk image for reddit app" -default = "reddit-app-base" -} -variable db_disk_image { -description = "Disk image for reddit db" -default = "reddit-db-base" -} -variable "environment_space" { - description = "Environment space prod" -} -variable "access_key" { - description = "key for s3 bucket" -} -variable secret_key { - description = "secret for s3 bucket" -} diff --git a/terraform/stage/.terraform.lock.hcl b/terraform/stage/.terraform.lock.hcl deleted file mode 100644 index 5754d2e..0000000 --- a/terraform/stage/.terraform.lock.hcl +++ /dev/null @@ -1,10 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/yandex-cloud/yandex" { - version = "0.106.0" - constraints = ">= 0.103.0" - hashes = [ - "h1:jHMQuc/PzkR31x8qgm5sM6D5yhN0X/NwkbNJCZZjWPE=", - ] -} diff --git a/terraform/stage/backend.tf b/terraform/stage/backend.tf deleted file mode 100644 index 6b84709..0000000 --- a/terraform/stage/backend.tf +++ /dev/null @@ -1,18 +0,0 @@ - -terraform { - -backend "s3" { - endpoints = { - s3 = "https://storage.yandexcloud.net" - } - bucket = "test-states" - region = "ru-central1" - key = "stage/stage.tfstate" - - skip_region_validation = true - skip_credentials_validation = true - skip_requesting_account_id = true - skip_s3_checksum = true - - } -} diff --git a/terraform/stage/main.tf b/terraform/stage/main.tf deleted file mode 100644 index 842d8ab..0000000 --- a/terraform/stage/main.tf +++ /dev/null @@ -1,42 +0,0 @@ - -terraform { - required_version = ">= 1.0.0" - required_providers { - yandex = { - source = "yandex-cloud/yandex" - version = ">= 0.103.0" - } - } -} - - -provider "yandex" { - service_account_key_file = var.service_account_key_file - token = var.yc_token - access_key = var.access_key - secret_key = var.secret_key - cloud_id = var.cloud_id - folder_id = var.folder_id - zone = var.zone -} - -module "app" { -source = "../modules/app" -public_key_path = var.public_key_path -subnet_id = var.subnet_id -folder_id = var.folder_id -app_disk_image = var.app_disk_image -zone = var.zone -cloud_id = var.cloud_id -service_account_key_file = var.service_account_key_file -} -module "db" { -source = "../modules/db" -public_key_path = var.public_key_path -subnet_id = var.subnet_id -folder_id = var.folder_id -db_disk_image = var.db_disk_image -zone = var.zone -cloud_id = var.cloud_id -service_account_key_file = var.service_account_key_file -} diff --git a/terraform/stage/outputs.tf b/terraform/stage/outputs.tf deleted file mode 100644 index 2f94927..0000000 --- a/terraform/stage/outputs.tf +++ /dev/null @@ -1,6 +0,0 @@ -output "external_ip_address_app" { - value = module.app.external_ip_address_app -} -output "external_ip_address_db" { - value = module.db.external_ip_address_db -} diff --git a/terraform/stage/terraform.tfvars.example b/terraform/stage/terraform.tfvars.example deleted file mode 100644 index f26537e..0000000 --- a/terraform/stage/terraform.tfvars.example +++ /dev/null @@ -1,11 +0,0 @@ -cloud_id = "b1gulp4hfrunfqk3lttb" -folder_id = "b1gsnn20hr06bqfra90t" -zone = "ru-central1-a" -service_account_key_file = "xxxxxxxxx/key.json" -public_key_path = "xxxxxxxxx/ubuntu.pub" -private_key_path = "xxxxxxxxx/ubuntu" -image_id = "fd8an808ivtptq6jemm6" -subnet_id = "e9b4tphlh2sjr6g0j2cq" -app_disk_image = "fd8atnk3t60s5fmiaqil" -db_disk_image = "fd8u6gsncuov2n36bcrt" -environment_space = "stage" diff --git a/terraform/stage/variables.tf b/terraform/stage/variables.tf deleted file mode 100644 index cb89185..0000000 --- a/terraform/stage/variables.tf +++ /dev/null @@ -1,48 +0,0 @@ -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 private key used for ssh access" -} -variable "app_disk_image" { -description = "Disk image for reddit app" -default = "reddit-app-base" -} -variable db_disk_image { -description = "Disk image for reddit db" -default = "reddit-db-base" -} -variable "environment_space" { - description = "Environment space stage" -} -variable "access_key" { - description = "key for s3 bucket" -} -variable secret_key { - description = "secret for s3 bucket" -} -variable yc_token { - type = string - description = "yc_token" -} diff --git a/terraform/storage-bucket.tf b/terraform/storage-bucket.tf deleted file mode 100644 index b0523cf..0000000 --- a/terraform/storage-bucket.tf +++ /dev/null @@ -1,35 +0,0 @@ -#terraform { -# required_version = ">= 1.0.0" -# required_providers { -# yandex = { -# source = "yandex-cloud/yandex" -# version = ">= 0.103.0" -# } -# } - -backend "s3" { - endpoints = { - s3 = "https://storage.yandexcloud.net" - } - bucket = "test-states" - region = "ru-central1" - key = "main/main.tfstate" - - - skip_region_validation = true - skip_credentials_validation = true - skip_requesting_account_id = true - skip_s3_checksum = true - - } -} - -provider "yandex" { - # access_key = var.access_key - # secret_key = var.secret_key - token = var.yc_token - service_account_key_file = var.service_account_key_file - cloud_id = var.cloud_id - folder_id = var.folder_id - zone = var.zone -} diff --git a/terraform/terraform.tfvars.example b/terraform/terraform.tfvars.example deleted file mode 100644 index 3df14ed..0000000 --- a/terraform/terraform.tfvars.example +++ /dev/null @@ -1,13 +0,0 @@ -yc_token = "y0_AgAAAABnLd1xAATuwxxxxxxxxxxxxxxxxxxxxxxxxxxx" -cloud_id = "b1gulp4hfrunfqk3lttb" -folder_id = "b1gsnn20hr06bqfra90t" -zone = "ru-central1-a" -service_account_key_file = "xxxxxxxxx/key.json" -public_key_path = "xxxxxxxxx/ubuntu.pub" -private_key_path = "xxxxxxxxx/ubuntu" -image_id = "fd8an808ivtptq6jemm6" -subnet_id = "e9b4tphlh2sjr6g0j2cq" -app_disk_image = "fd8atnk3t60s5fmiaqil" -db_disk_image = "fd8u6gsncuov2n36bcrt" -access_key = "YCAJEHdVd2Qxxxxxxxxxxxxx" -secret_key = "YCNOs05Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" diff --git a/terraform/variables.tf b/terraform/variables.tf deleted file mode 100644 index d07c743..0000000 --- a/terraform/variables.tf +++ /dev/null @@ -1,45 +0,0 @@ -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 private key used for ssh access" -} -variable "app_disk_image" { -description = "Disk image for reddit app" -default = "reddit-app-base" -} -variable db_disk_image { -description = "Disk image for reddit db" -default = "reddit-db-base" -} -variable "access_key" { - description = "key for s3 bucket" -} -variable secret_key { - description = "secret for s3 bucket" -} -variable yc_token { - type = string - description = "yc_token" -} From e7a09b4d1107d018d33f9a557ca3e7a64747b02c Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 18 Feb 2024 21:11:23 +0300 Subject: [PATCH 10/13] add tfvars for prod & stage --- terraform/prod/terraform.tfvars.example | 14 ++++++++++++++ terraform/stage/terraform.tfvars.example | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 terraform/prod/terraform.tfvars.example create mode 100644 terraform/stage/terraform.tfvars.example diff --git a/terraform/prod/terraform.tfvars.example b/terraform/prod/terraform.tfvars.example new file mode 100644 index 0000000..5b43e3d --- /dev/null +++ b/terraform/prod/terraform.tfvars.example @@ -0,0 +1,14 @@ +yc_token = "y0_AgAAAABnLd1xAATuwQAAAADx1Dxxxxxxxxxxxxxxxxx" +cloud_id = "b1gulp4hfrunfqk3lttb" +folder_id = "b1gsnn20hr06bqfra90t" +zone = "ru-central1-a" +service_account_key_file = "xxxxxxxxx/key.json" +public_key_path = "xxxxxxxxx/ubuntu.pub" +private_key_path = "xxxxxxxxx/ubuntu" +image_id = "fd8an808ivtptq6jemm6" +subnet_id = "e9b4tphlh2sjr6g0j2cq" +app_disk_image = "fd8atnk3t60s5fmiaqil" +db_disk_image = "fd8u6gsncuov2n36bcrt" +environment_space = "prod" +access_key = "YCAJEHdVd2Qxxxxxxxxxxxxx" +secret_key = "YCNOs05Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" diff --git a/terraform/stage/terraform.tfvars.example b/terraform/stage/terraform.tfvars.example new file mode 100644 index 0000000..41f0884 --- /dev/null +++ b/terraform/stage/terraform.tfvars.example @@ -0,0 +1,14 @@ +yc_token = "y0_AgAAAABnLd1xAATuwQAAAADx1Dxxxxxxxxxxxxxxxxx" +cloud_id = "b1gulp4hfrunfqk3lttb" +folder_id = "b1gsnn20hr06bqfra90t" +zone = "ru-central1-a" +service_account_key_file = "xxxxxxxxx/key.json" +public_key_path = "xxxxxxxxx/ubuntu.pub" +private_key_path = "xxxxxxxxx/ubuntu" +image_id = "fd8an808ivtptq6jemm6" +subnet_id = "e9b4tphlh2sjr6g0j2cq" +app_disk_image = "fd8atnk3t60s5fmiaqil" +db_disk_image = "fd8u6gsncuov2n36bcrt" +environment_space = "stage" +access_key = "YCAJEHdVd2Qxxxxxxxxxxxxx" +secret_key = "YCNOs05Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" From 5999e7e4c8ad3488371ec308d197c953a206c705 Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 18 Feb 2024 22:39:07 +0300 Subject: [PATCH 11/13] Terraform has been successfully initialized! --- terraform/prod/main.tf | 42 +++++++++++++++++++++++++++++++++++++ terraform/stage/main.tf | 42 +++++++++++++++++++++++++++++++++++++ terraform/storage-bucket.tf | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 terraform/prod/main.tf create mode 100644 terraform/stage/main.tf create mode 100644 terraform/storage-bucket.tf diff --git a/terraform/prod/main.tf b/terraform/prod/main.tf new file mode 100644 index 0000000..cebd8b2 --- /dev/null +++ b/terraform/prod/main.tf @@ -0,0 +1,42 @@ +/* +terraform { + required_version = ">= 1.0.0" + required_providers { + yandex = { + source = "yandex-cloud/yandex" + version = ">= 0.103.0" + } + } +} +*/ + +provider "yandex" { + service_account_key_file = var.service_account_key_file + token = var.yc_token + access_key = var.access_key + secret_key = var.secret_key + cloud_id = var.cloud_id + folder_id = var.folder_id + zone = var.zone +} + +module "app" { +source = "../modules/app" +public_key_path = var.public_key_path +subnet_id = var.subnet_id +folder_id = var.folder_id +app_disk_image = var.app_disk_image +zone = var.zone +cloud_id = var.cloud_id +service_account_key_file = var.service_account_key_file +} +module "db" { +source = "../modules/db" +public_key_path = var.public_key_path +subnet_id = var.subnet_id +folder_id = var.folder_id +db_disk_image = var.db_disk_image +zone = var.zone +cloud_id = var.cloud_id +service_account_key_file = var.service_account_key_file +} diff --git a/terraform/stage/main.tf b/terraform/stage/main.tf new file mode 100644 index 0000000..cebd8b2 --- /dev/null +++ b/terraform/stage/main.tf @@ -0,0 +1,42 @@ +/* +terraform { + required_version = ">= 1.0.0" + required_providers { + yandex = { + source = "yandex-cloud/yandex" + version = ">= 0.103.0" + } + } +} +*/ + +provider "yandex" { + service_account_key_file = var.service_account_key_file + token = var.yc_token + access_key = var.access_key + secret_key = var.secret_key + cloud_id = var.cloud_id + folder_id = var.folder_id + zone = var.zone +} + +module "app" { +source = "../modules/app" +public_key_path = var.public_key_path +subnet_id = var.subnet_id +folder_id = var.folder_id +app_disk_image = var.app_disk_image +zone = var.zone +cloud_id = var.cloud_id +service_account_key_file = var.service_account_key_file +} +module "db" { +source = "../modules/db" +public_key_path = var.public_key_path +subnet_id = var.subnet_id +folder_id = var.folder_id +db_disk_image = var.db_disk_image +zone = var.zone +cloud_id = var.cloud_id +service_account_key_file = var.service_account_key_file +} diff --git a/terraform/storage-bucket.tf b/terraform/storage-bucket.tf new file mode 100644 index 0000000..6afaf63 --- /dev/null +++ b/terraform/storage-bucket.tf @@ -0,0 +1,38 @@ +/* +terraform { + required_version = ">= 1.0.0" + required_providers { + yandex = { + source = "yandex-cloud/yandex" + version = ">= 0.103.0" + } + } + + +backend "s3" { + endpoints = { + s3 = "https://storage.yandexcloud.net" + } + bucket = "test-states" + region = "ru-central1" + key = "main/main.tfstate" + + + skip_region_validation = true + skip_credentials_validation = true + skip_requesting_account_id = true + skip_s3_checksum = true + + } +} +*/ + +provider "yandex" { + # access_key = var.access_key + # secret_key = var.secret_key + token = var.yc_token + service_account_key_file = var.service_account_key_file + cloud_id = var.cloud_id + folder_id = var.folder_id + zone = var.zone +} From 34fae9da9472348f35352088e3cf48453034efe6 Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 18 Feb 2024 22:43:52 +0300 Subject: [PATCH 12/13] add modules_dir --- terraform/modules/app/main.tf | 29 +++++++++++++++++++++++++ terraform/modules/app/outputs.tf | 3 +++ terraform/modules/app/variables.tf | 25 ++++++++++++++++++++++ terraform/modules/db/main.tf | 34 ++++++++++++++++++++++++++++++ terraform/modules/db/outputs.tf | 5 +++++ terraform/modules/db/variables.tf | 25 ++++++++++++++++++++++ terraform/modules/vpc/vpc.tf | 9 ++++++++ 7 files changed, 130 insertions(+) create mode 100644 terraform/modules/app/main.tf create mode 100644 terraform/modules/app/outputs.tf create mode 100644 terraform/modules/app/variables.tf create mode 100644 terraform/modules/db/main.tf create mode 100644 terraform/modules/db/outputs.tf create mode 100644 terraform/modules/db/variables.tf create mode 100644 terraform/modules/vpc/vpc.tf diff --git a/terraform/modules/app/main.tf b/terraform/modules/app/main.tf new file mode 100644 index 0000000..ecde1ff --- /dev/null +++ b/terraform/modules/app/main.tf @@ -0,0 +1,29 @@ +provider "yandex" { + 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" + labels = { + tags = "reddit-app" + } + resources { + core_fraction = 20 + cores = 2 + memory = 2 + } + boot_disk { + initialize_params { + image_id = var.app_disk_image + } + } + network_interface { + subnet_id = var.subnet_id + nat = true + } + metadata = { + ssh-keys = "ubuntu:${file(var.public_key_path)}" + } +} diff --git a/terraform/modules/app/outputs.tf b/terraform/modules/app/outputs.tf new file mode 100644 index 0000000..5e66420 --- /dev/null +++ b/terraform/modules/app/outputs.tf @@ -0,0 +1,3 @@ +output "external_ip_address_app" { +value = yandex_compute_instance.app.network_interface.0.nat_ip_address +} diff --git a/terraform/modules/app/variables.tf b/terraform/modules/app/variables.tf new file mode 100644 index 0000000..4f119e2 --- /dev/null +++ b/terraform/modules/app/variables.tf @@ -0,0 +1,25 @@ +variable "public_key_path" { + # Описание переменной + description = "Path to the public key used for ssh access" +} +variable "subnet_id" { + description = "Subnet" +} +variable app_disk_image { +description = "Disk image for reddit app" +default = "reddit-app-base" +} +variable "zone" { + description = "Zone" + # Значение по умолчанию + default = "ru-central1-a" +} +variable "cloud_id" { + description = "Cloud" +} +variable "service_account_key_file" { + description = "key.json" +} +variable "folder_id" { + description = "Folder" +} diff --git a/terraform/modules/db/main.tf b/terraform/modules/db/main.tf new file mode 100644 index 0000000..bc76a79 --- /dev/null +++ b/terraform/modules/db/main.tf @@ -0,0 +1,34 @@ +provider "yandex" { + 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" "db" { + name = "reddit-db" + labels = { + tags = "reddit-db" + } + + resources { + core_fraction = 20 + cores = 2 + memory = 2 + } + + boot_disk { + initialize_params { + image_id = var.db_disk_image + } + } + + network_interface { + subnet_id = var.subnet_id + nat = true + } + + metadata = { + ssh-keys = "ubuntu:${file(var.public_key_path)}" + } +} diff --git a/terraform/modules/db/outputs.tf b/terraform/modules/db/outputs.tf new file mode 100644 index 0000000..2415f62 --- /dev/null +++ b/terraform/modules/db/outputs.tf @@ -0,0 +1,5 @@ +output "external_ip_address_db" { +value = yandex_compute_instance.db.network_interface.0.nat_ip_address +} +#value = yandex_compute_instance.db.*.network_interface.0.ip_address +#} diff --git a/terraform/modules/db/variables.tf b/terraform/modules/db/variables.tf new file mode 100644 index 0000000..d1f3774 --- /dev/null +++ b/terraform/modules/db/variables.tf @@ -0,0 +1,25 @@ +variable "public_key_path" { + # Описание переменной + description = "Path to the public key used for ssh access" +} +variable "subnet_id" { + description = "Subnet" +} +variable db_disk_image { +description = "Disk image for reddit db" +default = "reddit-db-base" +} +variable "zone" { + description = "Zone" + # Значение по умолчанию + default = "ru-central1-a" +} +variable "cloud_id" { + description = "Cloud" +} +variable "service_account_key_file" { + description = "key.json" +} +variable "folder_id" { + description = "Folder" +} diff --git a/terraform/modules/vpc/vpc.tf b/terraform/modules/vpc/vpc.tf new file mode 100644 index 0000000..602fc8c --- /dev/null +++ b/terraform/modules/vpc/vpc.tf @@ -0,0 +1,9 @@ +resource "yandex_vpc_network" "app-network" { +name = "app-network" +} +resource "yandex_vpc_subnet" "app-subnet" { +name = "app-subnet" +zone = "ru-central1-a" +network_id = "${yandex_vpc_network.app-network.id}" +v4_cidr_blocks = ["192.168.10.0/24"] +} From bce76e408d031358b0a7348575983c85c88f9ea7 Mon Sep 17 00:00:00 2001 From: alkstmshkn Date: Sun, 18 Feb 2024 22:49:09 +0300 Subject: [PATCH 13/13] add terraform VARS --- terraform/prod/variables.tf | 48 ++++++++++++++++++++++++++++++++++++ terraform/stage/variables.tf | 48 ++++++++++++++++++++++++++++++++++++ terraform/variables.tf | 45 +++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 terraform/prod/variables.tf create mode 100644 terraform/stage/variables.tf create mode 100644 terraform/variables.tf diff --git a/terraform/prod/variables.tf b/terraform/prod/variables.tf new file mode 100644 index 0000000..e94698b --- /dev/null +++ b/terraform/prod/variables.tf @@ -0,0 +1,48 @@ +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 private key used for ssh access" +} +variable "app_disk_image" { +description = "Disk image for reddit app" +default = "reddit-app-base" +} +variable db_disk_image { +description = "Disk image for reddit db" +default = "reddit-db-base" +} +variable "environment_space" { + description = "Environment space prod" +} +variable "access_key" { + description = "key for s3 bucket" +} +variable secret_key { + description = "secret for s3 bucket" +} +variable yc_token { + type = string + description = "yc_token" +} diff --git a/terraform/stage/variables.tf b/terraform/stage/variables.tf new file mode 100644 index 0000000..cb89185 --- /dev/null +++ b/terraform/stage/variables.tf @@ -0,0 +1,48 @@ +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 private key used for ssh access" +} +variable "app_disk_image" { +description = "Disk image for reddit app" +default = "reddit-app-base" +} +variable db_disk_image { +description = "Disk image for reddit db" +default = "reddit-db-base" +} +variable "environment_space" { + description = "Environment space stage" +} +variable "access_key" { + description = "key for s3 bucket" +} +variable secret_key { + description = "secret for s3 bucket" +} +variable yc_token { + type = string + description = "yc_token" +} diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..d07c743 --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,45 @@ +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 private key used for ssh access" +} +variable "app_disk_image" { +description = "Disk image for reddit app" +default = "reddit-app-base" +} +variable db_disk_image { +description = "Disk image for reddit db" +default = "reddit-db-base" +} +variable "access_key" { + description = "key for s3 bucket" +} +variable secret_key { + description = "secret for s3 bucket" +} +variable yc_token { + type = string + description = "yc_token" +}