Skip to content

Instantly share code, notes, and snippets.

@imartinflores
Created June 30, 2023 14:32
Show Gist options
  • Save imartinflores/4ad906e876633b7f49155ec42febacd3 to your computer and use it in GitHub Desktop.
Save imartinflores/4ad906e876633b7f49155ec42febacd3 to your computer and use it in GitHub Desktop.
Virtual Networs
resource "azurerm_network_interface" "networkinterfacename" {
 name = "${var.resource_group_name}-department-nic"
 location = var.vm_location
 resource_group_name = var.resource_group_name
 ip_configuration {
 name = "${var.resource_group_name}-department-IpConfig"
 subnet_id = azurerm_subnet.subnetname.id
 private_ip_address_allocation = "Dynamic"
 }
}
resource "azurerm_network_security_group" "securitygroupname" {
 name = "${var.resource_group_name}-department-SecurityGroup"
 location = var.vm_location
 resource_group_name = var.resource_group_name
}
resource "azurerm_network_security_rule" "securityrulename" {
 for_each = local.secrules 
 name = each.key
 direction = each.value.direction
 access = each.value.access
 priority = each.value.priority
 protocol = each.value.protocol
 source_port_range = each.value.source_port_range
 destination_port_range = each.value.destination_port_range
 source_address_prefix = each.value.source_address_prefix
 destination_address_prefix = each.value.destination_address_prefix
 resource_group_name = var.resource_group_name
 network_security_group_name = azurerm_network_security_group.securitygroup.name
}
resource "azurerm_subnet" "subnetname" {
 name = "${var.resource_group_name}-deparment-subnet"
 resource_group_name = var.resource_group_name
 virtual_network_name = azurerm_virtual_network.qanetwork.name
 address_prefixes = ["addressprefix/port"]
}
resource "azurerm_linux_virtual_machine" "yourvmname" {
 name = var.azurerm_linux_virtual_machine_name
 location = var.vm_location
 resource_group_name = var.resource_group_name
 network_interface_ids = [azurerm_network_interface.qanic.id]
 size = "Standard_D2s_v3"
 os_disk {
 name = "diskname"
 caching = "ReadWrite"
 storage_account_type = "Premium_LRS"
 }
 source_image_reference {
 publisher = "Canonical"
 offer = "0001-com-ubuntu-server-focal"
 sku = "20_04-lts-gen2"
 version = "latest"
 }
 computer_name = var.azure_linux_vm_pcname
 admin_username = var.azure_user_admin
 admin_password = encryptedpassword
 boot_diagnostics {
 storage_account_uri = azurerm_storage_account.storageaccountname.primary_blob_endpoint
 }
tags = { environment = "yourenvironment" }
}
resource "azurerm_virtual_machine_extension" "vmExtension" {
 name = "hostname"
 virtual_machine_id = azurerm_linux_virtual_machine.yourvmname.id
 publisher = "Microsoft.Azure.Extensions"
 type = "CustomScript"
 type_handler_version = "2.0"
 settings = <<SETTINGS
 {
 "commandToExecute": "curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh"
 }
SETTINGS
}
resource "azurerm_virtual_network" "networkname" {
 name = "${var.resource_group_name}-deparment-vnet"
 address_space = ["addressspace/port"]
 location = var.vm_location
 resource_group_name = var.resource_group_name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment