skip to Main Content

I have just started coding in Terraform and doing the basics. Every code that I find in any repo asks comes with deploying a VM in Azure with LoadBalance, Availability Set and Storage to enable Boot Diagnostic.

Is there any simple syntax to disabled them ?

I tried to add "disabled" in front of those resource but that didnt work.

2

Answers


  1. try using the following code:

    ## Public_IP - VM1 NIC
        resource "azurerm_public_ip" "public_VM1" {
        name                = "public_VM1"
        resource_group_name = 
        location            = 
        allocation_method   = "Static"
    
        tags = {
        environment = "Migration-Lab"
        }
       }
    
    
    
    
    ## NIC VM1
       resource "azurerm_network_interface" "VM1" {
       name                = "VM1"
      location            = 
      resource_group_name = 
    
      ip_configuration {
        name                          = "VM1"
        subnet_id                     = 
        private_ip_address_allocation = "Dynamic"
        public_ip_address_id          = 
      }
    }
    
    ## Create a Linux VM1 in VNET1
    resource "azurerm_linux_virtual_machine" "LinuxVM1" {
      name                = "LinuxVM1"
      resource_group_name = 
      location            = 
      size                = "Standard_B1ms"
      admin_username      = "azureuser"
      network_interface_ids = [azurerm_network_interface.VM1.id]
      computer_name                   = "LinuxVM1"
      disable_password_authentication = true
    
     admin_ssh_key {
        username   = "azureuser"
        public_key = 
      }
    
      os_disk {
        caching              = "ReadWrite"
        storage_account_type = "Standard_LRS"
      }
    
      source_image_reference {
        publisher = "Canonical"
        offer     = "UbuntuServer"
        sku       = var.ubuntu_version
        version   = "latest"
      }
    }
    

    filling the missing values.

    It should be fine for a test environment

    Cheers,
    Nico

    Login or Signup to reply.
  2. How to deploy VM through Terraform in Azure without Loadbalancer,availability set and without storage for boot diagnostic

    I have created Azure VM using Terraform without Loadbalancer, Availability Set and without storage for boot diagnostic

    Terraform code:

    provider  "azurerm"  {
    features  {}
    }
    resource  "azurerm_resource_group"  "venkatrg"  {
    name = "Venkat-resource-group"
    location = "East US"
    }
    resource  "azurerm_virtual_network"  "vnet"  {
    name = "venkat-vnet"
    address_space = ["10.0.0.0/16"]
    location = azurerm_resource_group.venkatrg.location
    resource_group_name = azurerm_resource_group.venkatrg.name
    }
    resource  "azurerm_subnet"  "subnet"  {
    name = "vm-subnet"
    resource_group_name = azurerm_resource_group.venkatrg.name
    virtual_network_name = azurerm_virtual_network.vnet.name
    address_prefixes = ["10.0.1.0/24"]
    }
    resource  "azurerm_network_interface"  "samplenic"  {
    name = "VM-nic"
    location = azurerm_resource_group.venkatrg.location
    resource_group_name = azurerm_resource_group.venkatrg.name
    ip_configuration  {
    name = "internal"
    subnet_id = azurerm_subnet.subnet.id
    private_ip_address_allocation = "Dynamic"
    }
    }
    resource  "azurerm_windows_virtual_machine"  "myvm"  {
    name = "venkat-vm"
    location = azurerm_resource_group.venkatrg.location
    resource_group_name = azurerm_resource_group.venkatrg.name
    network_interface_ids = [azurerm_network_interface.samplenic.id]
    size = "Standard_B1ls"
    admin_username = "Venkat"
    admin_password = "Password1234!"
    os_disk  {
    name = "VM-osdisk"
    caching = "ReadWrite"
    storage_account_type = "Standard_LRS"
    }
    source_image_reference  {
    publisher = "MicrosoftWindowsServer"
    offer = "WindowsServer"
    sku = "2019-Datacenter"
    version = "latest"
    }
    }
    

    Terraform apply:

    enter image description here

    Once ran the above code,Azure VM got created without Availability Set , Boot diagnostic and LoadBalancer successfully.

    enter image description here

    Boot diagnostic

    To check the boot diagnostic is enabled in VM, you can follow the below steps.

    Azure Portal > Virtual Machines > Select your VM > Boot diagnostic

    enter image description here

    To check the Loadbalancer is associated with VM, you can use the below command.

    az network nic show-effective-route-table -g "Venkat-resource-group" -n "VM-nic" --query "value[].{Name:virtualMachine.name, LoadBalancer:ipConfigurations[].loadBalancerBackendAddressPools[].id}"
    

    Output
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search