terraform { required_providers { azurerm = { source = "hashicorp/azurerm", version = "~>3.0" } } } provider "azurerm" { features {} } resource "azurerm_resource_group" "rg" { name = var.rg_name location = var.location } # (Marketplace terms must be accepted via Azure CLI once before applying) resource "azurerm_virtual_network" "vnet" { name = "${var.rg_name}-vnet" location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name address_space = ["10.1.0.0/16"] } resource "azurerm_subnet" "subnet" { name = "default" resource_group_name = azurerm_resource_group.rg.name virtual_network_name = azurerm_virtual_network.vnet.name address_prefixes = ["10.1.1.0/24"] } resource "azurerm_network_security_group" "nsg" { name = "${var.rg_name}-nsg" location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name } resource "azurerm_network_security_rule" "ssh" { name = "Allow-SSH" priority = 100 direction = "Inbound" access = "Allow" protocol = "Tcp" source_port_range = "*" destination_port_range = "22" source_address_prefix = "*" destination_address_prefix = "*" resource_group_name = azurerm_resource_group.rg.name network_security_group_name = azurerm_network_security_group.nsg.name } resource "azurerm_network_security_rule" "gitea" { name = "Allow-Gitea-HTTP" priority = 110 direction = "Inbound" access = "Allow" protocol = "Tcp" source_port_range = "*" destination_port_range = "3000" source_address_prefix = "*" destination_address_prefix = "*" resource_group_name = azurerm_resource_group.rg.name network_security_group_name = azurerm_network_security_group.nsg.name } resource "azurerm_public_ip" "pip" { name = "${var.rg_name}-pip" location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name allocation_method = "Static" sku = "Standard" } resource "azurerm_network_interface" "nic" { name = "${var.rg_name}-nic" location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name ip_configuration { name = "nic-ipconfig" subnet_id = azurerm_subnet.subnet.id private_ip_address_allocation = "Dynamic" public_ip_address_id = azurerm_public_ip.pip.id } } # Attach NSG to this specific NIC: resource "azurerm_network_interface_security_group_association" "nic_nsg" { network_interface_id = azurerm_network_interface.nic.id network_security_group_id = azurerm_network_security_group.nsg.id } /*resource "azurerm_marketplace_agreement" "gitea_terms" { publisher = "bitnami" offer = "gitea" plan = "default" }*/ resource "azurerm_linux_virtual_machine" "gitea" { name = var.vm_name location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name size = var.vm_size admin_username = var.admin_user network_interface_ids = [azurerm_network_interface.nic.id] disable_password_authentication = true source_image_reference { publisher = "bitnami" offer = "gitea" sku = "default" version = "1.24.2114171813" } plan { name = "default" publisher = "bitnami" product = "gitea" } admin_ssh_key { username = var.admin_user public_key = file(var.ssh_pub_key_path) } os_disk { caching = "ReadWrite" storage_account_type = "Premium_LRS" } }