Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Select, configure, and scale Azure compute resources—VMs, App Service, AKS, and Container Apps
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
workflows/vm-creator/examples/terraform/main.tf
1terraform {2required_providers {3azurerm = {4source = "hashicorp/azurerm"5version = "~> 4.0"6}7}8}910provider "azurerm" {11features {}12subscription_id = var.subscription_id13}1415resource "azurerm_resource_group" "main" {16name = var.resource_group_name17location = var.location18tags = var.tags19}2021resource "azurerm_network_security_group" "main" {22name = "${var.vm_name}-nsg"23location = azurerm_resource_group.main.location24resource_group_name = azurerm_resource_group.main.name25tags = var.tags2627security_rule {28name = "AllowSSH"29priority = 100030direction = "Inbound"31access = "Allow"32protocol = "Tcp"33source_port_range = "*"34destination_port_range = "22"35source_address_prefix = var.ssh_source_address_prefix36destination_address_prefix = "*"37}38}3940resource "azurerm_virtual_network" "main" {41name = "${var.vm_name}-vnet"42address_space = ["10.0.0.0/16"]43location = azurerm_resource_group.main.location44resource_group_name = azurerm_resource_group.main.name45tags = var.tags46}4748resource "azurerm_subnet" "main" {49name = "default"50resource_group_name = azurerm_resource_group.main.name51virtual_network_name = azurerm_virtual_network.main.name52address_prefixes = ["10.0.0.0/24"]53}5455resource "azurerm_subnet_network_security_group_association" "main" {56subnet_id = azurerm_subnet.main.id57network_security_group_id = azurerm_network_security_group.main.id58}5960resource "azurerm_public_ip" "main" {61name = "${var.vm_name}-ip"62location = azurerm_resource_group.main.location63resource_group_name = azurerm_resource_group.main.name64allocation_method = "Static"65sku = "Standard"66tags = var.tags67}6869resource "azurerm_network_interface" "main" {70name = "${var.vm_name}-nic"71location = azurerm_resource_group.main.location72resource_group_name = azurerm_resource_group.main.name73tags = var.tags7475ip_configuration {76name = "ipconfig1"77subnet_id = azurerm_subnet.main.id78private_ip_address_allocation = "Dynamic"79public_ip_address_id = azurerm_public_ip.main.id80}81}8283resource "azurerm_linux_virtual_machine" "main" {84name = var.vm_name85location = azurerm_resource_group.main.location86resource_group_name = azurerm_resource_group.main.name87size = var.size88admin_username = var.admin_username89network_interface_ids = [azurerm_network_interface.main.id]90zone = var.zone == "" ? null : var.zone91tags = var.tags9293admin_ssh_key {94username = var.admin_username95public_key = var.admin_public_key96}9798os_disk {99caching = "ReadWrite"100storage_account_type = var.os_disk_type101disk_size_gb = var.os_disk_size_gb102}103104source_image_reference {105publisher = "Canonical"106offer = "ubuntu-24_04-lts"107sku = "server"108version = "latest"109}110}111