1
votes

Terraform v0.12.x

I'm trying to create an AWS launch template using of course the aws_launch_template resource, and trying to relate to what the AWS console gives me when I try to create a launch template there. In the AWS console, I see the "Network settings" option seen in screen shot.

enter image description here

However, but I don't see a corresponding setting for the Terraform resource? Is that correct? I think I need to set it because when I try to create a spot fleet request, using Terraform's aws_spot_fleet_request resource, and using the launch template created by Terraform, it defaults to the "EC2-Classic" setting, which doesn't work for me. I get this error

Error: Error requesting spot fleet: InvalidSpotFleetRequestConfig: Invalid: (InstanceType: r5a.xlarge with Os: Linux/UNIX and EC2-Classic)

How can I fix this?

1

1 Answers

1
votes

Ah, in the aws_spot_request resource, add an overrides that specifies a subnet id, which will of course put the instances in a VPC

resource "aws_spot_fleet_request" "jenkins_build_fleet" {
  ...    
  launch_template_config {
    launch_template_specification {
      id      = module.launch_template.id
      version = module.launch_template.version
    }
    overrides {
      subnet_id = "subnet-12345abcde"
    }
  }
}