What can cause "Network interfaces and instance-level security groups may not be specified on the same request" when using launch templates?

Viewed 134

I'm getting

╷
│ Error: creating EC2 Instance: InvalidParameterCombination: Network interfaces and an instance-level security groups may not be specified on the same request
│       status code: 400, request id: 97729886-6941-430d-9e6b-86b756710c6b
│ 

The aws_instance references a aws_launch_template but as far as I know the launch template and instance definition do not have conflicting setting regarding the security groups, I even removed all security group references from both the launch template and instance and I still get the same error.

What else can be the source of this message?

1 Answers

You can always try to create the EC2 instance from the AWS console with "Launch instance from template" and usually get a better indication of what is the underlying problem.

In particular check that you aws_instance is using the $Latest version of your aws_launch_template and not $Default which is usually version 1 and not the latest.

resource "aws_instance" "xxxx" {
  launch_template {
    id = aws_launch_template.yyyy.id
    version = "$Latest"
  }

...

Otherwise you may be trying with an older version of the launch template that actually is specifying security groups at both the network interface level and instance level.

Related