我正在尝试使用 Terrafrom 通过 Bastion 服务器连接到私有 ec2 实例。但是 Terrafrom 脚本会询问“您确定要继续连接(是/否)吗?” 我无法将“是”的答案传递给它。因此执行不完整。
我也尝试过 -input=false .. 但没有成功
# ---------------------------------------------------------------------------------------------------------------------
# Update the instnaces by installing newrelic agent using remote-exec
# ---------------------------------------------------------------------------------------------------------------------
resource "null_resource" "copy_file_newrelic_v_15" {
count = "${length(aws_instance.bastion.*.ami)}"
triggers = {
cluster_instance_ids = "${join(",", aws_instance.bastion.*.id)}"
}
connection {
host = "${element(aws_instance.bastion.*.public_ip, count.index)}"
user = "ec2-user"
private_key = "${file("C:/keys/nvirginia-key-pair-ajoy.pem")}"
agent = "true"
}
provisioner "remote-exec" {
connection {
agent = "true"
bastion_host = "${element(aws_instance.bastion.*.public_ip, count.index)}"
bastion_user = "ec2-user"
bastion_port = 22
bastion_private_key = "${file("C:/keys/nvirginia-key-pair-ajoy.pem")}"
user = "ec2-user"
private_key = "${file("C:/keys/nvirginia-key-pair-ajoy.pem")}"
host = "172.31.2.218"
}
inline = [
"ssh ec2-user@172.31.2.218"
]
}
}
在回答“您确定要继续连接(是/否)吗?”后,应通过实际执行。问题。手动或编程。
对于这个问题,我需要将“是”传递给 Terraform,这将被 Terraform 接受并完成执行
null_resource.copy_file_newrelic_v_15 (remote-exec): Connected!
null_resource.copy_file_newrelic_v_15: Still creating... (10s elapsed)
null_resource.copy_file_newrelic_v_15 (remote-exec): The authenticity of host '172.31.2.218 (172.31.2.218)' can't be established.
null_resource.copy_file_newrelic_v_15 (remote-exec): ECDSA key fingerprint is SHA256:0uaLK1VDcuHwwzCDM0GWba6RTTL4gD/hWaONHigPNyE.
null_resource.copy_file_newrelic_v_15 (remote-exec): ECDSA key fingerprint is MD5:f6:b0:39:f8:3a:dc:92:4f:c1:d9:c2:9d:13:6a:79:0a.
null_resource.copy_file_newrelic_v_15 (remote-exec): Are you sure you want to continue connecting (yes/no)?
null_resource.copy_file_newrelic_v_15: Still creating... (20s elapsed)
null_resource.copy_file_newrelic_v_15: Still creating... (30s elapsed)
null_resource.copy_file_newrelic_v_15: Still creating... (40s elapsed)
null_resource.copy_file_newrelic_v_15: Still creating... (50s elapsed)
null_resource.copy_file_newrelic_v_15: Still creating... (1m0s elapsed)
null_resource.copy_file_newrelic_v_15: Still creating... (1m10s elapsed)
null_resource.copy_file_newrelic_v_15: Still creating... (1m20s elapsed)
null_resource.copy_file_newrelic_v_15: Still creating... (1m30s elapsed)
null_resource.copy_file_newrelic_v_15: Still creating... (1m40s elapsed)