Last active
November 14, 2018 17:42
-
-
Save scarolan/95010d2b2180b7cf6919a82e623c2f0b to your computer and use it in GitHub Desktop.
challenge 04 answer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "azurerm" { | |
version = "= 1.4" | |
} | |
terraform { | |
required_version = ">= 0.11.7" | |
} | |
variable "name" { | |
default = "seanc03" | |
} | |
variable "location" { | |
default = "centralus" | |
} | |
variable "vmcount" { | |
default = 1 | |
} | |
resource "azurerm_resource_group" "main" { | |
name = "${var.name}-rg" | |
location = "${var.location}" | |
} | |
resource "azurerm_virtual_network" "main" { | |
name = "${var.name}-vnet" | |
address_space = ["10.0.0.0/16"] | |
location = "${azurerm_resource_group.main.location}" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
} | |
resource "azurerm_subnet" "main" { | |
name = "${var.name}-subnet" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
virtual_network_name = "${azurerm_virtual_network.main.name}" | |
address_prefix = "10.0.1.0/24" | |
} | |
resource "azurerm_network_interface" "main" { | |
name = "${var.name}-nic-${count.index}" | |
count = "${var.vmcount}" | |
location = "${azurerm_resource_group.main.location}" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
ip_configuration { | |
name = "config1" | |
subnet_id = "${azurerm_subnet.main.id}" | |
private_ip_address_allocation = "dynamic" | |
public_ip_address_id = "${element(azurerm_public_ip.main.*.id, count.index)}" | |
} | |
} | |
resource "azurerm_virtual_machine" "main" { | |
name = "${var.name}-vm${count.index}" | |
count = "${var.vmcount}" | |
location = "${azurerm_resource_group.main.location}" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
network_interface_ids = ["${element(azurerm_network_interface.main.*.id, count.index)}"] | |
vm_size = "Standard_A2_v2" | |
storage_image_reference { | |
publisher = "MicrosoftWindowsServer" | |
offer = "WindowsServer" | |
sku = "2016-Datacenter" | |
version = "latest" | |
} | |
storage_os_disk { | |
name = "${var.name}vm${count.index}-osdisk" | |
caching = "ReadWrite" | |
create_option = "FromImage" | |
managed_disk_type = "Standard_LRS" | |
} | |
os_profile { | |
computer_name = "${var.name}vm${count.index}" | |
admin_username = "testadmin" | |
admin_password = "Password1234!" | |
} | |
os_profile_windows_config {} | |
} | |
resource "azurerm_public_ip" "main" { | |
name = "${var.name}-pubip${count.index}" | |
count = "${var.vmcount}" | |
location = "${azurerm_resource_group.main.location}" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
public_ip_address_allocation = "static" | |
} | |
output "private-ip" { | |
value = "${azurerm_network_interface.main.*.private_ip_address}" | |
description = "Private IP Address" | |
} | |
output "public-ip" { | |
value = "${azurerm_public_ip.main.*.ip_address}" | |
description = "Public IP Address" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment