我正在使用Terraform配置AWS Spot-fleet。
Spot-fleet成功配置,但是当我尝试使用ssh连接到实例以便我可以在其上运行我的Node.js应用程序(预先安装在AMI上)时出现问题。我无法检索已配置的实例的public_ip地址。
我的请求如下:
main.tf
Foo Foo Word1: bar 1x foobar 1x foo 2x bar
Foo Bar Word3: bar 2x foobar 1x foo 1x bar
这是我得到的错误:
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
}
resource "aws_spot_fleet_request" "spot_fleet" {
iam_fleet_role = "${var.iam_fleet_role}"
spot_price = "${var.spot_price}"
allocation_strategy = "${var.allocation_strategy}"
target_capacity = "${var.target_capacity}"
terminate_instances_with_expiration = "${var.terminate_instances_with_expiration}"
valid_until = "${var.valid_until}"
wait_for_fulfillment = "${var.wait_for_fulfillment}"
launch_specification {
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
ami = "${var.ami}"
vpc_security_group_ids = ["${var.security_group_id}"]
root_block_device {
volume_size = "${var.volume_size}"
volume_type = "${var.volume_type}"
}
}
provisioner "remote-exec" {
inline = [
"cd my-app",
"npm install",
"npm start",
]
connection {
host = "${self.public_ip}"
type = "ssh"
user = "ubuntu"
private_key = "${file("my-secret.pem")}"
timeout = "2m"
agent = false
}
}
}
配置的现场实例确实具有公共IP地址,我可以在AWS控制台中看到它。
我也可以使用终端SSH进入实例。