0

这是我的代码,我正在尝试使用 terraform 配置程序配置 puppet 节点,但它显示以下错误,已设置连接主机密码、用户 ID 等

错误是-错误:超时-最后一个错误:拨号tcp:22:connectex:无法建立连接,因为目标机器主动拒绝了它。

resource "azurerm_resource_group" "main" {
  name     = "az-testing"
  location = "West US 2"

}
resource "azurerm_network_security_group" "Customernsg1" {
  name                = "demoNsg1"
  location            = azurerm_resource_group.main.location
  resource_group_name = azurerm_resource_group.main.name
}

resource "azurerm_network_security_rule" "customerrule1" {
  name                        = "SSH"
  priority                    = 100
  direction                   = "Inbound"
  access                      = "Allow"
  protocol                    = "Tcp"
  source_port_range           = "*"
  destination_port_range      = "22"
  source_address_prefix       = "*"
  destination_address_prefix  = "*"
  resource_group_name         = azurerm_resource_group.main.name
  network_security_group_name = azurerm_network_security_group.Customernsg1.name
}


resource "azurerm_virtual_network" "main" {
  name                = "vnetwork"
  address_space       = ["*.*.*.*/16"]
  location            = azurerm_resource_group.main.location
  resource_group_name = azurerm_resource_group.main.name
}

resource "azurerm_subnet" "internal" {
  name                 = "internal"
  resource_group_name  = azurerm_resource_group.main.name
  virtual_network_name = azurerm_virtual_network.main.name
  address_prefix       = "*.*.*.*/24"
}

resource "azurerm_subnet_network_security_group_association" "example" {
  subnet_id                     = azurerm_subnet.internal.id
  network_security_group_id     = azurerm_network_security_group.Customernsg1.id
}
resource "azurerm_public_ip" "example" {
  name                    = "test-pip"
  location                = azurerm_resource_group.main.location
  resource_group_name     = azurerm_resource_group.main.name
  allocation_method       = "Dynamic"
}

resource "azurerm_network_interface" "main" {
  name                = "vmnic"
  location            = azurerm_resource_group.main.location
  resource_group_name = azurerm_resource_group.main.name

  ip_configuration {
    name                          = "testconfiguration1"
    subnet_id                     = azurerm_subnet.internal.id
    private_ip_address_allocation = "Dynamic"
    public_ip_address_id          = azurerm_public_ip.example.id

  }
}


resource "azurerm_virtual_machine" "main" {
  name                  = "demo-vm"
  location              = azurerm_resource_group.main.location
  resource_group_name   = azurerm_resource_group.main.name
  network_interface_ids = [azurerm_network_interface.main.id]
  vm_size               = "Standard_DS1_v2"
  #user_data            = data.template_file.node_userdata.rendered

  # 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 {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"

  }
  storage_os_disk {
    name              = "myosdisk1"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }
  os_profile {
    computer_name  = "hostname"
    admin_username = "testadmin"
    admin_password = "Password1234!"
  }
  os_profile_linux_config {
    disable_password_authentication = false
  }
  tags = {
    environment = "staging"
  }


 provisioner "remote-exec" {
  connection {
    type        = "ssh"
    host        = azurerm_public_ip.example.ip_address
     user        = "testadmin"
    password    = "Password1234!"


  }

    inline = [
"rpm -Uvh $ wget https://apt.puppetlabs.com/puppet6-release-bionic.deb",
"sudo dpkg -i puppet6-release-bionic.deb",
"sudo apt-get install puppet-agent",
"export PATH=/opt/puppetlabs/bin:$PATH",
"puppet config set server $ puppet.demo.local  --section main",
"puppet resource service puppet ensure=running enable=true",
    ]
  }
}

显示以下错误

4

1 回答 1

0

该错误显示了导致的原因。实际上,我认为这不是使用remote_exec配置器的好方法。Terraform 还显示:

供应商只能作为最后的手段使用。对于最常见的情况,有更好的选择。有关更多信息,请参阅主供应商页面

对于 Azure 虚拟机,cloud-init 和 VM 扩展更合适。

于 2020-05-12T06:19:56.183 回答