resource "azurerm_linux_virtual_machine" "web" {
name = "wwweb"
computer_name = "wwweb"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
size = "Standard_F2"
admin_username = "chainer"
network_interface_ids = [
azurerm_network_interface.example.id,
]
admin_ssh_key {
username = "chainer"
public_key = file("/etc/ssh/teraf.pub")
}
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
provisioner "file" {
source = "/home/chainer/git/dev/main"
destination = "/home/chainer/main"
}
provisioner "file" {
source = "/home/chainer/git/dev/app.py"
destination = "/home/chainer/app.py"
}
provisioner "remote-exec" {
inline = [
"sudo apt update && sudo apt install python3.7 -y && sudo apt-get install python3-pip -y && sudo pip3 install Flask"
]
}
provisioner "remote-exec" {
inline = [
"export FLASK_APP=app.py && export FLASK_ENV=production && flask run -h 0.0.0.0 & "
]
}
provisioner "remote-exec" {
inline = [
"sudo chmod +x main && sudo ./main & "
]
}
connection {
host = azurerm_linux_virtual_machine.web.public_ip_address
user = "chainer"
type = "ssh"
private_key = file("/etc/ssh/teraf")
timeout = "10m"
}
}
azure