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

How to Handle AWS Spot Instance args (tags, etc.) #174

Closed
hashibot opened this issue Jun 13, 2017 · 5 comments
Closed

How to Handle AWS Spot Instance args (tags, etc.) #174

hashibot opened this issue Jun 13, 2017 · 5 comments
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.

Comments

@hashibot
Copy link

This issue was originally opened by @johnnyshields as hashicorp/terraform#6791. It was migrated here as part of the provider split. The original body of the issue is below.


This is a dupe of issue #32 and PR hashicorp/terraform#4380. I am raising a new issue because I'd like to revisit the problem and agree on an approach with the Terraform team.

The Problem

  • We need to set tags on AWS spot instances.
  • The Terraform schema contains a spot_instance_request resource. A aws_spot_instance_request is not an "instance" itself, rather it is a request to Amazon to generate an instance.
  • The Terraform schema allows setting tags on aws_spot_instance_request, however, the tags are not forwarded by AWS to the actual instance when the request in fulfilled (see: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-requests.html)

Possible Solutions

  1. Interpret tags on aws_spot_instance_request to mean the tags to set on the instance created when the spot request is fulfilled. This is what PR provider/aws: tag the spot instance. terraform#4380 does.
  2. Add an instance_args node to the aws_spot_instance_request resource which allows various args like tags to be set by Terraform on the instance after fulfillment.
  3. Enhance the aws_instance to have new fields is_spot_instance, spot_price, spot_type etc. If these are set, then Terraform uses a spot instance request workflow to initialize the instance. This approach will require the most effort but is ultimately the most friendly / least surprising to the developer in my opinion--many AWS-related libraries use this abstraction pattern.
  4. Introduce a new resource aws_spot_instance which behaves as described in config: require blocks for upstream dependencies terraform#3, to avoid changing the aws_instance object.
@hashibot hashibot added the bug Addresses a defect in current functionality. label Jun 13, 2017
@elatt
Copy link

elatt commented Sep 21, 2017

AWS now natively supports instance tags for spot fleets/requests: https://aws.amazon.com/about-aws/whats-new/2017/07/tag-your-spot-fleet-ec2-instances/

@rarkins
Copy link

rarkins commented Nov 11, 2017

I have one spot instance created by one spot instance request, and I'd like name and tags to work like they do on aws_instance. Is there any way to do this without needing to complicate things with a 1-instance "fleet"?

@radeksimko radeksimko added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 21, 2018
@tomelliff
Copy link
Contributor

Unfortunately it's still not directly possible to tag spot instances themselves when they start as a spot instance request. The AWS User Guide explains this a bit further and mentions you have to manually tag the instances after they are created.

It should be technically possible for Terraform to find the instances created by the spot request and then tag them after waiting for fulfilment but I'm not 100% sure on how to best define how this happens other than just have it happen implicitly if the spot instance request is tagged and wait_for_fulfilment is true potentially tagging the instance with things that were only meant for the request. That said, I'd be very surprised if there was anyone who genuinely didn't want those tags to be passed to the instance.

@ewbankkit
Copy link
Contributor

The issue has been noted in #32 (and others) and a solution discussed in #9061 (comment).

@ghost
Copy link

ghost commented Jul 4, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Jul 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

No branches or pull requests

6 participants