Getting error while creating and assigning aws spot instance

503 views
Skip to first unread message

sunil garje

unread,
Jun 13, 2017, 6:57:42 AM6/13/17
to Terraform
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



David Maze

unread,
Jun 13, 2017, 9:50:41 AM6/13/17
to Terraform
On Tuesday, June 13, 2017 at 6:57:42 AM UTC-4, sunil garje wrote:
Below s my playbook to cretate spot instance, create and assign EIP to that spot instance,

That's an odd request, since AWS may not be able to provide you a spot instance at the requested price and so it's possible that you'll never actually get the instance, and the EIP won't be able to be associated with anything.

The aws_spot_instance_request documentation is informative here, though.  You need to set the wait_for_fulfillment parameter on the spot instance request resource so that Terraform will wait for the instance to (hopefully) exist, and once it does, the spot_instance_id property is the instance ID (as opposed to the id property, which is the instance request ID).

sunil garje

unread,
Jun 14, 2017, 2:48:21 AM6/14/17
to terrafo...@googlegroups.com
Hi David,

Thanks for the response. The price which we have mentioned in playbook is directly taken from AWS so we are able to launch spot instance successfully but we are unable to associate existing elastic ip to that spot instance. Can you please guide how to associate existing elastic ip to the spot instance.

Thanks & Regards,
Sunil
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to a topic in the Google Groups "Terraform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/terraform-tool/U1qCCA0MGVc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/d8c64178-c1f8-499d-9fe9-514eac802f11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
# Keep learning till death #

Reply all
Reply to author
Forward
0 new messages