Created
February 13, 2019 14:51
-
-
Save mikaelkrief/b06178d1fde38ba24d67c5c5a574a9f1 to your computer and use it in GitHub Desktop.
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
resource "azurerm_virtual_machine" "myterraformvm" { | |
name = "myVM" | |
location = "eastus" | |
resource_group_name = "${azurerm_resource_group.myterraformgroup.name}" | |
network_interface_ids = ["${azurerm_network_interface.myterraformnic.id}"] | |
vm_size = "Standard_DS1_v2" | |
storage_os_disk { | |
name = "myOsDisk" | |
caching = "ReadWrite" | |
create_option = "FromImage" | |
managed_disk_type = "Premium_LRS" | |
} | |
storage_image_reference { | |
publisher = "Canonical" | |
offer = "UbuntuServer" | |
sku = "16.04.0-LTS" | |
version = "latest" | |
} | |
os_profile { | |
computer_name = "myvm" | |
admin_username = "azureuser" | |
} | |
os_profile_linux_config { | |
disable_password_authentication = true | |
ssh_keys { | |
path = "/home/azureuser/.ssh/authorized_keys" | |
key_data = "ssh-rsa AAAAB3Nz{snip}hwhqT9h" | |
} | |
} | |
boot_diagnostics { | |
enabled = "true" | |
storage_uri = "${azurerm_storage_account.mystorageaccount.primary_blob_endpoint}" | |
} | |
connection { | |
type = "ssh" | |
host = "${var.address_ip")}" | |
user = "${var.admin_username}" | |
password = "${var.admin_password}" | |
} | |
provisioner "file" { | |
source = "/mount_disk.sh" | |
destination = "/tmp/mount_disk.sh" | |
} | |
provisioner "remote-exec" { | |
inline = [ | |
"echo ${var.admin_password} | sudo -S chmod +x /tmp/mount_disk.sh", | |
"sudo /tmp/mount_disk.sh", | |
] | |
} | |
tags { | |
environment = "Terraform Demo" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment