Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when importing aws_spot_fleet_request #13567

Closed
aniaptebsft opened this issue Jun 1, 2020 · 6 comments · Fixed by #13577
Closed

Crash when importing aws_spot_fleet_request #13567

aniaptebsft opened this issue Jun 1, 2020 · 6 comments · Fixed by #13577
Assignees
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@aniaptebsft
Copy link

Terraform Version

Terraform version: 0.12.25
Go runtime version: go1.12.13

Terraform Configuration Files

provider "aws" {
	region = "us-west-2"
}

terraform {
  backend "s3" {
    bucket = "xxx"
    key    = "spot_fleets/fleet1"
    region = "us-west-2"
  }
}

resource "aws_spot_fleet_request" "fleet" {
  # ...instance configuration...
}

Debug Output

Crash Output

https://gist.github.com/aniaptebsft/eeec63169393a4475c9c8d2cd35a8c14

Expected Behavior

TF shouldn't have crashed, it should have imported the spot fleet request.

Actual Behavior

Terraform crashed, below are the top few lines of the crash
panic: interface conversion: interface {} is nil, not string 2020-06-01T08:38:18.956Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: 2020-06-01T08:38:18.956Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: goroutine 69 [running]: 2020-06-01T08:38:18.956Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: github.com/terraform-providers/terraform-provider-aws/aws.hashLaunchSpecification(0x4d37480, 0xc0009669c0, 0x1) 2020-06-01T08:38:18.956Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_spot_fleet_request.go:1610 +0x6d9 2020-06-01T08:38:18.956Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Set).hash(0xc000c99040, 0x4d37480, 0xc0009669c0, 0x417ae13, 0x4d37480) 2020-06-01T08:38:18.956Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/set.go:254 +0x3d 2020-06-01T08:38:18.956Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Set).add(0xc000c99040, 0x4d37480, 0xc0009669c0, 0xc00092f900, 0x0, 0x0) 2020-06-01T08:38:18.956Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/set.go:231 +0x83 2020-06-01T08:38:18.956Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Set).Add(...) 2020-06-01T08:38:18.957Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/set.go:75 2020-06-01T08:38:18.957Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: github.com/terraform-providers/terraform-provider-aws/aws.launchSpecsToSet(0xc000921740, 0xc, 0xc, 0xc000a484f0, 0xc000eb2400, 0x0, 0x0) 2020-06-01T08:38:18.957Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_spot_fleet_request.go:1276 +0x7b 2020-06-01T08:38:18.957Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsSpotFleetRequestRead(0xc000cd89a0, 0x4f27dc0, 0xc000140f00, 0xc000cd89a0, 0x0) 2020-06-01T08:38:18.957Z [DEBUG] plugin.terraform-provider-aws_v2.64.0_x4: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_spot_fleet_request.go:1193 +0x43f

Steps to Reproduce

  1. terraform init
  2. terraform import aws_spot_fleet_request.fleet sfr-XXX

Additional Context

None

References

None

@ghost ghost added service/ec2 Issues and PRs that pertain to the ec2 service. bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. labels Jun 1, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Jun 1, 2020
@ewbankkit
Copy link
Contributor

ewbankkit commented Jun 1, 2020

In the acceptance tests (e.g. TestAccAWSSpotFleetRequest_basic), the AZ is returned as an empty string, not nil

<DescribeSpotFleetRequestsResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
    <requestId>e2b6b2b2-821c-48a5-a761-6aee39be1e87</requestId>
    <spotFleetRequestConfigSet>
        <item>
            <activityStatus>pending_fulfillment</activityStatus>
            <createTime>2020-06-01T13:48:28.705Z</createTime>
            <spotFleetRequestConfig>
                <allocationStrategy>lowestPrice</allocationStrategy>
                <clientToken>terraform-20200601134817201100000002</clientToken>
                <excessCapacityTerminationPolicy>Default</excessCapacityTerminationPolicy>
                <fulfilledCapacity>0.0</fulfilledCapacity>
                <iamFleetRole>arn:aws:iam::123456789012:role/rs6rguqo3t</iamFleetRole>
                <instanceInterruptionBehavior>stop</instanceInterruptionBehavior>
                <instancePoolsToUseCount>1</instancePoolsToUseCount>
                <launchSpecifications>
                    <item>
                        <ebsOptimized>false</ebsOptimized>
                        <iamInstanceProfile>
                            <name/>
                        </iamInstanceProfile>
                        <imageId>ami-516b9131</imageId>
                        <instanceType>m1.small</instanceType>
                        <keyName>rs6rguqo3t</keyName>
                        <monitoring>
                            <enabled>false</enabled>
                        </monitoring>
                        <placement>
                            <availabilityZone/>
                            <tenancy/>
                        </placement>
                        <spotPrice/>
                        <subnetId/>
                        <userData/>
                    </item>
                </launchSpecifications>
                <onDemandAllocationStrategy>lowestPrice</onDemandAllocationStrategy>
                <onDemandFulfilledCapacity>0.0</onDemandFulfilledCapacity>
                <onDemandTargetCapacity>0</onDemandTargetCapacity>
                <replaceUnhealthyInstances>false</replaceUnhealthyInstances>
                <spotPrice>0.005</spotPrice>
                <targetCapacity>2</targetCapacity>
                <terminateInstancesWithExpiration>true</terminateInstancesWithExpiration>
                <type>maintain</type>
                <validUntil>2020-06-02T13:48:05.000Z</validUntil>
            </spotFleetRequestConfig>
            <spotFleetRequestId>sfr-9bd21fcc-a727-437a-8f6a-e7f969d31c30</spotFleetRequestId>
            <spotFleetRequestState>active</spotFleetRequestState>
        </item>
    </spotFleetRequestConfigSet>
</DescribeSpotFleetRequestsResponse>

whereas in the linked gist, the whole <placement></placement> section is missing, meaning m["availability_zone"] is nil

https://github.com/terraform-providers/terraform-provider-aws/blob/934b07ac2dc27a97e041e5f8558d2dd3bf369ae1/aws/resource_aws_spot_fleet_request.go#L1324-L1326

This is because when the resource is created the placement block is present (but with empty strings):

2020/06/01 09:48:17 [DEBUG] Requesting spot fleet with these opts: {
  DryRun: false,
  SpotFleetRequestConfig: {
    AllocationStrategy: "lowestPrice",
    ClientToken: "terraform-20200601134817201100000002",
    ExcessCapacityTerminationPolicy: "Default",
    IamFleetRole: "arn:aws:iam::123456789012:role/rs6rguqo3t",
    InstanceInterruptionBehavior: "stop",
    LaunchSpecifications: [{
        EbsOptimized: false,
        IamInstanceProfile: {
          Name: ""
        },
        ImageId: "ami-516b9131",
        InstanceType: "m1.small",
        KeyName: "rs6rguqo3t",
        Monitoring: {
          Enabled: false
        },
        Placement: {
          AvailabilityZone: "",
          Tenancy: ""
        },
        SpotPrice: "",
        SubnetId: "",
        UserData: ""
      }],
    ReplaceUnhealthyInstances: false,
    SpotPrice: "0.005",
    TargetCapacity: 2,
    TerminateInstancesWithExpiration: true,
    Type: "maintain",
    ValidUntil: 2020-06-02 13:48:05 +0000 UTC
  }
}

The solution is to check for nil, not "".
This is how it's done in hashLaunchTemplateOverrides:

https://github.com/terraform-providers/terraform-provider-aws/blob/934b07ac2dc27a97e041e5f8558d2dd3bf369ae1/aws/resource_aws_spot_fleet_request.go#L1620-L1643

@ewbankkit ewbankkit removed the needs-triage Waiting for first response or review from a maintainer. label Jun 1, 2020
@ewbankkit ewbankkit self-assigned this Jun 2, 2020
@sowmitranalla
Copy link

Terraform crashed for me too when refreshing spot fleet request state. This happened with aws provider 2.64.0. Rolled it back to 2.57.0 and things worked without a hitch.

@bflad bflad added this to the v2.68.0 milestone Jun 24, 2020
@bflad
Copy link
Contributor

bflad commented Jun 24, 2020

The fix for this has been merged and will release with version 2.68.0 of the Terraform AWS Provider, likely tomorrow. Thanks to @ewbankkit for the investigation and fix implementation. 👍

@ghost
Copy link

ghost commented Jun 26, 2020

This has been released in version 2.68.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Jul 24, 2020

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!

@ghost ghost locked and limited conversation to collaborators Jul 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
4 participants