ERROR: ╷ │ Error: Unsupported attribute │ │ on spot_inst.tf line 82, in resource "null_resource" "spot_inst_ssh": │ 82: host = element(aws_spot_fleet_request.spot_inst..public_ip,"${each.value.IMO}") │ │ This object does not have an attribute named "public_ip". ╵ ╷ │ Error: Unsupported attribute │ │ on spot_inst.tf line 82, in resource "null_resource" "spot_inst_ssh": │ 82: host = element(aws_spot_fleet_request.spot_inst..public_ip,"${each.value.IMO}") │ │ This object does not have an attribute named "public_ip". ╵
Below is the main.tf file
locals {
csvdata = csvdecode(file("C:\\Users\\myhome\\Desktop\\test_terraform\\IMO_TOKEN.csv"))
}
resource "aws_spot_fleet_request" "spot_inst" {
iam_fleet_role = "arn:aws:iam::123456789:role/aws-ec2-spot-fleet-tagging-role"
for_each = { for inst in local.csvdata : inst.IMO => inst }
spot_price = "0.5"
target_capacity = 1
wait_for_fulfillment = true
launch_specification {
instance_type = "m5a.xlarge"
ami = "ami-07dbhghghhfgfg"
associate_public_ip_address = true
key_name = "dryrun"
subnet_id = "subnet-059107999db020b76"
vpc_security_group_ids = ["sg-0511bb4914501d1ce"]
root_block_device{
volume_size = 20
volume_type = "gp3"
iops = "3000"
}
tags = {
Name = "CloudInst${each.value.TOKEN}"
Environment = "dev"
Group = "OPS"
}
}
launch_specification {
instance_type = "m5d.xlarge"
ami = "ami-07dbhghghhfgfg"
associate_public_ip_address = true
key_name = "dryrun"
subnet_id = "subnet-059107999db020b76"
vpc_security_group_ids = ["sg-0511bb4914501d1ce"]
root_block_device{
volume_size = 20
volume_type = "gp3"
iops = "3000"
}
tags = {
Name = "CloudInst${each.value.TOKEN}"
Environment = "dev"
Group = "OPS"
}
}
/*
connection {
type = "ssh"
host = "${self.public_ip}"
user = "centos"
private_key = "${file("C:\\Users\\myhome\\Desktop\\test_terraform\\dryrun.pem")}"
timeout = "5m"
agent = true
}
provisioner "remote-exec" {
inline = ["/usr/bin/nohup /usr/bin/sudo /usr/bin/sh /home/centos/new_cloudinst.sh ${each.value.IMO} ${each.value.TOKEN}"]
}
*/
}
resource "null_resource" "spot_inst_ssh" {
depends_on = [aws_spot_fleet_request.spot_inst]
for_each = { for inst in local.csvdata : inst.IMO => inst }
connection {
type = "ssh"
host = element(aws_spot_fleet_request.spot_inst.*.public_ip,"${each.value.IMO}")
user = "centos"
private_key = "${file("C:\\Users\\myhome\\Desktop\\test_terraform\\dryrun.pem")}"
timeout = "5m"
agent = true
}
provisioner "remote-exec" {
inline = ["/usr/bin/nohup /usr/bin/sudo /usr/bin/sh /home/centos/new_cloudinst.sh ${each.value.IMO} ${each.value.TOKEN}"]
}
}