diff --git a/builtin/providers/aws/resource_aws_spot_fleet_request.go b/builtin/providers/aws/resource_aws_spot_fleet_request.go index 7fb1a05ef8..669a8239aa 100644 --- a/builtin/providers/aws/resource_aws_spot_fleet_request.go +++ b/builtin/providers/aws/resource_aws_spot_fleet_request.go @@ -290,6 +290,13 @@ func resourceAwsSpotFleetRequest() *schema.Resource { func buildSpotFleetLaunchSpecification(d map[string]interface{}, meta interface{}) (*ec2.SpotFleetLaunchSpecification, error) { conn := meta.(*AWSClient).ec2conn + + _, hasSubnet := d["subnet_id"] + _, hasAZ := d["availability_zone"] + if !hasAZ && !hasSubnet { + return nil, fmt.Errorf("LaunchSpecification must include a subnet_id or an availability_zone") + } + opts := &ec2.SpotFleetLaunchSpecification{ ImageId: aws.String(d["ami"].(string)), InstanceType: aws.String(d["instance_type"].(string)), @@ -938,12 +945,6 @@ func hashLaunchSpecification(v interface{}) int { buf.WriteString(fmt.Sprintf("%s-", m["availability_zone"].(string))) } else if m["subnet_id"] != nil && m["subnet_id"] != "" { buf.WriteString(fmt.Sprintf("%s-", m["subnet_id"].(string))) - } else { - panic( - fmt.Sprintf( - "Must set one of:\navailability_zone %#v\nsubnet_id: %#v", - m["availability_zone"], - m["subnet_id"])) } buf.WriteString(fmt.Sprintf("%s-", m["instance_type"].(string))) buf.WriteString(fmt.Sprintf("%s-", m["spot_price"].(string))) diff --git a/builtin/providers/aws/resource_aws_spot_fleet_request_test.go b/builtin/providers/aws/resource_aws_spot_fleet_request_test.go index d6a2968e6d..ccb240542d 100644 --- a/builtin/providers/aws/resource_aws_spot_fleet_request_test.go +++ b/builtin/providers/aws/resource_aws_spot_fleet_request_test.go @@ -3,6 +3,7 @@ package aws import ( "encoding/base64" "fmt" + "regexp" "testing" "github.com/aws/aws-sdk-go/aws" @@ -33,6 +34,20 @@ func TestAccAWSSpotFleetRequest_basic(t *testing.T) { }) } +func TestAccAWSSpotFleetRequest_brokenLaunchSpecification(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSSpotFleetRequestConfigBroken, + ExpectError: regexp.MustCompile("LaunchSpecification must include a subnet_id or an availability_zone"), + }, + }, + }) +} + func TestAccAWSSpotFleetRequest_launchConfiguration(t *testing.T) { var sfr ec2.SpotFleetRequestConfig @@ -208,6 +223,51 @@ resource "aws_spot_fleet_request" "foo" { } ` +const testAccAWSSpotFleetRequestConfigBroken = ` +resource "aws_key_pair" "debugging" { + key_name = "tmp-key" + public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" +} + +resource "aws_iam_policy_attachment" "test-attach" { + name = "test-attachment" + roles = ["${aws_iam_role.test-role.name}"] + policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2SpotFleetRole" +} + +resource "aws_iam_role" "test-role" { + name = "test-role" + assume_role_policy = <