#Creating a Resource Group
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "PasinduTestRG" {
name = "PasinduTestRG"
location = "eastus"
}
#Create a Virtual Network and a Subnet
resource "azurerm_virtual_network" "PasinduTestVN" {
name = "PasinduTestVN"
address_space = ["10.1.0.0/24"]
location = azurerm_resource_group.PasinduTestRG.location
resource_group_name = azurerm_resource_group.PasinduTestRG.name
}
resource "azurerm_subnet" "PasinduTestS" {
name = "PasinduTestS"
resource_group_name = azurerm_resource_group.PasinduTestRG.name
virtual_network_name = azurerm_virtual_network.PasinduTestVN.name
address_prefixes = ["10.1.0.0/26"]
}
#Create a Network Interface Card
resource "azurerm_network_interface" "PasinduTestNIC" {
name = "PasinduTestNIC"
location = azurerm_resource_group.PasinduTestRG.location
resource_group_name = azurerm_resource_group.PasinduTestRG.name
ip_configuration {
name = "192.168.43.48"
subnet_id = azurerm_subnet.PasinduTestS.id
private_ip_address_allocation = "Dynamic"
}
}
#Create a Virtual Machine.
resource "azurerm_windows_virtual_machine" "PasinduTestVM" {
name = "PasinduTestVM"
resource_group_name = azurerm_resource_group.PasinduTestRG.name
location = azurerm_resource_group.PasinduTestRG.location
size = "Standard_B1s"
admin_username = "[pasindu]"
admin_password = "[Syd@07125]"
network_interface_ids = [
azurerm_network_interface.PasinduTestNIC.id,
]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "EuroLinux Sp. z o. o."
offer = "LinuxServer"
sku = "Centos 7.9.22"
version = "latest"
}
}