diff --git a/backend.tf b/backend.tf new file mode 100644 index 0000000..2e952a8 --- /dev/null +++ b/backend.tf @@ -0,0 +1,8 @@ +terraform { + backend "azurerm" { + resource_group_name = "mate-azure-task-12" + storage_account_name = "tfstate144" + container_name = "tfstate" + key = "terraform.tfstate" + } +} diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..a84561b --- /dev/null +++ b/main.tf @@ -0,0 +1,42 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "3.105.0" + } + } +} + +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "main" { + name = "todolist-terraform-task" + location = "West Europe" +} + +module "network" { + source = "./modules/network" + resource_group_name = azurerm_resource_group.main.name + location = azurerm_resource_group.main.location + dns_label_prefix = var.dns_label +} + +module "compute" { + source = "./modules/compute" + location = azurerm_resource_group.main.location + resource_group_name = azurerm_resource_group.main.name + vm_name = var.vm_name + + subnet_id = module.network.subnet_id + public_ip_id = module.network.public_ip_address + ssh_key = var.ssh_key +} + +module "storage" { + source = "./modules/storage" + resource_group_name = azurerm_resource_group.main.name + location = azurerm_resource_group.main.location + storage_account_name = var.storage_account_name +} diff --git a/modules/compute/main.tf b/modules/compute/main.tf new file mode 100644 index 0000000..1cec084 --- /dev/null +++ b/modules/compute/main.tf @@ -0,0 +1,66 @@ +resource "azurerm_public_ip" "linuxboxpip" { + name = "linuxboxpip" + location = var.location + resource_group_name = var.resource_group_name + allocation_method = "Static" +} + +resource "azurerm_network_interface" "vm-nic" { + 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 = azurerm_public_ip.linuxboxpip.id + } +} + +resource "azurerm_linux_virtual_machine" "matebox" { + name = "matebox" + resource_group_name = var.resource_group_name + location = var.location + size = "Standard_B1s" + admin_username = "adminuser" + network_interface_ids = [ + azurerm_network_interface.vm-nic.id, + ] + + admin_ssh_key { + username = "adminuser" + public_key = var.ssh_key + } + + 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" "CustomScript" { + name = "CustomScript" + virtual_machine_id = azurerm_linux_virtual_machine.matebox.id + publisher = "Microsoft.Azure.Extensions" + type = "CustomScript" + type_handler_version = "2.0" + + settings = <