Guest User

Untitled

a guest
Sep 19th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. /*Tested Ok example of Azure VM deployment*/
  2.  
  3. variable "prefix" {
  4. default = "tfvmex"
  5. }
  6.  
  7. /*Create a resource group in a region*/
  8. resource "azurerm_resource_group" "main" {
  9. name = "${var.prefix}-resources"
  10. location = "West US 2"
  11. }
  12.  
  13. /*create a primary virtual network*/
  14. resource "azurerm_virtual_network" "main" {
  15. name = "${var.prefix}-network"
  16. address_space = ["10.0.0.0/16"]
  17. location = "${azurerm_resource_group.main.location}"
  18. resource_group_name = "${azurerm_resource_group.main.name}"
  19. }
  20.  
  21. /*Create a subnet on a virtual network in a resource group*/
  22. resource "azurerm_subnet" "internal" {
  23. name = "internal"
  24. resource_group_name = "${azurerm_resource_group.main.name}"
  25. virtual_network_name = "${azurerm_virtual_network.main.name}"
  26. address_prefix = "10.0.2.0/24"
  27. }
  28.  
  29. /*create a primary network interface (before the VM is created)*/
  30. resource "azurerm_network_interface" "main" {
  31. name = "${var.prefix}-nic"
  32. location = "${azurerm_resource_group.main.location}"
  33. resource_group_name = "${azurerm_resource_group.main.name}"
  34.  
  35. ip_configuration {
  36. name = "testconfiguration1"
  37. subnet_id = "${azurerm_subnet.internal.id}"
  38. private_ip_address_allocation = "dynamic"
  39. }
  40. }
  41.  
  42. /*Create a virtual machine in the defined resource group with the
  43. created primary interface in the defined network on the designated
  44. subnet :-) */
  45. resource "azurerm_virtual_machine" "main" {
  46. name = "${var.prefix}-vm"
  47. location = "${azurerm_resource_group.main.location}"
  48. resource_group_name = "${azurerm_resource_group.main.name}"
  49. network_interface_ids = ["${azurerm_network_interface.main.id}"]
  50. vm_size = "Standard_DS1_v2"
  51.  
  52. # Uncomment this line to delete the OS disk automatically when deleting the VM
  53. delete_os_disk_on_termination = true
  54.  
  55. # Uncomment this line to delete the data disks automatically when deleting the VM
  56. #delete_data_disks_on_termination = true
  57.  
  58. storage_image_reference {
  59. publisher = "Canonical"
  60. offer = "UbuntuServer"
  61. sku = "16.04-LTS"
  62. version = "latest"
  63. }
  64.  
  65. storage_os_disk {
  66. name = "myosdisk1"
  67. caching = "ReadWrite"
  68. create_option = "FromImage"
  69. managed_disk_type = "Standard_LRS"
  70. }
  71.  
  72. os_profile {
  73. computer_name = "hostname"
  74. admin_username = "testadmin"
  75. admin_password = "Password1234!"
  76. }
  77.  
  78. os_profile_linux_config {
  79. disable_password_authentication = false
  80. }
  81.  
  82. boot_diagnostics {
  83. enabled = "true"
  84. storage_uri = "${azurerm_storage_account.diagstorage2.primary_blob_endpoint}"
  85. }
  86.  
  87. tags {
  88. environment = "development"
  89. }
  90. }
Add Comment
Please, Sign In to add comment