diff --git a/Azure_VM_Small_20260416_124004.TF b/Azure_VM_Small_20260416_124004.TF new file mode 100644 index 0000000..405157c --- /dev/null +++ b/Azure_VM_Small_20260416_124004.TF @@ -0,0 +1,109 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 4.0" + } + } +} + +provider "azurerm" { + features {} +} + +variable "simpl_resource_group" { + type = string + description = "Name of the pre-existing Azure Resource Group" +} + +variable "simpl_vm_size" { + type = string +} + +variable "simpl_image_urn" { + type = string + description = "Format: Publisher:Offer:SKU:Version (e.g. Canonical:UbuntuServer:22_04-lts:latest)" +} + +variable "simpl_admin_password" { + type = string + sensitive = true +} + +variable "simpl_cloud_init" { + type = string +} + +locals { + image_parts = split(":", "Canonical:UbuntuServer:22_04-lts:latest") +} + +data "azurerm_resource_group" "simpl_rg" { + name = "espacios-de-datos-infraestructura" +} + +resource "azurerm_virtual_network" "simpl_vnet" { + name = "simpl-vnet-{UUID}" + address_space = ["10.0.0.0/16"] + location = data.azurerm_resource_group.simpl_rg.location + resource_group_name = data.azurerm_resource_group.simpl_rg.name +} + +resource "azurerm_subnet" "simpl_subnet" { + name = "simpl-subnet-{UUID}" + resource_group_name = data.azurerm_resource_group.simpl_rg.name + virtual_network_name = azurerm_virtual_network.simpl_vnet.name + address_prefixes = ["10.0.1.0/24"] +} + +resource "azurerm_public_ip" "simpl_pip" { + name = "simpl-pip-{UUID}" + location = data.azurerm_resource_group.simpl_rg.location + resource_group_name = data.azurerm_resource_group.simpl_rg.name + allocation_method = "Static" + sku = "Standard" +} + +resource "azurerm_network_interface" "simpl_nic" { + name = "simpl-nic-{UUID}" + location = data.azurerm_resource_group.simpl_rg.location + resource_group_name = data.azurerm_resource_group.simpl_rg.name + + ip_configuration { + name = "internal" + subnet_id = azurerm_subnet.simpl_subnet.id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = azurerm_public_ip.simpl_pip.id + } +} + +resource "azurerm_linux_virtual_machine" "simpl_vm" { + name = "offering-enterprise-server-{UUID}-terraform" + resource_group_name = data.azurerm_resource_group.simpl_rg.name + location = data.azurerm_resource_group.simpl_rg.location + size = "Standard_B2s" + admin_username = "simpluser" + admin_password = "var.simpl_admin_password" + disable_password_authentication = false + + network_interface_ids = [azurerm_network_interface.simpl_nic.id] + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = local.image_parts[0] + offer = local.image_parts[1] + sku = local.image_parts[2] + version = local.image_parts[3] + } + + custom_data = "var.simpl_cloud_init" +} + +output "vmIps" { + depends_on = [azurerm_linux_virtual_machine.simpl_vm] + value = [azurerm_public_ip.simpl_pip.ip_address] +}