117 lines
3.1 KiB
HCL
117 lines
3.1 KiB
HCL
terraform {
|
|
required_providers {
|
|
azurerm = {
|
|
source = "hashicorp/azurerm"
|
|
version = "~> 4.0"
|
|
}
|
|
}
|
|
}
|
|
|
|
provider "azurerm" {
|
|
features {}
|
|
subscription_id = var.simpl_subscription_id
|
|
}
|
|
|
|
variable "simpl_subscription_id" {
|
|
type = string
|
|
}
|
|
|
|
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_ssh_public_key" {
|
|
type = string
|
|
}
|
|
|
|
variable "simpl_cloud_init" {
|
|
type = string
|
|
}
|
|
|
|
locals {
|
|
image_parts = split(":", Canonical:UbuntuServer:22_04-lts:latest_urn)
|
|
}
|
|
|
|
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 = var.simpl_vm_size
|
|
admin_username = "simpluser"
|
|
|
|
network_interface_ids = [azurerm_network_interface.simpl_nic.id]
|
|
|
|
admin_ssh_key {
|
|
username = "simpluser"
|
|
public_key = var.simpl_ssh_public_key
|
|
}
|
|
|
|
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 = base64encode(var.simpl_cloud_init)
|
|
}
|
|
|
|
output "vmIps" {
|
|
depends_on = [azurerm_linux_virtual_machine.simpl_vm]
|
|
value = [azurerm_public_ip.simpl_pip.ip_address]
|
|
}
|