1## main.tf
2 3resource"azurerm_linux_virtual_machine""dev_eu_north_ubuntu_vm"{ 4name="dev-eu-north-ubuntu2204-vm" 5resource_group_name=azurerm_resource_group.dev_eu_north_rg.name 6location=azurerm_resource_group.dev_eu_north_rg.location 7size="Standard_F2" 8admin_username="rahulwagh" 9 #admin_password = "G<7€YraRgk_7lnksE}yu37`Fe"
10disable_password_authentication=true11admin_ssh_key{12username="rahulwagh"13public_key=file("/Users/rahulwagh/.ssh/dev-vm-ssh-key-pair.pub")14}1516network_interface_ids=[17azurerm_network_interface.dev_eu_north_nic.id,18]1920os_disk{21caching="ReadWrite"22storage_account_type="Standard_LRS"23}2425source_image_reference{26publisher="Canonical"27offer="0001-com-ubuntu-server-jammy"28sku="22_04-lts"29version="latest"30}31}3233resource"azurerm_network_interface""dev_eu_north_nic"{34name="dev-eu-north-nic"35location=azurerm_resource_group.dev_eu_north_rg.location36resource_group_name=azurerm_resource_group.dev_eu_north_rg.name3738ip_configuration{39name="internal"40subnet_id=azurerm_subnet.dev_eu_north_public_subnet.id41private_ip_address_allocation="Dynamic"42public_ip_address_id=azurerm_public_ip.dev_eu_north_static_public_ip.id43}44depends_on=[azurerm_network_security_group.dev_eu_north_ssh_nsg,azurerm_public_ip.dev_eu_north_static_public_ip]45}4647resource"azurerm_public_ip""dev_eu_north_static_public_ip"{48name="dev-eu-north-static-public-ip"49resource_group_name=azurerm_resource_group.dev_eu_north_rg.name50location=azurerm_resource_group.dev_eu_north_rg.location51allocation_method="Static"52}5354# Create Network Security Group and rule
55resource"azurerm_network_security_group""dev_eu_north_ssh_nsg"{56name="dev-eu-north-ssh-nsg"57location=azurerm_resource_group.dev_eu_north_rg.location58resource_group_name=azurerm_resource_group.dev_eu_north_rg.name5960security_rule{61name="SSH"62priority=100163direction="Inbound"64access="Allow"65protocol="Tcp"66source_port_range="*"67destination_port_range="22"68source_address_prefix="*"69destination_address_prefix="*"70}7172tags={73environment="Terraform Demo"74}75}7677#Connect the security group to the network interface
78resource"azurerm_network_interface_security_group_association""dev_eu_north_nsg_nic_association"{79network_interface_id=azurerm_network_interface.dev_eu_north_nic.id80network_security_group_id=azurerm_network_security_group.dev_eu_north_ssh_nsg.id81depends_on=[azurerm_network_interface.dev_eu_north_nic]82}