Skip to content

Instantly share code, notes, and snippets.

@bobalob
Last active November 3, 2016 20:33
Show Gist options
  • Save bobalob/f51870636ae9141ef6f274146a7c0177 to your computer and use it in GitHub Desktop.
Save bobalob/f51870636ae9141ef6f274146a7c0177 to your computer and use it in GitHub Desktop.
Example Terraform files for Azure Resource Manager
# Create a virtual network in the web_servers resource group
resource "azurerm_virtual_network" "pipelineNetwork" {
name = "pipelineNetwork"
address_space = ["10.0.0.0/16"]
location = "North Europe"
resource_group_name = "${azurerm_resource_group.pipelineResources.name}"
}
resource "azurerm_subnet" "pipelineSubnet1" {
name = "pipelineSubnet1"
resource_group_name = "${azurerm_resource_group.pipelineResources.name}"
virtual_network_name = "${azurerm_virtual_network.pipelineNetwork.name}"
address_prefix = "10.0.1.0/24"
}
resource "azurerm_subnet" "pipelineSubnet2" {
name = "pipelineSubnet2"
resource_group_name = "${azurerm_resource_group.pipelineResources.name}"
virtual_network_name = "${azurerm_virtual_network.pipelineNetwork.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_resource_group" "pipelineResources" {
name = "pipelineResources"
location = "North Europe"
tags {
environment = "Pipeline"
}
}
resource "azurerm_storage_account" "testStorageAccount" {
name = "teststorageaccount99"
resource_group_name = "${azurerm_resource_group.pipelineResources.name}"
location = "North Europe"
account_type = "Standard_LRS"
tags {
environment = "staging"
}
}
resource "azurerm_storage_container" "testStorageContainerVhds" {
name = "vhds"
resource_group_name = "${azurerm_resource_group.pipelineResources.name}"
storage_account_name = "${azurerm_storage_account.testStorageAccount.name}"
container_access_type = "private"
}
resource "azurerm_network_security_group" "testvm1SecurityGroup" {
name = "testvm1SecurityGroup"
location = "North Europe"
resource_group_name = "${azurerm_resource_group.pipelineResources.name}"
}
resource "azurerm_network_security_rule" "rdpRule" {
name = "rdpRule"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "3389"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = "${azurerm_resource_group.pipelineResources.name}"
network_security_group_name = "${azurerm_network_security_group.testvm1SecurityGroup.name}"
}
resource "azurerm_public_ip" "testPublicIp" {
name = "testPublicIp"
location = "North Europe"
resource_group_name = "${azurerm_resource_group.pipelineResources.name}"
public_ip_address_allocation = "dynamic"
tags {
environment = "Pipeline environment"
}
}
resource "azurerm_network_interface" "testnic" {
name = "testvm1nic"
location = "North Europe"
resource_group_name = "${azurerm_resource_group.pipelineResources.name}"
network_security_group_id = "${azurerm_network_security_group.testvm1SecurityGroup.id}"
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.pipelineSubnet1.id}"
private_ip_address_allocation = "dynamic"
public_ip_address_id = "${azurerm_public_ip.testPublicIp.id}"
}
}
resource "azurerm_virtual_machine" "testvm1" {
name = "testvm1"
location = "North Europe"
resource_group_name = "${azurerm_resource_group.pipelineResources.name}"
network_interface_ids = ["${azurerm_network_interface.testnic.id}"]
vm_size = "Basic_A1"
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter"
version = "latest"
}
storage_os_disk {
name = "testvm1osdisk1"
vhd_uri = "${azurerm_storage_account.testStorageAccount.primary_blob_endpoint}${azurerm_storage_container.testStorageContainerVhds.name}/testvm1osdisk1.vhd"
caching = "ReadWrite"
create_option = "FromImage"
}
os_profile {
computer_name = "testvm1"
admin_username = "TestAdmin"
admin_password = "c8920f35ny84950n7"
}
tags {
environment = "Pipeline environment"
}
}
# Get Server types
# Get-AzureRmVMImagePublisher -Location "North Europe" | ? {$_.PublisherName -match "MicrosoftWindows"}
# Get-AzureRmVMImageOffer -Location "North Europe" -PublisherName "MicrosoftWindowsServer"
# Get-AzureRmVMImageSku -Location "North Europe" -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment