hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.85k stars 9.2k forks source link

[Bug]: Create spot instance request with a network interface fails #38335

Open gabrielar opened 4 months ago

gabrielar commented 4 months ago

Terraform Core Version

1.9.2

AWS Provider Version

5.57.0

Affected Resource(s)

Expected Behavior

Given:

resource "aws_spot_instance_request" "default" {

  ami                         = data.aws_ami.alpine.id

  spot_price                  = "0.0053"
  wait_for_fulfillment        = true

  instance_type               = "t3.nano"
  availability_zone           = "us-east-1c"

  root_block_device {
    volume_size = 5
    tags = {
      Name = "some_disk_name"
    }
  }

  network_interface {
    network_interface_id = "some_interface_id"
    device_index = 0
  }

  key_name                    = "some_key_id"

  iam_instance_profile        = "some_profile_id"

  user_data = "some_rendered_user_data"

  tags = {
    Name = "request_name"
  }
}

a spot instance request should be created.

Actual Behavior

The apply command fails with response 400 from AWS, and error text mentions that network_card_index is not acceptable for a spot instance request.

This seems to be supported by the Boto documentation which states:

NetworkCardIndex (integer) – The index of the network card. Some instance types support multiple network cards. The primary network interface must be assigned to network card index 0. The default is network card index 0.

If you are using RequestSpotInstances to create Spot Instances, omit this parameter because you can’t specify the network card index when using this API. To specify the network card index, use RunInstances.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_spot_instance_request" "default" {

  ami                         = data.aws_ami.alpine.id

  spot_price                  = "0.0053"
  wait_for_fulfillment        = true

  instance_type               = "t3.nano"
  availability_zone           = "us-east-1c"

  root_block_device {
    volume_size = 5
    tags = {
      Name = "some_disk_name"
    }
  }

  network_interface {
    network_interface_id = "some_interface_id"
    device_index = 0
  }

  key_name                    = "some_key_id"

  iam_instance_profile        = "some_profile_id"

  user_data = "some_rendered_user_data"

  tags = {
    Name = "request_name"
  }
}

Steps to Reproduce

  1. with an initialised workspace
  2. run apply command
  3. observe a failure with response 400 from AWS, and error text mentions that network_card_index is not acceptable for a spot instance request.

Debug Output

A failure with response 400 from AWS, and error text mentions that network_card_index is not acceptable for a spot instance request.

This seems to be supported by the Boto documentation which states:

NetworkCardIndex (integer) – The index of the network card. Some instance types support multiple network cards. The primary network interface must be assigned to network card index 0. The default is network card index 0.

If you are using RequestSpotInstances to create Spot Instances, omit this parameter because you can’t specify the network card index when using this API. To specify the network card index, use RunInstances.

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

Yes

github-actions[bot] commented 4 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

gabrielar commented 3 months ago

This PR linked to this issue, now contains a test for the added functionality, and a copy paste of the test report for all tests for TestAccEC2Instance and TestAccEC2SpotInstanceRequest. Please let me know if anything else is needed for this PR to be merged.