Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_spot_instance_request with associate_public_ip_address=true never assign public ip. #9575

Closed
maskinoshita opened this issue Oct 25, 2016 · 7 comments

Comments

@maskinoshita
Copy link

I'm trying to launch a spot instance with public ip in VPC. My EIPs are reached limit, so I need to use auto-assigned public ip. I set associate_public_ip_address true, but public ip is never assigned. I also tried an ondemand instance. In this case, a public ip was assigned.

vpc(subnet) setting:

  • Auto-assign Public IP: no

According to aws cli doc, spot instance with public ip can be done with followed code.
http://docs.aws.amazon.com/cli/latest/reference/ec2/request-spot-instances.html#examples

command:

aws ec2 request-spot-instances --spot-price "0.050" --instance-count 1 --type "one-time" --launch-specification file://specification.json

spcification.json:

{
  "ImageId": "ami-1a2b3c4d",
  "KeyName": "my-key-pair",
  "InstanceType": "m3.medium",
  "NetworkInterfaces": [
    {
      "DeviceIndex": 0,
      "SubnetId": "subnet-1a2b3c4d",
      "Groups": [ "sg-1a2b3c4d" ],
      "AssociatePublicIpAddress": true
    }
  ],
  "IamInstanceProfile": {
      "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role"
  }
}

Terraform Version

  • 0.7.7

Affected Resource(s)

  • aws_spot_instance_request

Terraform Configuration Files

// OK (ondemand instance in vpc)
resource "aws_instance" "ondemand" {
  // public ip is associated.
  associate_public_ip_address = true

  user_data = "..."

  instance_type = "..."
  key_name = "..."
  subnet_id = "..."
  vpc_security_group_ids = [
    "..."
  ]
  tags {
    Name = "..."
  }
}

// NG (spot instance in vpc)
resource "aws_spot_instance_request" "spot" {
  // public ip is never associated
  associate_public_ip_address = true

  spot_price = "0.5"
  wait_for_fulfillment = true

  user_data = "..."

  ami = "..."
  instance_type = "..."
  key_name = "..."

  subnet_id = "..."
  vpc_security_group_ids = [
    "..."
  ]
  tags {
    Name = "..."
  }
}

Expected Behavior

When "associate_public_ip_address=true", aws_spot_instance_request should associate public ip.

Actual Behavior

aws_spot_instance_request never associates public ip.

@stack72
Copy link
Contributor

stack72 commented Oct 26, 2016

Hi @maskinoshita

Thanks for opening the issue here - sorry this is causing you some problems. Can you tell me if the subnet that you are launching the instance into actually allows public_ips to be mapped?

Paul

@davidski
Copy link

Forgive me for jumping in on this thread -- this has bit me as well. 😄

Per the AWS docs (http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-ip-addressing.html), setting a subnet's public_ip auto-assign value to false has no effect if the EC2 reservation request has the public_ip value set to true. When using the spot_instance resource, I've been seeing reservations without the AssociatePublicIpAddress set to true per http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-spot-instance-requests.html.

Looking at the code, the resource_aws_spot_instance seems to have different logic (https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/resource_aws_spot_instance_request.go#L112-L114) than the on-demand version (https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/resource_aws_spot_instance_request.go#L112-L114), though I think the AWS-side structures are pretty much the same. Might this be the problem, @stack72 ?

@stack72 stack72 added bug waiting-response An issue/pull request is waiting for a response from the community provider/aws labels Oct 26, 2016
@maskinoshita
Copy link
Author

maskinoshita commented Oct 27, 2016

Hi, @stack72, @davidski

I wrote a reproduction code. Please see a following gist:
https://gist.github.com/maskinoshita/a7c439bfe9f2c519d45cc46946d9f19f

As @davidski said, ondemand and spot have different behaviors when subnet's map_public_ip_on_launch is set false.

I'm confused in this behavior.

@davidski
Copy link

davidski commented Nov 7, 2016

Hey @stack72 - This issue still has the waiting-response label on it. Is there anything else you need to help get this into the queue? Happy to help out where I can, short of the Go coding. 😄

@mitchellh mitchellh removed the waiting-response An issue/pull request is waiting for a response from the community label Dec 1, 2016
@hrach
Copy link
Contributor

hrach commented Mar 29, 2017

Bug is still present in 0.9.2.

@hrach
Copy link
Contributor

hrach commented Jun 8, 2017

PR with fix is here if you would like to try: #13736

@ghost
Copy link

ghost commented Apr 10, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants