Error: remote-exec provisioner error
│
│ with azurerm_virtual_machine.example,
│ on main.tf line 380, in resource “azurerm_virtual_machine” “example”:
│ 380: provisioner “remote-exec” {
│
│ host for provisioner cannot be empty
coed:
terraform {
required_version = “>=0.12”
required_providers {
azurerm = {
source = “hashicorp/azurerm”
version = “~>2.0”
}
}
}
provider “azurerm”{
features {}
}
resource “azurerm_resource_group” “rg” {
name = “my-first-terraform-rg”
location = “eastus”
}
resource “azurerm_virtual_network” “myvnet” {
name = “my-vnet”
address_space = [ “10.0.0.0/16” ]
location = “eastus”
resource_group_name = azurerm_resource_group.rg.name
}
resource “azurerm_subnet” “frontendsubnet” {
name = “frontendSubnet”
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.myvnet.name
address_prefix = “10.0.1.0/24”
}
resource “azurerm_network_security_group” “example” {
name = “acceptanceTestSecurityGroup1”
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
security_rule {
name = “test123”
priority = 100
direction = “Inbound”
access = “Allow”
protocol = “Tcp”
source_port_range = “"
destination_port_range = "”
source_address_prefix = “"
destination_address_prefix = "”
}
}
resource “azurerm_subnet_network_security_group_association” “example” {
subnet_id = azurerm_subnet.frontendSubnet.id
network_security_group_id = azurerm_network_security_group.example.id
}
resource “azurerm_public_ip” “myvm1publicip” {
name = “pip1”
location = “eastus”
resource_group_name = azurerm_resource_group.rg.name
allocation_method = “Dynamic”
sku = “Basic”
}
data “azurerm_public_ip” “myterraformpublicip” {
name = azurerm_public_ip.myvm1publicip.name
resource_group_name = azurerm_resource_group.rg.name
}
resource “azurerm_network_interface” “myvm1nic” {
name = “myvm1-nic”
location = “eastus”
resource_group_name = azurerm_resource_group.rg.name
ip_configuration {
name = “ipconfig1”
subnet_id = azurerm_subnet.frontendsubnet.id
private_ip_address_allocation = “Dynamic”
public_ip_address_id = azurerm_public_ip.myvm1publicip.id
}
}
resource “azurerm_windows_virtual_machine” “example” {
name = “myvm1”
location = “eastus”
resource_group_name = azurerm_resource_group.rg.name
network_interface_ids = [ azurerm_network_interface.myvm1nic.id ]
size = “Standard_A1_v2”
delete_os_disk_on_termination = true
storage_image_reference {
publisher = “OpenLogic”
offer = “CentOS”
sku = “7.5”
version = “latest”
storage_os_disk {
name = “chiki”
caching = “ReadWrite”
create_option = “FromImage”
managed_disk_type = “Standard_LRS”
}
os_profile {
computer_name = “linuxhost”
admin_username = “terminator”
admin_password = “Password@1234”
}
os_profile_linux_config {
disable_password_authentication = false
}
resource “null_resource” “execute” {
connection {
type = “ssh”
host = azurerm_public_ip.myvm1publicip.ip_address
timeout = “5m”
user = “adminuser”
password = “Password123!”
}
provisioner “remote-exec” {
inline = [
“ls -a”,
“cat newfile.txt”
]
}
}
}