terraprov provisoner无法连接到机器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了terraprov provisoner无法连接到机器相关的知识,希望对你有一定的参考价值。
这是我的代码,我正在尝试使用Terraform Provisioner配置er节点,但显示以下错误,设置了连接主机密码,用户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",
]
}
}
答案
错误显示了引起的原因。实际上,我认为这不是使用remote_exec
预配器的好方法。 Terraform还显示:供应商只能作为不得已的手段。对于大多数常见情况,有更好的选择。有关更多信息,请参见the main Provisioners page。
对于Azure虚拟机,更适合使用cloud-init和VM扩展名。
以上是关于terraprov provisoner无法连接到机器的主要内容,如果未能解决你的问题,请参考以下文章
无法使用php连接错误连接到mysql:无法连接到'localhost'(10061)上的MySQL服务器[重复]
MySQL Workbench 无法连接到我的 RDS 数据库:无法连接到 localhost
Django docker 容器无法连接到 mysql 容器,出现错误“无法连接到 'db' (111) 上的 MySQL 服务器”)