Hi Team,
Below s my playbook to cretate spot instance, create and assign EIP to that spot instance,
# Request a spot instance at $0.03
provider "aws" {
region = "us-east-1"
}
resource "aws_spot_instance_request""terra-sample" {
ami = "ami-56d890"
spot_price = "0.066"
instance_type = "c3.large"
subnet_id = "subnet-abc"
associate_public_ip_address = "true"
spot_type = "one-time"
key_name = "mykey"
block_duration_minutes = "180"
root_block_device {
volume_size = 50
volume_type = "standard"
}
tags {
key = "Name"
value = "spot-instance"
}
}
resource "aws_eip_association" "eip_assoc" {
instance_id = "${
aws_spot_instance_request.terra-sample.id}"
allocation_id = "${
aws_eip.ip.id}"
}
resource "aws_eip" "ip" {
vpc = true
}
terraform plan executed successfully but when i ran terraform apply its creating spot instance and EIP but unable to associate that EIP, getting below error,
==================================
Error applying plan:1 error(s) occurred:* aws_eip_association.eip_assoc: 1 error(s) occurred:* aws_eip_association.eip_assoc: [WARN] Error attaching EIP, message: "Invalid id: "sir-zz4h420j"", code: "InvalidInstanceID.Malformed"
==================================
Instead of instance id its taking resource id, i am new to Terraform so dont know how to assign EIP to instance id in Spot instance.
In spot instance there is no instance id Field in AWS console instance id's are listed under Capacity tab.
Please help me to resolve this issue.
Thanks & regards,
Sunil