Skip to content

Commit

Permalink
add modules_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
alkstmshkn committed Feb 18, 2024
1 parent 5999e7e commit 34fae9d
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 0 deletions.
29 changes: 29 additions & 0 deletions terraform/modules/app/main.tf
Original file line number Diff line number Diff line change
@@ -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)}"
}
}
3 changes: 3 additions & 0 deletions terraform/modules/app/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
}
25 changes: 25 additions & 0 deletions terraform/modules/app/variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}
34 changes: 34 additions & 0 deletions terraform/modules/db/main.tf
Original file line number Diff line number Diff line change
@@ -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)}"
}
}
5 changes: 5 additions & 0 deletions terraform/modules/db/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
#}
25 changes: 25 additions & 0 deletions terraform/modules/db/variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}
9 changes: 9 additions & 0 deletions terraform/modules/vpc/vpc.tf
Original file line number Diff line number Diff line change
@@ -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"]
}

0 comments on commit 34fae9d

Please sign in to comment.