Created
April 21, 2020 13:38
-
-
Save heoelri/4564636f8a3ac0a350b18e8ae26145a7 to your computer and use it in GitHub Desktop.
Sample Configuration deploying a VM on Azure Stack Hub with Terraform
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
# Configure the Azure Stack Provider | |
# https://www.terraform.io/docs/providers/azurestack/index.html | |
provider "azurestack" { | |
# NOTE: we recommend pinning the version of the Provider which should be used in the Provider block | |
# https://github.com/terraform-providers/terraform-provider-azurestack/releases | |
version = "=0.9.0" | |
# Connection Details (can be provided via variables) | |
arm_endpoint = "" # https://management.local.azurestack.external (for ASDK) | |
client_id = "" | |
client_secret = "" | |
subscription_id = "" | |
tenant_id = "" | |
} | |
# Create a resource group | |
resource "azurestack_resource_group" "deployment" { | |
name = "terraformrg" | |
location = "local" | |
} | |
# Create a virtual network within the resource group | |
resource "azurestack_virtual_network" "deployment" { | |
name = "terraform-vnet" | |
address_space = ["10.0.0.0/16"] | |
location = azurestack_resource_group.deployment.location | |
resource_group_name = azurestack_resource_group.deployment.name | |
} | |
# Azure Stack Virtual Network Subnet | |
resource "azurestack_subnet" "default" { | |
name = "default" | |
resource_group_name = azurestack_resource_group.deployment.name | |
virtual_network_name = azurestack_virtual_network.deployment.name | |
address_prefix = "10.0.1.0/24" | |
} | |
# Public IP Address | |
resource "azurestack_public_ip" "terraform-vm1-pip" { | |
name = "terraform-vm1-pip" | |
location = azurestack_resource_group.deployment.location | |
resource_group_name = azurestack_resource_group.deployment.name | |
public_ip_address_allocation = "static" | |
} | |
# Network Interface | |
resource "azurestack_network_interface" "terraform-vm1-nic" { | |
name = "terraform-vm1-nic" | |
location = azurestack_resource_group.deployment.location | |
resource_group_name = azurestack_resource_group.deployment.name | |
network_security_group_id = azurestack_network_security_group.terraform-vm1-nsg.id | |
ip_configuration { | |
name = "testconfiguration1" | |
subnet_id = azurestack_subnet.default.id | |
private_ip_address_allocation = "dynamic" | |
public_ip_address_id = azurestack_public_ip.terraform-vm1-pip.id | |
} | |
} | |
# Azure Stack Virtual Machine | |
resource "azurestack_virtual_machine" "terraform-vm1" { | |
name = "terraform-vm1" | |
location = azurestack_resource_group.deployment.location | |
resource_group_name = azurestack_resource_group.deployment.name | |
network_interface_ids = [ | |
azurestack_network_interface.terraform-vm1-nic.id | |
] | |
vm_size = "Standard_F2" | |
storage_image_reference { | |
publisher = "Canonical" | |
offer = "UbuntuServer" | |
sku = "18.04-LTS" | |
version = "latest" | |
} | |
storage_os_disk { | |
name = "terraform-vm1-osdisk" | |
create_option = "FromImage" | |
managed_disk_type = "Standard_LRS" | |
} | |
os_profile { | |
computer_name = "hostname" | |
admin_username = "testadmin" | |
admin_password = "Password1234!" | |
} | |
os_profile_linux_config { | |
disable_password_authentication = false | |
} | |
} | |
# Network Security Group (with a rule for RDP) | |
resource "azurestack_network_security_group" "terraform-vm1-nsg" { | |
name = "terraform-vm1-nsg" | |
location = azurestack_resource_group.deployment.location | |
resource_group_name = azurestack_resource_group.deployment.name | |
security_rule { | |
name = "RuleAllowRDP" | |
priority = 100 | |
direction = "Inbound" | |
access = "Allow" | |
protocol = "Tcp" | |
source_port_range = "*" | |
destination_port_range = "3389" | |
source_address_prefix = "*" | |
destination_address_prefix = "*" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment