How to deploy spot instances in your custom VPC

resource “aws_spot_instance_request” “my-spot” {

spot_price = “$.$$$”
ami = “ami-xxxxx” #
wait_for_fulfillment = true
spot_type = “persistent”
instance_interruption_behaviour = “stop”
instance_type = “my.metal”
key_name = aws_key_pair.my-key.key_name
}

The above code deploys spot in “default-vpc” and in a default subnet. Can some point me as to how to deploy the spot instance in your private vpc with private subnet and not default vpc and default subnet ???

-Girish

Although not expected, deployment of single private spot instances isn’t supported by the resource.
However you could create an autoscaling group with launch configuration or a spot_fleet for deployment. Using ASGs for SPOT itself make sense though.

It might be helpful to start with or learn from an existing module like:
https://registry.terraform.io/modules/figurate/spot-fleet/aws/latest?tab=inputs