Last active
June 7, 2018 17:54
-
-
Save jwkidd3/98c0b993134a120af831934a3fe8fad0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" {} | |
| data "azurerm_resource_group" "image" { | |
| name = "jktempvmrg" | |
| } | |
| data "azurerm_image" "image" { | |
| name = "jknginx" | |
| resource_group_name = "${data.azurerm_resource_group.image.name}" | |
| } | |
| resource "azurerm_resource_group" "test" { | |
| name = "jkterraimagetestrg" | |
| location = "southcentralus" | |
| } | |
| resource "azurerm_virtual_network" "test" { | |
| name = "acctvn" | |
| address_space = ["10.0.0.0/16"] | |
| location = "${azurerm_resource_group.test.location}" | |
| resource_group_name = "${azurerm_resource_group.test.name}" | |
| } | |
| resource "azurerm_subnet" "test" { | |
| name = "acctsub" | |
| resource_group_name = "${azurerm_resource_group.test.name}" | |
| virtual_network_name = "${azurerm_virtual_network.test.name}" | |
| address_prefix = "10.0.2.0/24" | |
| } | |
| # Create public IPs | |
| resource "azurerm_public_ip" "myterraformpublicip" { | |
| name = "myPublicIP" | |
| location = "${azurerm_resource_group.test.location}" | |
| resource_group_name = "${azurerm_resource_group.test.name}" | |
| public_ip_address_allocation = "dynamic" | |
| tags { | |
| environment = "Terraform" | |
| } | |
| } | |
| # Create Network Security Group and rule | |
| resource "azurerm_network_security_group" "myterraformnsg" { | |
| name = "myNetworkSecurityGroup" | |
| location = "${azurerm_resource_group.test.location}" | |
| resource_group_name = "${azurerm_resource_group.test.name}" | |
| security_rule { | |
| name = "SSH" | |
| priority = 1001 | |
| direction = "Inbound" | |
| access = "Allow" | |
| protocol = "Tcp" | |
| source_port_range = "*" | |
| destination_port_range = "22" | |
| source_address_prefix = "*" | |
| destination_address_prefix = "*" | |
| } | |
| security_rule { | |
| name = "HTTP" | |
| priority = 1002 | |
| direction = "Inbound" | |
| access = "Allow" | |
| protocol = "Tcp" | |
| source_port_range = "*" | |
| destination_port_range = "80" | |
| source_address_prefix = "*" | |
| destination_address_prefix = "*" | |
| } | |
| tags { | |
| environment = "Terraform NSG" | |
| } | |
| } | |
| resource "azurerm_network_interface" "test" { | |
| name = "acctni" | |
| location = "${azurerm_resource_group.test.location}" | |
| resource_group_name = "${azurerm_resource_group.test.name}" | |
| network_security_group_id = "${azurerm_network_security_group.myterraformnsg.id}" | |
| ip_configuration { | |
| name = "testconfiguration1" | |
| subnet_id = "${azurerm_subnet.test.id}" | |
| private_ip_address_allocation = "dynamic" | |
| public_ip_address_id = "${azurerm_public_ip.myterraformpublicip.id}" | |
| } | |
| } | |
| resource "azurerm_managed_disk" "test" { | |
| name = "datadisk_existing" | |
| location = "${azurerm_resource_group.test.location}" | |
| resource_group_name = "${azurerm_resource_group.test.name}" | |
| storage_account_type = "Standard_LRS" | |
| create_option = "Empty" | |
| disk_size_gb = "1023" | |
| } | |
| resource "azurerm_virtual_machine" "test" { | |
| name = "acctvm" | |
| location = "${azurerm_resource_group.test.location}" | |
| resource_group_name = "${azurerm_resource_group.test.name}" | |
| network_interface_ids = ["${azurerm_network_interface.test.id}"] | |
| vm_size = "Standard_DS1_v2" | |
| # Uncomment this line to delete the OS disk automatically when deleting the VM | |
| # delete_os_disk_on_termination = true | |
| # Uncomment this line to delete the data disks automatically when deleting the VM | |
| # delete_data_disks_on_termination = true | |
| storage_image_reference { | |
| id="${data.azurerm_image.image.id}" | |
| } | |
| storage_os_disk { | |
| name = "myosdisk1" | |
| caching = "ReadWrite" | |
| create_option = "FromImage" | |
| managed_disk_type = "Standard_LRS" | |
| } | |
| # Optional data disks | |
| storage_data_disk { | |
| name = "datadisk_new" | |
| managed_disk_type = "Standard_LRS" | |
| create_option = "Empty" | |
| lun = 0 | |
| disk_size_gb = "1023" | |
| } | |
| storage_data_disk { | |
| name = "${azurerm_managed_disk.test.name}" | |
| managed_disk_id = "${azurerm_managed_disk.test.id}" | |
| create_option = "Attach" | |
| lun = 1 | |
| disk_size_gb = "${azurerm_managed_disk.test.disk_size_gb}" | |
| } | |
| # os_profile_linux_config { | |
| # disable_password_authentication = true | |
| # ssh_keys { | |
| # path = "/home/azureuser/.ssh/authorized_keys" | |
| # key_data = "ssh-rsa AAAAB3Nz{snip}hwhqT9h" | |
| # } | |
| # } | |
| os_profile { | |
| computer_name = "jktestvm" | |
| admin_username = "azureops" | |
| admin_password = "Starbucks1234" | |
| } | |
| os_profile_linux_config { | |
| disable_password_authentication = false | |
| } | |
| tags { | |
| environment = "staging" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment