diff --git a/.gitignore b/.gitignore index 30d74d2584..0e4c95c492 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ -test \ No newline at end of file +**/.terraform/* +*.tfstate +*.tfstate.* +*.tfvars +yc-key.json +id_rsa +id_rsa.pub \ No newline at end of file diff --git a/labs/app_python/pulumi/.gitignore b/labs/app_python/pulumi/.gitignore new file mode 100644 index 0000000000..a3807e5bdb --- /dev/null +++ b/labs/app_python/pulumi/.gitignore @@ -0,0 +1,2 @@ +*.pyc +venv/ diff --git a/labs/app_python/pulumi/Pulumi.dev.yaml b/labs/app_python/pulumi/Pulumi.dev.yaml new file mode 100644 index 0000000000..3fc954d2fc --- /dev/null +++ b/labs/app_python/pulumi/Pulumi.dev.yaml @@ -0,0 +1,6 @@ +encryptionsalt: v1:VOWYF2ib5ug=:v1:BMl6B+O3G1V2TCs2:j4xsbIEdJB7nG4SAFJrtGpT6EFZLsw== +config: + yandex:cloudId: b1gv84qp02od589u3le0 + yandex:folderId: b1g9bh9kbc2skuhht2de + yandex:zone: ru-central1-a + yandex:serviceAccountKeyFile: /workspaces/DevOps-Core-Course/labs/yc-key.json diff --git a/labs/app_python/pulumi/Pulumi.yaml b/labs/app_python/pulumi/Pulumi.yaml new file mode 100644 index 0000000000..9105928901 --- /dev/null +++ b/labs/app_python/pulumi/Pulumi.yaml @@ -0,0 +1,10 @@ +name: app-python +description: lab04 pulumi part +runtime: + name: python + options: + toolchain: pip +config: + pulumi:tags: + value: + pulumi:template: python diff --git a/labs/app_python/pulumi/__main__.py b/labs/app_python/pulumi/__main__.py new file mode 100644 index 0000000000..0637b0ec13 --- /dev/null +++ b/labs/app_python/pulumi/__main__.py @@ -0,0 +1,32 @@ +import pulumi +import pulumi_yandex as yandex + +network = yandex.VpcNetwork("lab-network") + +subnet = yandex.VpcSubnet( + "lab-subnet", + network_id=network.id, + zone="ru-central1-a", + v4_cidr_blocks=["10.0.0.0/24"] +) + +vm = yandex.ComputeInstance( + "lab-vm", + resources={ + "cores": 2, + "memory": 1, + "core_fraction": 20 + }, + boot_disk={ + "initialize_params": { + "image_id": "fd80qm01ah03dkqb14lc", + "size": 30 + } + }, + network_interfaces=[{ + "subnet_id": subnet.id, + "nat": True + }] +) + +pulumi.export("public_ip", vm.network_interfaces[0].nat_ip_address) \ No newline at end of file diff --git a/labs/app_python/pulumi/requirements.txt b/labs/app_python/pulumi/requirements.txt new file mode 100644 index 0000000000..ded3a4e88d --- /dev/null +++ b/labs/app_python/pulumi/requirements.txt @@ -0,0 +1,2 @@ +pulumi>=3.0.0,<4.0.0 +pulumi-yandex \ No newline at end of file diff --git a/labs/app_python/terraform/.terraform.lock.hcl b/labs/app_python/terraform/.terraform.lock.hcl new file mode 100644 index 0000000000..4322722cec --- /dev/null +++ b/labs/app_python/terraform/.terraform.lock.hcl @@ -0,0 +1,22 @@ +# 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.190.0" + hashes = [ + "h1:AYCj4pxRSXXzuQnb28QhLj/XqbfFuUiFrQgEXLZnm14=", + "zh:39577304131502f989bf3a97d5de8417898e14ea69a92002c5151c83ecb1e948", + "zh:476a84d42d45fd553213e2612b83d51165baa8ea59b80dc3143a5f6745e26432", + "zh:57d92fb9424013c1ce01a1a0977ee4adedfa4f2ab5dafb3d0de890317629120a", + "zh:648db15d880cbfd93473dd3a642ede1f91977ec5c7147cdf23d3343ddff2299c", + "zh:774ebd4f7ea8d4cc6df36840e0b65a10f60a4157e6842fd026a633a985978255", + "zh:80f0b68f28e61f6a843962c80e341bf2bfb7bb3943c261f36e3a896ab6162eff", + "zh:8e14d20dcff177d9b6bcac07b6c6650ec04fce56c53a0d5d4ed039b7971e4a36", + "zh:aef377dcea92d8045c1e6f4f76371c450a87b112918930c51c6ab640c6f5a403", + "zh:c06d3e888f38990684c8acac4385402fbddb8f4bb41076575345aba0866a30d5", + "zh:c1c32d292f2d0fca549adf83e4e6b974493a56c752c6e95a20e35df65d3cf845", + "zh:c2538900499b1025827d34ffb7f6616c3e2e2ba8aa12a8f11030d276d7a4e4d5", + "zh:e954a17935e7489a2c13e110af2b6a09387c9c3d57e4bc6f596993f5f398d3ef", + "zh:f0767078524982d45e6cc679a57cd40d11e28d4d1ec0e33d04b0adba4dc5253c", + ] +} diff --git a/labs/app_python/terraform/main.tf b/labs/app_python/terraform/main.tf new file mode 100644 index 0000000000..9bb4f31da9 --- /dev/null +++ b/labs/app_python/terraform/main.tf @@ -0,0 +1,55 @@ +terraform { + required_providers { + yandex = { + source = "yandex-cloud/yandex" + } + } +} + +provider "yandex" { + service_account_key_file = var.service_account_key_file + cloud_id = var.cloud_id + folder_id = var.folder_id + zone = var.zone +} + +# --- Network --- +resource "yandex_vpc_network" "lab_network" { + name = "lab-network" +} + +# --- Subnet --- +resource "yandex_vpc_subnet" "lab_subnet" { + name = "lab-subnet" + zone = var.zone + network_id = yandex_vpc_network.lab_network.id + v4_cidr_blocks = ["10.0.0.0/24"] +} + +# --- VM --- +resource "yandex_compute_instance" "vm" { + name = "lab04-vm" + platform_id = "standard-v2" + + resources { + cores = 2 + memory = 1 + core_fraction = 20 + } + + boot_disk { + initialize_params { + image_id = "fd80qm01ah03dkqb14lc" + size = 30 + } + } + + network_interface { + subnet_id = yandex_vpc_subnet.lab_subnet.id + nat = true + } + + metadata = { + ssh-keys = "ubuntu:${file(var.ssh_public_key_path)}" + } +} \ No newline at end of file diff --git a/labs/app_python/terraform/outputs.tf b/labs/app_python/terraform/outputs.tf new file mode 100644 index 0000000000..032c54474c --- /dev/null +++ b/labs/app_python/terraform/outputs.tf @@ -0,0 +1,3 @@ +output "public_ip" { + value = yandex_compute_instance.vm.network_interface[0].nat_ip_address +} \ No newline at end of file diff --git a/labs/app_python/terraform/variables.tf b/labs/app_python/terraform/variables.tf new file mode 100644 index 0000000000..91492d86ef --- /dev/null +++ b/labs/app_python/terraform/variables.tf @@ -0,0 +1,9 @@ +variable "cloud_id" {} +variable "folder_id" {} + +variable "zone" { + default = "ru-central1-a" +} + +variable "service_account_key_file" {} +variable "ssh_public_key_path" {} \ No newline at end of file