_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 terraform-providers/terraform-provider-aws#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.
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.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)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 hashicorp/terraform#4380 does.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.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.aws_spot_instance which behaves as described in hashicorp/terraform#3, to avoid changing the aws_instance object.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/
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"?
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.
The issue has been noted in https://github.com/terraform-providers/terraform-provider-aws/issues/32 (and others) and a solution discussed in https://github.com/terraform-providers/terraform-provider-aws/issues/9061#issuecomment-557818716.
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!
Most helpful comment
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_fulfilmentis 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.