From d890863c27403431b430aff4df17aea4f4980c8b Mon Sep 17 00:00:00 2001 From: Leonid Lachmann Date: Mon, 25 Aug 2025 21:55:55 +0300 Subject: [PATCH 01/17] experimental-1 --- .terraform/modules/modules.json | 1 + .terraform/terraform.tfstate | 41 ++++++++++++ backend.tf | 8 +++ files.txt | 107 ++++++++++++++++++++++++++++++++ main.tf | 51 +++++++++++++++ modules/compute/main.tf | 12 ++++ modules/compute/outputs.tf | 9 +++ modules/compute/variables.tf | 36 +++++++++++ modules/network/main.tf | 59 ++++++++++++++++++ modules/network/outputs.tf | 16 +++++ modules/network/variables.tf | 44 +++++++++++++ modules/storage/main.tf | 13 ++++ modules/storage/outputs.tf | 8 +++ modules/storage/variables.tf | 16 +++++ outputs.tf | 7 +++ terraform.tfvars | 3 + variables.tf | 78 +++++++++++++++++++++++ 17 files changed, 509 insertions(+) create mode 100644 .terraform/modules/modules.json create mode 100644 .terraform/terraform.tfstate create mode 100644 backend.tf create mode 100644 files.txt create mode 100644 main.tf create mode 100644 modules/compute/main.tf create mode 100644 modules/compute/outputs.tf create mode 100644 modules/compute/variables.tf create mode 100644 modules/network/main.tf create mode 100644 modules/network/outputs.tf create mode 100644 modules/network/variables.tf create mode 100644 modules/storage/main.tf create mode 100644 modules/storage/outputs.tf create mode 100644 modules/storage/variables.tf create mode 100644 outputs.tf create mode 100644 terraform.tfvars create mode 100644 variables.tf diff --git a/.terraform/modules/modules.json b/.terraform/modules/modules.json new file mode 100644 index 0000000..07ad431 --- /dev/null +++ b/.terraform/modules/modules.json @@ -0,0 +1 @@ +{"Modules":[{"Key":"","Source":"","Dir":"."},{"Key":"compute","Source":"./modules/compute","Dir":"modules/compute"},{"Key":"compute.compute","Source":"./modules/compute","Dir":""},{"Key":"network","Source":"./modules/network","Dir":"modules/network"},{"Key":"storage","Source":"./modules/storage","Dir":"modules/storage"}]} \ No newline at end of file diff --git a/.terraform/terraform.tfstate b/.terraform/terraform.tfstate new file mode 100644 index 0000000..38b1b21 --- /dev/null +++ b/.terraform/terraform.tfstate @@ -0,0 +1,41 @@ +{ + "version": 3, + "terraform_version": "1.12.2", + "backend": { + "type": "azurerm", + "config": { + "access_key": null, + "ado_pipeline_service_connection_id": null, + "client_certificate": null, + "client_certificate_password": null, + "client_certificate_path": null, + "client_id": null, + "client_id_file_path": null, + "client_secret": null, + "client_secret_file_path": null, + "container_name": "tfstate", + "endpoint": null, + "environment": null, + "key": "terraform.tfstate", + "lookup_blob_endpoint": null, + "metadata_host": null, + "msi_endpoint": null, + "oidc_request_token": null, + "oidc_request_url": null, + "oidc_token": null, + "oidc_token_file_path": null, + "resource_group_name": "mate-azure-task-backend", + "sas_token": null, + "snapshot": null, + "storage_account_name": "leidenstorage", + "subscription_id": null, + "tenant_id": null, + "use_aks_workload_identity": null, + "use_azuread_auth": null, + "use_cli": null, + "use_msi": null, + "use_oidc": null + }, + "hash": 3580684206 + } +} \ No newline at end of file diff --git a/backend.tf b/backend.tf new file mode 100644 index 0000000..c26a155 --- /dev/null +++ b/backend.tf @@ -0,0 +1,8 @@ +terraform { + backend "azurerm" { + resource_group_name = "mate-azure-task-12" + storage_account_name = "leidenstorage" + container_name = "tfstate" + key = "terraform.tfstate" + } +} \ No newline at end of file diff --git a/files.txt b/files.txt new file mode 100644 index 0000000..0a7e4ef --- /dev/null +++ b/files.txt @@ -0,0 +1,107 @@ + ⮬ Windows 10 +਩ ⮬: 000000D6 2450:3723 +C:\USERS\LEIDENLOKI\DEVOPS_TODOLIST_TERRAFORM_TASK + files.txt + image.png + install-app.sh + README.md + +.github + workflows + terraform-validate.yml + +app + .gitignore + LICENSE + manage.py + README.md + requirements.txt + start.sh + todoapp.service + + accounts + admin.py + forms.py + models.py + tests.py + urls.py + views.py + __init__.py + + migrations + __init__.py + + templates + accounts + login.html + register.html + + api + serializers.py + tests.py + urls.py + views.py + __init__.py + + migrations + __init__.py + + lists + admin.py + forms.py + models.py + tests.py + urls.py + views.py + __init__.py + + migrations + 0001_initial.py + __init__.py + + static + lists + css + table.css + + images + asc.gif + bg.gif + desc.gif + + js + jquery.tablesorter.min.js + lists.js + + templates + lists + index.html + overview.html + todolist.html + + templatetags + lists_extras.py + __init__.py + + todolist + settings.py + urls.py + wsgi.py + __init__.py + + static + css + custom.css + + images + favicon.png + + js + site.js + + templates + 403.html + 404.html + 500.html + base.html + diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..fd5cf6a --- /dev/null +++ b/main.tf @@ -0,0 +1,51 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 3.0.0" + } + } +} + +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "rg" { + name = var.resource_group_name + location = var.location +} + +module "network" { + source = "./modules/network" + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + virtual_network_name = var.virtual_network_name + vnet_address_prefix = var.vnet_address_prefix + subnet_name = var.subnet_name + subnet_address_prefix = var.subnet_address_prefix + network_security_group_name = var.network_security_group_name + public_ip_address_name = var.public_ip_address_name + dns_label = var.dns_label +} + +module "storage" { + source = "./modules/storage" + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + storage_account_name = var.storage_account_name_app_artifacts + storage_container_name = var.storage_container_name_app_artifacts +} + +module "compute" { + source = "./modules/compute" + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + vm_name = var.vm_name + vm_size = var.vm_size + ssh_key_public = var.ssh_key_public + subnet_id = module.network.subnet_id + public_ip_id = module.network.public_ip_id + script_url = module.storage.script_url + nsg_id = module.network.nsg_id +} diff --git a/modules/compute/main.tf b/modules/compute/main.tf new file mode 100644 index 0000000..a57a832 --- /dev/null +++ b/modules/compute/main.tf @@ -0,0 +1,12 @@ +module "compute" { + source = "./modules/compute" + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + vm_name = var.vm_name + vm_size = var.vm_size + ssh_key_public = var.ssh_key_public + subnet_id = module.network.subnet_id + public_ip_id = module.network.public_ip_id + storage_account_name = module.storage.storage_account_name + script_url = module.storage.script_url +} \ No newline at end of file diff --git a/modules/compute/outputs.tf b/modules/compute/outputs.tf new file mode 100644 index 0000000..cddda21 --- /dev/null +++ b/modules/compute/outputs.tf @@ -0,0 +1,9 @@ +output "vm_id" { + value = azurerm_linux_virtual_machine.main.id + description = "The ID of the virtual machine." +} + +output "vm_private_ip" { + value = azurerm_network_interface.main.private_ip_address + description = "The private IP address of the virtual machine." +} \ No newline at end of file diff --git a/modules/compute/variables.tf b/modules/compute/variables.tf new file mode 100644 index 0000000..06e6bdd --- /dev/null +++ b/modules/compute/variables.tf @@ -0,0 +1,36 @@ +variable "resource_group_name" { + description = "Name of the resource group" + type = string +} +variable "location" { + description = "Azure region for resources" + type = string +} +variable "virtual_network_name" { + description = "Name of the Virtual Network" + type = string +} +variable "vnet_address_prefix" { + description = "Address prefix for the Virtual Network" + type = list(string) # ЗМІНЕНО: тепер list(string) +} +variable "subnet_name" { + description = "Name of the Subnet" + type = string +} +variable "subnet_address_prefix" { + description = "Address prefix for the Subnet" + type = list(string) # ЗМІНЕНО: тепер list(string) +} +variable "network_security_group_name" { + description = "Name of the Network Security Group" + type = string +} +variable "public_ip_address_name" { + description = "Name of the Public IP Address" + type = string +} +variable "dns_label" { + description = "DNS label for the Public IP Address" + type = string +} \ No newline at end of file diff --git a/modules/network/main.tf b/modules/network/main.tf new file mode 100644 index 0000000..fa174c9 --- /dev/null +++ b/modules/network/main.tf @@ -0,0 +1,59 @@ +resource "azurerm_virtual_network" "vnet" { + name = var.virtual_network_name + location = var.location + resource_group_name = var.resource_group_name + address_space = var.vnet_address_prefix +} + +resource "azurerm_subnet" "subnet" { + name = var.subnet_name + resource_group_name = var.resource_group_name + virtual_network_name = azurerm_virtual_network.vnet.name + address_prefixes = var.subnet_address_prefix +} + +resource "azurerm_network_security_group" "nsg" { + name = var.network_security_group_name + location = var.location + resource_group_name = var.resource_group_name + + security_rule { + name = "SSH" + priority = 1001 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "22" + source_address_prefix = "*" + destination_address_prefix = "*" + } + security_rule { + name = "HTTP" + priority = 1002 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "80" + source_address_prefix = "*" + destination_address_prefix = "*" + } +} + +resource "azurerm_public_ip" "pip" { + name = var.public_ip_address_name + location = var.location + resource_group_name = var.resource_group_name + allocation_method = "Dynamic" + domain_name_label = "${var.dns_label}${random_integer.r.result}" + + tags = { + environment = "dev" + } +} + +resource "random_integer" "r" { + min = 10000 + max = 99999 +} \ No newline at end of file diff --git a/modules/network/outputs.tf b/modules/network/outputs.tf new file mode 100644 index 0000000..b8feb1f --- /dev/null +++ b/modules/network/outputs.tf @@ -0,0 +1,16 @@ +output "subnet_id" { + description = "The ID of the Subnet" + value = azurerm_subnet.subnet.id +} +output "nsg_id" { + description = "The ID of the Network Security Group" + value = azurerm_network_security_group.nsg.id +} +output "public_ip_address" { + description = "The Public IP Address of the Linux VM" + value = azurerm_public_ip.pip.ip_address +} +output "public_ip_fqdn" { + description = "The FQDN of the Public IP Address" + value = azurerm_public_ip.pip.fqdn +} \ No newline at end of file diff --git a/modules/network/variables.tf b/modules/network/variables.tf new file mode 100644 index 0000000..79e446e --- /dev/null +++ b/modules/network/variables.tf @@ -0,0 +1,44 @@ +variable "resource_group_name" { + description = "Назва групи ресурсів, до якої належить віртуальна машина." + type = string +} + +variable "location" { + description = "Регіон Azure для віртуальної машини." + type = string +} + +variable "virtual_network_name" { + description = "Назва віртуальної мережі." + type = string +} + +variable "vnet_address_prefix" { + description = "Префікс адреси для віртуальної мережі." + type = string +} + +variable "subnet_name" { + description = "Назва підмережі." + type = string +} + +variable "subnet_address_prefix" { + description = "Префікс адреси для підмережі." + type = string +} + +variable "network_security_group_name" { + description = "Назва групи безпеки мережі." + type = string +} + +variable "public_ip_address_name" { + description = "Назва публічної IP-адреси." + type = string +} + +variable "dns_label" { + description = "Мітка DNS для публічної IP-адреси." + type = string +} \ No newline at end of file diff --git a/modules/storage/main.tf b/modules/storage/main.tf new file mode 100644 index 0000000..a2053f2 --- /dev/null +++ b/modules/storage/main.tf @@ -0,0 +1,13 @@ +resource "azurerm_storage_account" "sa" { + name = var.storage_account_name + resource_group_name = var.resource_group_name + location = var.location + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_storage_container" "sc" { + name = var.storage_container_name + storage_account_name = azurerm_storage_account.sa.name + container_access_type = "blob" +} \ No newline at end of file diff --git a/modules/storage/outputs.tf b/modules/storage/outputs.tf new file mode 100644 index 0000000..2dcda4b --- /dev/null +++ b/modules/storage/outputs.tf @@ -0,0 +1,8 @@ +output "storage_account_name" { + description = "The name of the Storage Account for application artifacts" + value = azurerm_storage_account.sa.name +} +output "storage_container_name" { + description = "The name of the Storage Container for application artifacts" + value = azurerm_storage_container.sc.name +} \ No newline at end of file diff --git a/modules/storage/variables.tf b/modules/storage/variables.tf new file mode 100644 index 0000000..b94ddd0 --- /dev/null +++ b/modules/storage/variables.tf @@ -0,0 +1,16 @@ +variable "resource_group_name" { + description = "Name of the resource group" + type = string +} +variable "location" { + description = "Azure region for resources" + type = string +} +variable "storage_account_name" { + description = "Name of the storage account for application artifacts" + type = string +} +variable "storage_container_name" { + description = "Name of the storage container for application artifacts" + type = string +} \ No newline at end of file diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..d9f1c35 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,7 @@ +output "public_ip_address" { + value = module.network.public_ip_address +} + +output "public_ip_fqdn" { + value = module.network.public_ip_fqdn +} \ No newline at end of file diff --git a/terraform.tfvars b/terraform.tfvars new file mode 100644 index 0000000..2f647d9 --- /dev/null +++ b/terraform.tfvars @@ -0,0 +1,3 @@ +location = "uksouth" +resource_group_name = "mate-azure-task-12" +ssh_key_public = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCnTufDrlK40pNPp2Qho8Z7aixGNbV7q1hkfJzIUcQiYsr5eN1Utc/zx1E6IPDyHi+t4E5GKDm88yU8FbeDL3ShAULkB4/UvQzmTho2DjHRBEfAo9Z/pPkv0HJYtlgdol0aCwo30vWr/dRtq6Ir2Iw5hAZcAe3hKg2Qq9VfjBjiOTl434ONar0wajnApA550nuWEKU/vvQEBdP8Lx+vulteTGmvP9JWV4ZhWQVJkArYi0wvRX1UEoEj/P/eXNQl+h7BwxGRa3OyUaU7yCRE0QKba0mesAwSBdncs+tFqoNQD7JiCR7QnSzKoQ7MJQg/945d86UijPisT9IGGDyyB9kZrEUR/ePrCuH+xhFXuOdHectdH3xzui00zhdoiov6XfTYMrzoOF1+aJJFMI42yySGV5lWknfvIfAAr/1j6/1HPAIX/FDnlUPRRuMMLWHUAguW/oqXIRKzpR6h4/YVCe/cToHpPIkd3jZpCNADKXkp4Eoef78lOn1S71gVjzk1LOk=" \ No newline at end of file diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..97cbd5a --- /dev/null +++ b/variables.tf @@ -0,0 +1,78 @@ +# variables.tf (кореневий) +variable "location" { + description = "Azure region for all resources" + type = string + default = "uksouth" +} + +variable "resource_group_name" { + description = "Name of the main resource group" + type = string + default = "mate-azure-task-12" +} + +# Network Module Variables +variable "virtual_network_name" { + description = "Name of the Virtual Network" + type = string + default = "vnet" +} +variable "vnet_address_prefix" { + description = "Address prefix for the Virtual Network" + type = list(string) + default = ["10.0.0.0/16"] +} +variable "subnet_name" { + description = "Name of the Subnet" + type = string + default = "default" +} +variable "subnet_address_prefix" { + description = "Address prefix for the Subnet" + type = list(string) + default = ["10.0.0.0/24"] +} +variable "network_security_group_name" { + description = "Name of the Network Security Group" + type = string + default = "defaultnsg" +} +variable "public_ip_address_name" { + description = "Name of the Public IP Address" + type = string + default = "linuxboxpip" +} +variable "dns_label" { + description = "DNS label for the Public IP Address" + type = string + default = "matetask" +} + +# Compute Module Variables +variable "vm_name" { + description = "Name of the Virtual Machine" + type = string + default = "matebox" +} +variable "vm_size" { + description = "Size of the Virtual Machine" + type = string + default = "Standard_B1s" +} +variable "ssh_key_public" { + description = "Public SSH key content for VM access" + type = string + sensitive = true # Позначаємо як чутливу інформацію +} + +# Storage Module Variables for Application Artifacts +variable "storage_account_name_app_artifacts" { + description = "Name of the storage account for application artifacts" + type = string + default = "matetaskappstorage" # Унікальне ім'я +} +variable "storage_container_name_app_artifacts" { + description = "Name of the storage container for application artifacts" + type = string + default = "task-artifacts" +} From 2746bfac8e7eeb2ab8c87ebbf68c0ac9c24d9d55 Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 16:39:20 +0300 Subject: [PATCH 02/17] Update backend.tf 1 --- backend.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend.tf b/backend.tf index c26a155..1d054c3 100644 --- a/backend.tf +++ b/backend.tf @@ -1,8 +1,8 @@ terraform { backend "azurerm" { resource_group_name = "mate-azure-task-12" - storage_account_name = "leidenstorage" + storage_account_name = "yourstorageaccount" container_name = "tfstate" key = "terraform.tfstate" } -} \ No newline at end of file +} From 61dc799b490af9098c62a6afd9d09bf88bc832fe Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 16:44:17 +0300 Subject: [PATCH 03/17] Update main.tf 1 --- modules/compute/main.tf | 64 +++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/modules/compute/main.tf b/modules/compute/main.tf index a57a832..e78439e 100644 --- a/modules/compute/main.tf +++ b/modules/compute/main.tf @@ -1,12 +1,52 @@ -module "compute" { - source = "./modules/compute" - resource_group_name = azurerm_resource_group.rg.name - location = azurerm_resource_group.rg.location - vm_name = var.vm_name - vm_size = var.vm_size - ssh_key_public = var.ssh_key_public - subnet_id = module.network.subnet_id - public_ip_id = module.network.public_ip_id - storage_account_name = module.storage.storage_account_name - script_url = module.storage.script_url -} \ No newline at end of file +resource "azurerm_network_interface" "main" { + name = "${var.vm_name}-nic" + location = var.location + resource_group_name = var.resource_group_name + + ip_configuration { + name = "internal" + subnet_id = var.subnet_id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = var.public_ip_id + } +} + +resource "azurerm_linux_virtual_machine" "main" { + name = var.vm_name + resource_group_name = var.resource_group_name + location = var.location + size = var.vm_size + admin_username = "adminuser" + network_interface_ids = [azurerm_network_interface.main.id] + + admin_ssh_key { + username = "adminuser" + public_key = var.ssh_key_public + } + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "Canonical" + offer = "0001-com-ubuntu-server-jammy" + sku = "22_04-lts" + version = "latest" + } +} + +resource "azurerm_virtual_machine_extension" "main" { + name = "${var.vm_name}-install-app" + virtual_machine_id = azurerm_linux_virtual_machine.main.id + publisher = "Microsoft.Azure.Extensions" + type = "CustomScript" + type_handler_version = "2.0" + + settings = < Date: Sun, 12 Oct 2025 16:45:58 +0300 Subject: [PATCH 04/17] Update variables.tf 1 --- modules/compute/variables.tf | 40 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/modules/compute/variables.tf b/modules/compute/variables.tf index 06e6bdd..4e909e0 100644 --- a/modules/compute/variables.tf +++ b/modules/compute/variables.tf @@ -2,35 +2,39 @@ variable "resource_group_name" { description = "Name of the resource group" type = string } + variable "location" { description = "Azure region for resources" type = string } -variable "virtual_network_name" { - description = "Name of the Virtual Network" + +variable "vm_name" { + description = "Name of the virtual machine" type = string } -variable "vnet_address_prefix" { - description = "Address prefix for the Virtual Network" - type = list(string) # ЗМІНЕНО: тепер list(string) -} -variable "subnet_name" { - description = "Name of the Subnet" + +variable "vm_size" { + description = "Size of the virtual machine" type = string } -variable "subnet_address_prefix" { - description = "Address prefix for the Subnet" - type = list(string) # ЗМІНЕНО: тепер list(string) + +variable "ssh_key_public" { + description = "Public SSH key for the virtual machine" + type = string + sensitive = true } -variable "network_security_group_name" { - description = "Name of the Network Security Group" + +variable "subnet_id" { + description = "ID of the subnet to connect the VM to" type = string } -variable "public_ip_address_name" { - description = "Name of the Public IP Address" + +variable "public_ip_id" { + description = "ID of the public IP address to associate with the VM" type = string } -variable "dns_label" { - description = "DNS label for the Public IP Address" + +variable "script_url" { + description = "URL of the script to execute on the VM" type = string -} \ No newline at end of file +} From 8a7576f90bfb0f5364fb76baf322142f6500efdd Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 16:47:17 +0300 Subject: [PATCH 05/17] Update variables.tf 1 --- modules/network/variables.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/network/variables.tf b/modules/network/variables.tf index 79e446e..043b0c0 100644 --- a/modules/network/variables.tf +++ b/modules/network/variables.tf @@ -15,7 +15,7 @@ variable "virtual_network_name" { variable "vnet_address_prefix" { description = "Префікс адреси для віртуальної мережі." - type = string + type = list(string) } variable "subnet_name" { @@ -25,7 +25,7 @@ variable "subnet_name" { variable "subnet_address_prefix" { description = "Префікс адреси для підмережі." - type = string + type = list(string) } variable "network_security_group_name" { @@ -41,4 +41,4 @@ variable "public_ip_address_name" { variable "dns_label" { description = "Мітка DNS для публічної IP-адреси." type = string -} \ No newline at end of file +} From 6582c9bc3cf7b329f0c9e7d502b9739f8bc38035 Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:19:49 +0300 Subject: [PATCH 06/17] Delete .terraform/terraform.tfstate --- .terraform/terraform.tfstate | 41 ------------------------------------ 1 file changed, 41 deletions(-) delete mode 100644 .terraform/terraform.tfstate diff --git a/.terraform/terraform.tfstate b/.terraform/terraform.tfstate deleted file mode 100644 index 38b1b21..0000000 --- a/.terraform/terraform.tfstate +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": 3, - "terraform_version": "1.12.2", - "backend": { - "type": "azurerm", - "config": { - "access_key": null, - "ado_pipeline_service_connection_id": null, - "client_certificate": null, - "client_certificate_password": null, - "client_certificate_path": null, - "client_id": null, - "client_id_file_path": null, - "client_secret": null, - "client_secret_file_path": null, - "container_name": "tfstate", - "endpoint": null, - "environment": null, - "key": "terraform.tfstate", - "lookup_blob_endpoint": null, - "metadata_host": null, - "msi_endpoint": null, - "oidc_request_token": null, - "oidc_request_url": null, - "oidc_token": null, - "oidc_token_file_path": null, - "resource_group_name": "mate-azure-task-backend", - "sas_token": null, - "snapshot": null, - "storage_account_name": "leidenstorage", - "subscription_id": null, - "tenant_id": null, - "use_aks_workload_identity": null, - "use_azuread_auth": null, - "use_cli": null, - "use_msi": null, - "use_oidc": null - }, - "hash": 3580684206 - } -} \ No newline at end of file From 22ae2a3e8238b216ac89ee3e5f2753259a695e75 Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:20:33 +0300 Subject: [PATCH 07/17] Delete .terraform/modules/modules.json --- .terraform/modules/modules.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .terraform/modules/modules.json diff --git a/.terraform/modules/modules.json b/.terraform/modules/modules.json deleted file mode 100644 index 07ad431..0000000 --- a/.terraform/modules/modules.json +++ /dev/null @@ -1 +0,0 @@ -{"Modules":[{"Key":"","Source":"","Dir":"."},{"Key":"compute","Source":"./modules/compute","Dir":"modules/compute"},{"Key":"compute.compute","Source":"./modules/compute","Dir":""},{"Key":"network","Source":"./modules/network","Dir":"modules/network"},{"Key":"storage","Source":"./modules/storage","Dir":"modules/storage"}]} \ No newline at end of file From f873db65fbd032c512a955ed34ccd635a71812de Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:28:02 +0300 Subject: [PATCH 08/17] Update outputs.tf 2 --- modules/network/outputs.tf | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/modules/network/outputs.tf b/modules/network/outputs.tf index b8feb1f..b72f47e 100644 --- a/modules/network/outputs.tf +++ b/modules/network/outputs.tf @@ -1,16 +1,29 @@ +# The subnet ID. output "subnet_id" { - description = "The ID of the Subnet" + description = "The ID of the subnet." value = azurerm_subnet.subnet.id } + +# The Public IP Address ID. Required for NIC association. +output "public_ip_id" { + description = "The ID of the Public IP Address." + value = azurerm_public_ip.pip.id +} + +# The Network Security Group ID. Required for NIC association. output "nsg_id" { - description = "The ID of the Network Security Group" + description = "The ID of the Network Security Group." value = azurerm_network_security_group.nsg.id } + +# The Public IP address of the Linux VM. output "public_ip_address" { - description = "The Public IP Address of the Linux VM" + description = "The Public IP Address of the Linux VM." value = azurerm_public_ip.pip.ip_address } + +# The FQDN of the Public IP Address. output "public_ip_fqdn" { - description = "The FQDN of the Public IP Address" + description = "The FQDN of the Public IP Address." value = azurerm_public_ip.pip.fqdn -} \ No newline at end of file +} From 13022488bb2d6127ac669feefb0bed01ec22e33a Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:30:41 +0300 Subject: [PATCH 09/17] Update main.tf 2 --- modules/storage/main.tf | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/storage/main.tf b/modules/storage/main.tf index a2053f2..863eeee 100644 --- a/modules/storage/main.tf +++ b/modules/storage/main.tf @@ -1,3 +1,4 @@ +# Creates the storage account for application artifacts. resource "azurerm_storage_account" "sa" { name = var.storage_account_name resource_group_name = var.resource_group_name @@ -6,8 +7,18 @@ resource "azurerm_storage_account" "sa" { account_replication_type = "LRS" } +# Creates the storage container for application artifacts. resource "azurerm_storage_container" "sc" { name = var.storage_container_name storage_account_name = azurerm_storage_account.sa.name container_access_type = "blob" -} \ No newline at end of file +} + +# Uploads the application installation script to the blob container. +resource "azurerm_storage_blob" "app_script" { + name = "install-app.sh" + storage_account_name = azurerm_storage_account.sa.name + storage_container_name = azurerm_storage_container.sc.name + type = "Block" + source = "${path.root}/install-app.sh" +} From e7e740433b0f23961a61b17790230bb424e47d95 Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:33:28 +0300 Subject: [PATCH 10/17] Update outputs.tf 2 --- modules/storage/outputs.tf | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/storage/outputs.tf b/modules/storage/outputs.tf index 2dcda4b..dcd67a1 100644 --- a/modules/storage/outputs.tf +++ b/modules/storage/outputs.tf @@ -1,8 +1,17 @@ +# The name of the Storage Account. output "storage_account_name" { - description = "The name of the Storage Account for application artifacts" + description = "The name of the Storage Account for application artifacts." value = azurerm_storage_account.sa.name } + +# The name of the Storage Container. output "storage_container_name" { - description = "The name of the Storage Container for application artifacts" + description = "The name of the Storage Container for application artifacts." value = azurerm_storage_container.sc.name -} \ No newline at end of file +} + +# The URL of the installation script in the blob storage. +output "script_url" { + description = "The URL of the installation script for the VM extension." + value = azurerm_storage_blob.app_script.url +} From 21c60d7b8d164b16ae65ec5d46fe69a0b449cbbc Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:35:06 +0300 Subject: [PATCH 11/17] Update variables.tf 2 --- modules/compute/variables.tf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/compute/variables.tf b/modules/compute/variables.tf index 4e909e0..25cb063 100644 --- a/modules/compute/variables.tf +++ b/modules/compute/variables.tf @@ -34,6 +34,12 @@ variable "public_ip_id" { type = string } +# Added variable for the Network Security Group ID. +variable "nsg_id" { + description = "ID of the Network Security Group to associate with the NIC" + type = string +} + variable "script_url" { description = "URL of the script to execute on the VM" type = string From bc725f912ef0eac14b7c4fee0d59c7b0789dfd16 Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:36:07 +0300 Subject: [PATCH 12/17] Update main.tf 2 --- modules/compute/main.tf | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/compute/main.tf b/modules/compute/main.tf index e78439e..071ffba 100644 --- a/modules/compute/main.tf +++ b/modules/compute/main.tf @@ -1,3 +1,4 @@ +# Creates the Network Interface for the VM and associates the NSG. resource "azurerm_network_interface" "main" { name = "${var.vm_name}-nic" location = var.location @@ -11,6 +12,21 @@ resource "azurerm_network_interface" "main" { } } +# Associates the Network Security Group with the Network Interface. +resource "azurerm_network_interface_security_group_association" "main" { + network_interface_id = azurerm_network_interface.main.id + network_security_group_id = var.nsg_id +} + +# Creates the SSH public key resource as required by the task. +resource "azurerm_ssh_public_key" "main" { + name = "linuxboxsshkey" + resource_group_name = var.resource_group_name + location = var.location + public_key = var.ssh_key_public +} + +# Creates the Linux Virtual Machine. resource "azurerm_linux_virtual_machine" "main" { name = var.vm_name resource_group_name = var.resource_group_name @@ -21,7 +37,7 @@ resource "azurerm_linux_virtual_machine" "main" { admin_ssh_key { username = "adminuser" - public_key = var.ssh_key_public + public_key = azurerm_ssh_public_key.main.public_key } os_disk { @@ -37,6 +53,7 @@ resource "azurerm_linux_virtual_machine" "main" { } } +# Creates the VM extension to download and execute the installation script. resource "azurerm_virtual_machine_extension" "main" { name = "${var.vm_name}-install-app" virtual_machine_id = azurerm_linux_virtual_machine.main.id @@ -45,8 +62,9 @@ resource "azurerm_virtual_machine_extension" "main" { type_handler_version = "2.0" settings = < Date: Sun, 12 Oct 2025 19:36:58 +0300 Subject: [PATCH 13/17] Update outputs.tf 2 --- modules/compute/outputs.tf | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/compute/outputs.tf b/modules/compute/outputs.tf index cddda21..fa5e7c5 100644 --- a/modules/compute/outputs.tf +++ b/modules/compute/outputs.tf @@ -3,7 +3,20 @@ output "vm_id" { description = "The ID of the virtual machine." } +# Corrected the value to get the private IP from the IP configuration. output "vm_private_ip" { - value = azurerm_network_interface.main.private_ip_address + value = azurerm_network_interface.main.ip_configuration[0].private_ip_address description = "The private IP address of the virtual machine." -} \ No newline at end of file +} + +# Added public IP output for easier verification. +output "vm_public_ip" { + value = azurerm_network_interface.main.ip_configuration[0].public_ip_address_id != null ? data.azurerm_public_ip.vm_pip.ip_address : "" + description = "The public IP address of the virtual machine." +} + +data "azurerm_public_ip" "vm_pip" { + name = split("/", azurerm_network_interface.main.ip_configuration[0].public_ip_address_id)[8] + resource_group_name = var.resource_group_name + depends_on = [azurerm_linux_virtual_machine.main] +} From d9feb96db00028dfd4ba3498bee317860d9e97a7 Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:38:20 +0300 Subject: [PATCH 14/17] Update main.tf 2 --- main.tf | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/main.tf b/main.tf index fd5cf6a..d58a442 100644 --- a/main.tf +++ b/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { azurerm = { source = "hashicorp/azurerm" - version = ">= 3.0.0" + version = "~>3.0" } } } @@ -17,28 +17,31 @@ resource "azurerm_resource_group" "rg" { } module "network" { - source = "./modules/network" + source = "./modules/network" + resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location virtual_network_name = var.virtual_network_name - vnet_address_prefix = var.vnet_address_prefix + vnet_address_prefix = [var.vnet_address_prefix] subnet_name = var.subnet_name - subnet_address_prefix = var.subnet_address_prefix + subnet_address_prefix = [var.subnet_address_prefix] network_security_group_name = var.network_security_group_name public_ip_address_name = var.public_ip_address_name dns_label = var.dns_label } module "storage" { - source = "./modules/storage" - resource_group_name = azurerm_resource_group.rg.name - location = azurerm_resource_group.rg.location - storage_account_name = var.storage_account_name_app_artifacts - storage_container_name = var.storage_container_name_app_artifacts + source = "./modules/storage" + + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + storage_account_name = var.storage_account_name + storage_container_name = var.storage_container_name } module "compute" { - source = "./modules/compute" + source = "./modules/compute" + resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location vm_name = var.vm_name @@ -46,6 +49,6 @@ module "compute" { ssh_key_public = var.ssh_key_public subnet_id = module.network.subnet_id public_ip_id = module.network.public_ip_id - script_url = module.storage.script_url nsg_id = module.network.nsg_id + script_url = module.storage.script_url } From 366f3cafd438caf181901db648d70312b3084e81 Mon Sep 17 00:00:00 2001 From: Leonid Lachmann <148564629+leoleiden@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:40:19 +0300 Subject: [PATCH 15/17] Delete files.txt --- files.txt | 107 ------------------------------------------------------ 1 file changed, 107 deletions(-) delete mode 100644 files.txt diff --git a/files.txt b/files.txt deleted file mode 100644 index 0a7e4ef..0000000 --- a/files.txt +++ /dev/null @@ -1,107 +0,0 @@ - ⮬ Windows 10 -਩ ⮬: 000000D6 2450:3723 -C:\USERS\LEIDENLOKI\DEVOPS_TODOLIST_TERRAFORM_TASK - files.txt - image.png - install-app.sh - README.md - -.github - workflows - terraform-validate.yml - -app - .gitignore - LICENSE - manage.py - README.md - requirements.txt - start.sh - todoapp.service - - accounts - admin.py - forms.py - models.py - tests.py - urls.py - views.py - __init__.py - - migrations - __init__.py - - templates - accounts - login.html - register.html - - api - serializers.py - tests.py - urls.py - views.py - __init__.py - - migrations - __init__.py - - lists - admin.py - forms.py - models.py - tests.py - urls.py - views.py - __init__.py - - migrations - 0001_initial.py - __init__.py - - static - lists - css - table.css - - images - asc.gif - bg.gif - desc.gif - - js - jquery.tablesorter.min.js - lists.js - - templates - lists - index.html - overview.html - todolist.html - - templatetags - lists_extras.py - __init__.py - - todolist - settings.py - urls.py - wsgi.py - __init__.py - - static - css - custom.css - - images - favicon.png - - js - site.js - - templates - 403.html - 404.html - 500.html - base.html - From 05264d85ea80bdd1d9a32f4575ee0525369c5e06 Mon Sep 17 00:00:00 2001 From: Leonid Lachmann Date: Mon, 25 May 2026 17:34:38 +0300 Subject: [PATCH 16/17] terraform reborn --- .gitignore | 7 ++++++ .terraform.lock.hcl | 43 ++++++++++++++++++++++++++++++++ backend.tf | 4 +-- main.tf | 40 ++++++++++++++++++++++++------ outputs.tf | 6 +++-- terraform.tfvars | 31 ++++++++++++++++++++--- variables.tf | 60 +++++++++++++++++++++++++++++++++------------ 7 files changed, 161 insertions(+), 30 deletions(-) create mode 100644 .gitignore create mode 100644 .terraform.lock.hcl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..226e0fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.terraform/ +*.tfstate +*.tfstate.* +terraform.tfvars +override.tf +override.tf.json +crash.log diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..87dcccd --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,43 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/azurerm" { + version = "3.117.1" + constraints = "~> 3.75" + hashes = [ + "h1:Y9J+emydHX7LpJYKdF9Zmng0zcRR86Awm/t28LNzb68=", + "zh:0c513676836e3c50d004ece7d2624a8aff6faac14b833b96feeac2e4bc2c1c12", + "zh:50ea01ada95bae2f187db9e926e463f45d860767a85ebc59160414e00e76c35d", + "zh:52c2a9edacc06b3f72153f5ef6daca0761c6292158815961fe37f60bc576a3d7", + "zh:618eed2a06b19b1a025b45b05891846d570a6a1cca4d23f4942f5a99e1f747ae", + "zh:61cde5d3165d7e5ec311d5d89486819cd605c1b2d54611b5c97bd4e97dba2762", + "zh:6a873358d5031fc222f5e05f029d1237f3dce8345c767665f393283dfa2627f6", + "zh:afdd80064b2a04da311856feb4ed45f77ff4df6c356e8c2b10afb51fe7e61c70", + "zh:b09113df7e0e8c8959539bd22bae6c39faeb269ba3c4cd948e742f5cf58c35fb", + "zh:d340db7973109761cfc27d52aa02560363337c908b2c99b3628adc5a70a99d5b", + "zh:d5a577226ebc8c65e8f19384878a86acc4b51ede4b4a82d37c3b331b0efcd4a7", + "zh:e2962b147f9e71732df8dbc74940c10d20906f3c003cbfaa1eb9fabbf601a9f0", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + ] +} + +provider "registry.terraform.io/hashicorp/random" { + version = "3.9.0" + constraints = "~> 3.5" + hashes = [ + "h1:q/uaUTBdKgAmZESrwsoeDQff9uUA/cI/N5ZKNgVwa9c=", + "zh:161ad0bd9a75768c82f53fb6e7172a9d8be2d4889b012645a34795031aaf1bf1", + "zh:19dc9a5b17729725ccfc4f45b0500af0ee5bc6b6b160c7adb8f2bf617d2c80ea", + "zh:269eda8fe42daa7974d5a34d166c3ba9defe80cde86c01e4dadcfdf2e1f05e5f", + "zh:373f7c65566f8f2cc7f45d698654feb9d988996957e1266a69ca00c52d6d16d0", + "zh:5599d16804c41c83009ec621b6d6b6f74e102f5827678a4750f8809055546b61", + "zh:583be0440469a22bff70dcfa56593b01566860b29607437264adb51060cf46fc", + "zh:5f211d8ec3f2e1f414870d9584bfe26e6995560ef81c748f8447a48164767398", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:7b547fd16216761ef86efc3ed516ac5ac0c5c42b7c7eb24a08cef2d93f69ed5e", + "zh:7e7c0679daf2a382151d05068c8c3f0dae6b7b7dccf818827b73dd08638df2ef", + "zh:8089dec888a8038b9b4fb23b3df7e1057293dbc5b60b42cc47ff690d69d4b61b", + "zh:c51f15a031edfd6f23ce8ced3446ca7f8d8d647e2499890d7d5d10d5016d7257", + "zh:c94784f005708890dc6895afd53636ec00ec1e430b15d41e5aebfb1d4b39bd04", + ] +} diff --git a/backend.tf b/backend.tf index 1d054c3..877984e 100644 --- a/backend.tf +++ b/backend.tf @@ -1,7 +1,7 @@ terraform { backend "azurerm" { - resource_group_name = "mate-azure-task-12" - storage_account_name = "yourstorageaccount" + resource_group_name = "tfstate" + storage_account_name = "terra5" container_name = "tfstate" key = "terraform.tfstate" } diff --git a/main.tf b/main.tf index d58a442..01b724c 100644 --- a/main.tf +++ b/main.tf @@ -1,19 +1,45 @@ terraform { + required_version = ">= 1.5.0, < 2.0.0" + required_providers { azurerm = { source = "hashicorp/azurerm" - version = "~>3.0" + version = "~> 3.75" + } + random = { + source = "hashicorp/random" + version = "~> 3.5" } } } provider "azurerm" { features {} + subscription_id = var.subscription_id +} + +resource "random_integer" "dns_suffix" { + min = 1000 + max = 9999 +} + +locals { + dns_label = "${var.dns_label}${random_integer.dns_suffix.result}" + + common_tags = merge( + { + environment = var.environment + project = var.resource_group_name + managed_by = "terraform" + }, + var.tags + ) } resource "azurerm_resource_group" "rg" { name = var.resource_group_name location = var.location + tags = local.common_tags } module "network" { @@ -22,12 +48,12 @@ module "network" { resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location virtual_network_name = var.virtual_network_name - vnet_address_prefix = [var.vnet_address_prefix] + vnet_address_prefix = var.vnet_address_prefix # fixed: was [var.vnet_address_prefix] subnet_name = var.subnet_name - subnet_address_prefix = [var.subnet_address_prefix] + subnet_address_prefix = var.subnet_address_prefix # fixed: was [var.subnet_address_prefix] network_security_group_name = var.network_security_group_name public_ip_address_name = var.public_ip_address_name - dns_label = var.dns_label + dns_label = local.dns_label # fixed: now globally unique } module "storage" { @@ -35,8 +61,8 @@ module "storage" { resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location - storage_account_name = var.storage_account_name - storage_container_name = var.storage_container_name + storage_account_name = var.storage_account_name # fixed: matched to variable name below + storage_container_name = var.storage_container_name # fixed: matched to variable name below } module "compute" { @@ -51,4 +77,4 @@ module "compute" { public_ip_id = module.network.public_ip_id nsg_id = module.network.nsg_id script_url = module.storage.script_url -} +} \ No newline at end of file diff --git a/outputs.tf b/outputs.tf index d9f1c35..5e14bb3 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,7 +1,9 @@ output "public_ip_address" { - value = module.network.public_ip_address + description = "The public IP address assigned to the virtual machine" + value = module.network.public_ip_address } output "public_ip_fqdn" { - value = module.network.public_ip_fqdn + description = "The fully qualified domain name (FQDN) of the public IP address" + value = module.network.public_ip_fqdn } \ No newline at end of file diff --git a/terraform.tfvars b/terraform.tfvars index 2f647d9..8c27d5e 100644 --- a/terraform.tfvars +++ b/terraform.tfvars @@ -1,3 +1,28 @@ -location = "uksouth" -resource_group_name = "mate-azure-task-12" -ssh_key_public = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCnTufDrlK40pNPp2Qho8Z7aixGNbV7q1hkfJzIUcQiYsr5eN1Utc/zx1E6IPDyHi+t4E5GKDm88yU8FbeDL3ShAULkB4/UvQzmTho2DjHRBEfAo9Z/pPkv0HJYtlgdol0aCwo30vWr/dRtq6Ir2Iw5hAZcAe3hKg2Qq9VfjBjiOTl434ONar0wajnApA550nuWEKU/vvQEBdP8Lx+vulteTGmvP9JWV4ZhWQVJkArYi0wvRX1UEoEj/P/eXNQl+h7BwxGRa3OyUaU7yCRE0QKba0mesAwSBdncs+tFqoNQD7JiCR7QnSzKoQ7MJQg/945d86UijPisT9IGGDyyB9kZrEUR/ePrCuH+xhFXuOdHectdH3xzui00zhdoiov6XfTYMrzoOF1+aJJFMI42yySGV5lWknfvIfAAr/1j6/1HPAIX/FDnlUPRRuMMLWHUAguW/oqXIRKzpR6h4/YVCe/cToHpPIkd3jZpCNADKXkp4Eoef78lOn1S71gVjzk1LOk=" \ No newline at end of file +subscription_id = "b1e27144-9a08-4722-8311-9fce7db53f60" # ← your Azure Subscription ID + +location = "uksouth" +resource_group_name = "mate-azure-task-12" +environment = "dev" + +# Network +virtual_network_name = "vnet" +vnet_address_prefix = ["10.0.0.0/16"] +subnet_name = "default" +subnet_address_prefix = ["10.0.0.0/24"] +network_security_group_name = "defaultnsg" +public_ip_address_name = "linuxboxpip" +dns_label = "matetask" + +# Compute +vm_name = "matebox" +vm_size = "Standard_B1s" +ssh_key_public = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCnTufDrlK40pNPp2Qho8Z7aixGNbV7q1hkfJzIUcQiYsr5eN1Utc/zx1E6IPDyHi+t4E5GKDm88yU8FbeDL3ShAULkB4/UvQzmTho2DjHRBEfAo9Z/pPkv0HJYtlgdol0aCwo30vWr/dRtq6Ir2Iw5hAZcAe3hKg2Qq9VfjBjiOTl434ONar0wajnApA550nuWEKU/vvQEBdP8Lx+vulteTGmvP9JWV4ZhWQVJkArYi0wvRX1UEoEj/P/eXNQl+h7BwxGRa3OyUaU7yCRE0QKba0mesAwSBdncs+tFqoNQD7JiCR7QnSzKoQ7MJQg/945d86UijPisT9IGGDyyB9kZrEUR/ePrCuH+xhFXuOdHectdH3xzui00zhdoiov6XfTYMrzoOF1+aJJFMI42yySGV5lWknfvIfAAr/1j6/1HPAIX/FDnlUPRRuMMLWHUAguW/oqXIRKzpR6h4/YVCe/cToHpPIkd3jZpCNADKXkp4Eoef78lOn1S71gVjzk1LOk=" # ← replace + +# Storage +storage_account_name = "matetaskappstorage" +storage_container_name = "task-artifacts" + +# Tags +tags = { + owner = "your-name" +} \ No newline at end of file diff --git a/variables.tf b/variables.tf index 97cbd5a..19588cc 100644 --- a/variables.tf +++ b/variables.tf @@ -1,78 +1,106 @@ -# variables.tf (кореневий) +variable "subscription_id" { + description = "Azure Subscription ID to deploy resources into" + type = string +} + variable "location" { description = "Azure region for all resources" type = string default = "uksouth" } +variable "environment" { + description = "Deployment environment label (e.g. dev, staging, prod)" + type = string + default = "dev" +} + variable "resource_group_name" { description = "Name of the main resource group" type = string default = "mate-azure-task-12" } -# Network Module Variables +variable "tags" { + description = "Additional tags to merge onto all resources" + type = map(string) + default = {} +} + +# ── Network ────────────────────────────────────────────────────────────────── + variable "virtual_network_name" { description = "Name of the Virtual Network" type = string default = "vnet" } + variable "vnet_address_prefix" { - description = "Address prefix for the Virtual Network" + description = "Address prefix(es) for the Virtual Network" type = list(string) default = ["10.0.0.0/16"] } + variable "subnet_name" { description = "Name of the Subnet" type = string default = "default" } + variable "subnet_address_prefix" { - description = "Address prefix for the Subnet" + description = "Address prefix(es) for the Subnet" type = list(string) default = ["10.0.0.0/24"] } + variable "network_security_group_name" { description = "Name of the Network Security Group" type = string default = "defaultnsg" } + variable "public_ip_address_name" { - description = "Name of the Public IP Address" + description = "Name of the Public IP Address resource" type = string default = "linuxboxpip" } + variable "dns_label" { - description = "DNS label for the Public IP Address" + description = "Base DNS label for the Public IP (a random 4-digit suffix is appended automatically to ensure global uniqueness)" type = string default = "matetask" } -# Compute Module Variables +# ── Compute ─────────────────────────────────────────────────────────────────── + variable "vm_name" { description = "Name of the Virtual Machine" type = string default = "matebox" } + variable "vm_size" { - description = "Size of the Virtual Machine" + description = "SKU size of the Virtual Machine" type = string default = "Standard_B1s" } + variable "ssh_key_public" { description = "Public SSH key content for VM access" type = string - sensitive = true # Позначаємо як чутливу інформацію + sensitive = true } -# Storage Module Variables for Application Artifacts -variable "storage_account_name_app_artifacts" { - description = "Name of the storage account for application artifacts" +# ── Storage ─────────────────────────────────────────────────────────────────── + +variable "storage_account_name" { + description = "Name of the storage account for application artifacts (globally unique, 3–24 chars, lowercase alphanumeric only)" type = string - default = "matetaskappstorage" # Унікальне ім'я + default = "matetaskappstorage" } -variable "storage_container_name_app_artifacts" { - description = "Name of the storage container for application artifacts" + +variable "storage_container_name" { + description = "Name of the blob container for application artifacts" type = string default = "task-artifacts" -} +} \ No newline at end of file From 0a38aeb63708de123e0e9ae267335bbbf17ef01f Mon Sep 17 00:00:00 2001 From: Leonid Lachmann Date: Mon, 25 May 2026 18:00:28 +0300 Subject: [PATCH 17/17] terraform reborn azureuser --- modules/compute/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/compute/main.tf b/modules/compute/main.tf index 071ffba..da9cc93 100644 --- a/modules/compute/main.tf +++ b/modules/compute/main.tf @@ -32,11 +32,11 @@ resource "azurerm_linux_virtual_machine" "main" { resource_group_name = var.resource_group_name location = var.location size = var.vm_size - admin_username = "adminuser" + admin_username = "azureuser" network_interface_ids = [azurerm_network_interface.main.id] admin_ssh_key { - username = "adminuser" + username = "azureuser" public_key = azurerm_ssh_public_key.main.public_key }