github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/resource_aws_spot_fleet_request_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"log"
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/aws/aws-sdk-go/aws"
    11  	"github.com/aws/aws-sdk-go/service/ec2"
    12  	"github.com/hashicorp/terraform/helper/acctest"
    13  	"github.com/hashicorp/terraform/helper/resource"
    14  	"github.com/hashicorp/terraform/terraform"
    15  )
    16  
    17  func TestAccAWSSpotFleetRequest_changePriceForcesNewRequest(t *testing.T) {
    18  	var before, after ec2.SpotFleetRequestConfig
    19  	rName := acctest.RandString(10)
    20  	rInt := acctest.RandInt()
    21  
    22  	resource.Test(t, resource.TestCase{
    23  		PreCheck:     func() { testAccPreCheck(t) },
    24  		Providers:    testAccProviders,
    25  		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
    26  		Steps: []resource.TestStep{
    27  			{
    28  				Config: testAccAWSSpotFleetRequestConfig(rName, rInt),
    29  				Check: resource.ComposeAggregateTestCheckFunc(
    30  					testAccCheckAWSSpotFleetRequestExists(
    31  						"aws_spot_fleet_request.foo", &before),
    32  					resource.TestCheckResourceAttr(
    33  						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
    34  					resource.TestCheckResourceAttr(
    35  						"aws_spot_fleet_request.foo", "spot_price", "0.005"),
    36  					resource.TestCheckResourceAttr(
    37  						"aws_spot_fleet_request.foo", "launch_specification.#", "1"),
    38  				),
    39  			},
    40  			{
    41  				Config: testAccAWSSpotFleetRequestConfigChangeSpotBidPrice(rName, rInt),
    42  				Check: resource.ComposeAggregateTestCheckFunc(
    43  					testAccCheckAWSSpotFleetRequestExists(
    44  						"aws_spot_fleet_request.foo", &after),
    45  					resource.TestCheckResourceAttr(
    46  						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
    47  					resource.TestCheckResourceAttr(
    48  						"aws_spot_fleet_request.foo", "launch_specification.#", "1"),
    49  					resource.TestCheckResourceAttr(
    50  						"aws_spot_fleet_request.foo", "spot_price", "0.01"),
    51  					testAccCheckAWSSpotFleetRequestConfigRecreated(t, &before, &after),
    52  				),
    53  			},
    54  		},
    55  	})
    56  }
    57  
    58  func TestAccAWSSpotFleetRequest_lowestPriceAzOrSubnetInRegion(t *testing.T) {
    59  	var sfr ec2.SpotFleetRequestConfig
    60  	rName := acctest.RandString(10)
    61  	rInt := acctest.RandInt()
    62  
    63  	resource.Test(t, resource.TestCase{
    64  		PreCheck:     func() { testAccPreCheck(t) },
    65  		Providers:    testAccProviders,
    66  		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
    67  		Steps: []resource.TestStep{
    68  			{
    69  				Config: testAccAWSSpotFleetRequestConfig(rName, rInt),
    70  				Check: resource.ComposeAggregateTestCheckFunc(
    71  					testAccCheckAWSSpotFleetRequestExists(
    72  						"aws_spot_fleet_request.foo", &sfr),
    73  					resource.TestCheckResourceAttr(
    74  						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
    75  					resource.TestCheckResourceAttr(
    76  						"aws_spot_fleet_request.foo", "launch_specification.#", "1"),
    77  				),
    78  			},
    79  		},
    80  	})
    81  }
    82  
    83  func TestAccAWSSpotFleetRequest_lowestPriceAzInGivenList(t *testing.T) {
    84  	var sfr ec2.SpotFleetRequestConfig
    85  	rName := acctest.RandString(10)
    86  	rInt := acctest.RandInt()
    87  
    88  	resource.Test(t, resource.TestCase{
    89  		PreCheck:     func() { testAccPreCheck(t) },
    90  		Providers:    testAccProviders,
    91  		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
    92  		Steps: []resource.TestStep{
    93  			{
    94  				Config: testAccAWSSpotFleetRequestConfigWithAzs(rName, rInt),
    95  				Check: resource.ComposeAggregateTestCheckFunc(
    96  					testAccCheckAWSSpotFleetRequestExists(
    97  						"aws_spot_fleet_request.foo", &sfr),
    98  					resource.TestCheckResourceAttr(
    99  						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
   100  					resource.TestCheckResourceAttr(
   101  						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
   102  					resource.TestCheckResourceAttr(
   103  						"aws_spot_fleet_request.foo", "launch_specification.335709043.availability_zone", "us-west-2a"),
   104  					resource.TestCheckResourceAttr(
   105  						"aws_spot_fleet_request.foo", "launch_specification.1671188867.availability_zone", "us-west-2b"),
   106  				),
   107  			},
   108  		},
   109  	})
   110  }
   111  
   112  func TestAccAWSSpotFleetRequest_lowestPriceSubnetInGivenList(t *testing.T) {
   113  	var sfr ec2.SpotFleetRequestConfig
   114  	rName := acctest.RandString(10)
   115  	rInt := acctest.RandInt()
   116  
   117  	resource.Test(t, resource.TestCase{
   118  		PreCheck:     func() { testAccPreCheck(t) },
   119  		Providers:    testAccProviders,
   120  		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
   121  		Steps: []resource.TestStep{
   122  			{
   123  				Config: testAccAWSSpotFleetRequestConfigWithSubnet(rName, rInt),
   124  				Check: resource.ComposeAggregateTestCheckFunc(
   125  					testAccCheckAWSSpotFleetRequestExists(
   126  						"aws_spot_fleet_request.foo", &sfr),
   127  					resource.TestCheckResourceAttr(
   128  						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
   129  					resource.TestCheckResourceAttr(
   130  						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
   131  				),
   132  			},
   133  		},
   134  	})
   135  }
   136  
   137  func TestAccAWSSpotFleetRequest_multipleInstanceTypesInSameAz(t *testing.T) {
   138  	var sfr ec2.SpotFleetRequestConfig
   139  	rName := acctest.RandString(10)
   140  	rInt := acctest.RandInt()
   141  
   142  	resource.Test(t, resource.TestCase{
   143  		PreCheck:     func() { testAccPreCheck(t) },
   144  		Providers:    testAccProviders,
   145  		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
   146  		Steps: []resource.TestStep{
   147  			{
   148  				Config: testAccAWSSpotFleetRequestConfigMultipleInstanceTypesinSameAz(rName, rInt),
   149  				Check: resource.ComposeAggregateTestCheckFunc(
   150  					testAccCheckAWSSpotFleetRequestExists(
   151  						"aws_spot_fleet_request.foo", &sfr),
   152  					resource.TestCheckResourceAttr(
   153  						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
   154  					resource.TestCheckResourceAttr(
   155  						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
   156  					resource.TestCheckResourceAttr(
   157  						"aws_spot_fleet_request.foo", "launch_specification.335709043.instance_type", "m1.small"),
   158  					resource.TestCheckResourceAttr(
   159  						"aws_spot_fleet_request.foo", "launch_specification.335709043.availability_zone", "us-west-2a"),
   160  					resource.TestCheckResourceAttr(
   161  						"aws_spot_fleet_request.foo", "launch_specification.590403189.instance_type", "m3.large"),
   162  					resource.TestCheckResourceAttr(
   163  						"aws_spot_fleet_request.foo", "launch_specification.590403189.availability_zone", "us-west-2a"),
   164  				),
   165  			},
   166  		},
   167  	})
   168  }
   169  
   170  func TestAccAWSSpotFleetRequest_multipleInstanceTypesInSameSubnet(t *testing.T) {
   171  	var sfr ec2.SpotFleetRequestConfig
   172  	rName := acctest.RandString(10)
   173  	rInt := acctest.RandInt()
   174  
   175  	resource.Test(t, resource.TestCase{
   176  		PreCheck:     func() { testAccPreCheck(t) },
   177  		Providers:    testAccProviders,
   178  		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
   179  		Steps: []resource.TestStep{
   180  			{
   181  				Config: testAccAWSSpotFleetRequestConfigMultipleInstanceTypesinSameSubnet(rName, rInt),
   182  				Check: resource.ComposeAggregateTestCheckFunc(
   183  					testAccCheckAWSSpotFleetRequestExists(
   184  						"aws_spot_fleet_request.foo", &sfr),
   185  					resource.TestCheckResourceAttr(
   186  						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
   187  					resource.TestCheckResourceAttr(
   188  						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
   189  				),
   190  			},
   191  		},
   192  	})
   193  }
   194  
   195  func TestAccAWSSpotFleetRequest_overriddingSpotPrice(t *testing.T) {
   196  	var sfr ec2.SpotFleetRequestConfig
   197  	rName := acctest.RandString(10)
   198  	rInt := acctest.RandInt()
   199  
   200  	resource.Test(t, resource.TestCase{
   201  		PreCheck:     func() { testAccPreCheck(t) },
   202  		Providers:    testAccProviders,
   203  		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
   204  		Steps: []resource.TestStep{
   205  			{
   206  				Config: testAccAWSSpotFleetRequestConfigOverridingSpotPrice(rName, rInt),
   207  				Check: resource.ComposeAggregateTestCheckFunc(
   208  					testAccCheckAWSSpotFleetRequestExists(
   209  						"aws_spot_fleet_request.foo", &sfr),
   210  					resource.TestCheckResourceAttr(
   211  						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
   212  					resource.TestCheckResourceAttr(
   213  						"aws_spot_fleet_request.foo", "spot_price", "0.005"),
   214  					resource.TestCheckResourceAttr(
   215  						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
   216  					resource.TestCheckResourceAttr(
   217  						"aws_spot_fleet_request.foo", "launch_specification.4143232216.spot_price", "0.01"),
   218  					resource.TestCheckResourceAttr(
   219  						"aws_spot_fleet_request.foo", "launch_specification.4143232216.instance_type", "m3.large"),
   220  					resource.TestCheckResourceAttr(
   221  						"aws_spot_fleet_request.foo", "launch_specification.335709043.spot_price", ""), //there will not be a value here since it's not overriding
   222  					resource.TestCheckResourceAttr(
   223  						"aws_spot_fleet_request.foo", "launch_specification.335709043.instance_type", "m1.small"),
   224  				),
   225  			},
   226  		},
   227  	})
   228  }
   229  
   230  func TestAccAWSSpotFleetRequest_diversifiedAllocation(t *testing.T) {
   231  	var sfr ec2.SpotFleetRequestConfig
   232  	rName := acctest.RandString(10)
   233  	rInt := acctest.RandInt()
   234  
   235  	resource.Test(t, resource.TestCase{
   236  		PreCheck:     func() { testAccPreCheck(t) },
   237  		Providers:    testAccProviders,
   238  		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
   239  		Steps: []resource.TestStep{
   240  			{
   241  				Config: testAccAWSSpotFleetRequestConfigDiversifiedAllocation(rName, rInt),
   242  				Check: resource.ComposeAggregateTestCheckFunc(
   243  					testAccCheckAWSSpotFleetRequestExists(
   244  						"aws_spot_fleet_request.foo", &sfr),
   245  					resource.TestCheckResourceAttr(
   246  						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
   247  					resource.TestCheckResourceAttr(
   248  						"aws_spot_fleet_request.foo", "launch_specification.#", "3"),
   249  					resource.TestCheckResourceAttr(
   250  						"aws_spot_fleet_request.foo", "allocation_strategy", "diversified"),
   251  				),
   252  			},
   253  		},
   254  	})
   255  }
   256  
   257  func TestAccAWSSpotFleetRequest_withWeightedCapacity(t *testing.T) {
   258  	var sfr ec2.SpotFleetRequestConfig
   259  	rName := acctest.RandString(10)
   260  	rInt := acctest.RandInt()
   261  
   262  	fulfillSleep := func() resource.TestCheckFunc {
   263  		// sleep so that EC2 can fuflill the request. We do this to guard against a
   264  		// regression and possible leak where we'll destroy the request and the
   265  		// associated IAM role before anything is actually provisioned and running,
   266  		// thus leaking when those newly started instances are attempted to be
   267  		// destroyed
   268  		// See https://github.com/hashicorp/terraform/pull/8938
   269  		return func(s *terraform.State) error {
   270  			log.Print("[DEBUG] Test: Sleep to allow EC2 to actually begin fulfilling TestAccAWSSpotFleetRequest_withWeightedCapacity request")
   271  			time.Sleep(1 * time.Minute)
   272  			return nil
   273  		}
   274  	}
   275  
   276  	resource.Test(t, resource.TestCase{
   277  		PreCheck:     func() { testAccPreCheck(t) },
   278  		Providers:    testAccProviders,
   279  		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
   280  		Steps: []resource.TestStep{
   281  			{
   282  				Config: testAccAWSSpotFleetRequestConfigWithWeightedCapacity(rName, rInt),
   283  				Check: resource.ComposeAggregateTestCheckFunc(
   284  					fulfillSleep(),
   285  					testAccCheckAWSSpotFleetRequestExists(
   286  						"aws_spot_fleet_request.foo", &sfr),
   287  					resource.TestCheckResourceAttr(
   288  						"aws_spot_fleet_request.foo", "spot_request_state", "active"),
   289  					resource.TestCheckResourceAttr(
   290  						"aws_spot_fleet_request.foo", "launch_specification.#", "2"),
   291  					resource.TestCheckResourceAttr(
   292  						"aws_spot_fleet_request.foo", "launch_specification.4120185872.weighted_capacity", "3"),
   293  					resource.TestCheckResourceAttr(
   294  						"aws_spot_fleet_request.foo", "launch_specification.4120185872.instance_type", "r3.large"),
   295  					resource.TestCheckResourceAttr(
   296  						"aws_spot_fleet_request.foo", "launch_specification.590403189.weighted_capacity", "6"),
   297  					resource.TestCheckResourceAttr(
   298  						"aws_spot_fleet_request.foo", "launch_specification.590403189.instance_type", "m3.large"),
   299  				),
   300  			},
   301  		},
   302  	})
   303  }
   304  
   305  func TestAccAWSSpotFleetRequest_withEBSDisk(t *testing.T) {
   306  	var config ec2.SpotFleetRequestConfig
   307  	rName := acctest.RandString(10)
   308  	rInt := acctest.RandInt()
   309  
   310  	resource.Test(t, resource.TestCase{
   311  		PreCheck:     func() { testAccPreCheck(t) },
   312  		Providers:    testAccProviders,
   313  		CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy,
   314  		Steps: []resource.TestStep{
   315  			{
   316  				Config: testAccAWSSpotFleetRequestEBSConfig(rName, rInt),
   317  				Check: resource.ComposeAggregateTestCheckFunc(
   318  					testAccCheckAWSSpotFleetRequestExists(
   319  						"aws_spot_fleet_request.foo", &config),
   320  					testAccCheckAWSSpotFleetRequest_EBSAttributes(
   321  						&config),
   322  				),
   323  			},
   324  		},
   325  	})
   326  }
   327  
   328  func TestAccAWSSpotFleetRequest_CannotUseEmptyKeyName(t *testing.T) {
   329  	_, errs := validateSpotFleetRequestKeyName("", "key_name")
   330  	if len(errs) == 0 {
   331  		t.Fatal("Expected the key name to trigger a validation error")
   332  	}
   333  }
   334  
   335  func testAccCheckAWSSpotFleetRequestConfigRecreated(t *testing.T,
   336  	before, after *ec2.SpotFleetRequestConfig) resource.TestCheckFunc {
   337  	return func(s *terraform.State) error {
   338  		if before.SpotFleetRequestId == after.SpotFleetRequestId {
   339  			t.Fatalf("Expected change of Spot Fleet Request IDs, but both were %v", before.SpotFleetRequestId)
   340  		}
   341  		return nil
   342  	}
   343  }
   344  
   345  func testAccCheckAWSSpotFleetRequestExists(
   346  	n string, sfr *ec2.SpotFleetRequestConfig) resource.TestCheckFunc {
   347  	return func(s *terraform.State) error {
   348  		rs, ok := s.RootModule().Resources[n]
   349  		if !ok {
   350  			return fmt.Errorf("Not found: %s", n)
   351  		}
   352  
   353  		if rs.Primary.ID == "" {
   354  			return errors.New("No Spot fleet request with that id exists")
   355  		}
   356  
   357  		conn := testAccProvider.Meta().(*AWSClient).ec2conn
   358  
   359  		params := &ec2.DescribeSpotFleetRequestsInput{
   360  			SpotFleetRequestIds: []*string{&rs.Primary.ID},
   361  		}
   362  		resp, err := conn.DescribeSpotFleetRequests(params)
   363  
   364  		if err != nil {
   365  			return err
   366  		}
   367  
   368  		if v := len(resp.SpotFleetRequestConfigs); v != 1 {
   369  			return fmt.Errorf("Expected 1 request returned, got %d", v)
   370  		}
   371  
   372  		*sfr = *resp.SpotFleetRequestConfigs[0]
   373  
   374  		return nil
   375  	}
   376  }
   377  
   378  func testAccCheckAWSSpotFleetRequest_EBSAttributes(
   379  	sfr *ec2.SpotFleetRequestConfig) resource.TestCheckFunc {
   380  	return func(s *terraform.State) error {
   381  		if len(sfr.SpotFleetRequestConfig.LaunchSpecifications) == 0 {
   382  			return errors.New("Missing launch specification")
   383  		}
   384  
   385  		spec := *sfr.SpotFleetRequestConfig.LaunchSpecifications[0]
   386  
   387  		ebs := spec.BlockDeviceMappings
   388  		if len(ebs) < 2 {
   389  			return fmt.Errorf("Expected %d block device mappings, got %d", 2, len(ebs))
   390  		}
   391  
   392  		if *ebs[0].DeviceName != "/dev/xvda" {
   393  			return fmt.Errorf("Expected device 0's name to be %s, got %s", "/dev/xvda", *ebs[0].DeviceName)
   394  		}
   395  		if *ebs[1].DeviceName != "/dev/xvdcz" {
   396  			return fmt.Errorf("Expected device 1's name to be %s, got %s", "/dev/xvdcz", *ebs[1].DeviceName)
   397  		}
   398  
   399  		return nil
   400  	}
   401  }
   402  
   403  func testAccCheckAWSSpotFleetRequestDestroy(s *terraform.State) error {
   404  	conn := testAccProvider.Meta().(*AWSClient).ec2conn
   405  
   406  	for _, rs := range s.RootModule().Resources {
   407  		if rs.Type != "aws_spot_fleet_request" {
   408  			continue
   409  		}
   410  
   411  		_, err := conn.CancelSpotFleetRequests(&ec2.CancelSpotFleetRequestsInput{
   412  			SpotFleetRequestIds: []*string{aws.String(rs.Primary.ID)},
   413  			TerminateInstances:  aws.Bool(true),
   414  		})
   415  
   416  		if err != nil {
   417  			return fmt.Errorf("Error cancelling spot request (%s): %s", rs.Primary.ID, err)
   418  		}
   419  	}
   420  
   421  	return nil
   422  }
   423  
   424  func testAccAWSSpotFleetRequestConfig(rName string, rInt int) string {
   425  	return fmt.Sprintf(`
   426  resource "aws_key_pair" "debugging" {
   427  	key_name = "tmp-key-%s"
   428  	public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
   429  }
   430  
   431  resource "aws_iam_policy" "test-policy" {
   432    name = "test-policy-%d"
   433    path = "/"
   434    description = "Spot Fleet Request ACCTest Policy"
   435    policy = <<EOF
   436  {
   437    "Version": "2012-10-17",
   438    "Statement": [{
   439      "Effect": "Allow",
   440      "Action": [
   441         "ec2:DescribeImages",
   442         "ec2:DescribeSubnets",
   443         "ec2:RequestSpotInstances",
   444         "ec2:TerminateInstances",
   445         "ec2:DescribeInstanceStatus",
   446         "iam:PassRole"
   447          ],
   448      "Resource": ["*"]
   449    }]
   450  }
   451  EOF
   452  }
   453  
   454  resource "aws_iam_policy_attachment" "test-attach" {
   455      name = "test-attachment-%d"
   456      roles = ["${aws_iam_role.test-role.name}"]
   457      policy_arn = "${aws_iam_policy.test-policy.arn}"
   458  }
   459  
   460  resource "aws_iam_role" "test-role" {
   461      name = "test-role-%s"
   462      assume_role_policy = <<EOF
   463  {
   464    "Version": "2012-10-17",
   465    "Statement": [
   466      {
   467        "Sid": "",
   468        "Effect": "Allow",
   469        "Principal": {
   470          "Service": [
   471            "spotfleet.amazonaws.com",
   472            "ec2.amazonaws.com"
   473          ]
   474        },
   475        "Action": "sts:AssumeRole"
   476      }
   477    ]
   478  }
   479  EOF
   480  }
   481  
   482  resource "aws_spot_fleet_request" "foo" {
   483      iam_fleet_role = "${aws_iam_role.test-role.arn}"
   484      spot_price = "0.005"
   485      target_capacity = 2
   486      valid_until = "2019-11-04T20:44:20Z"
   487      terminate_instances_with_expiration = true
   488      launch_specification {
   489          instance_type = "m1.small"
   490          ami = "ami-d06a90b0"
   491          key_name = "${aws_key_pair.debugging.key_name}"
   492      }
   493      depends_on = ["aws_iam_policy_attachment.test-attach"]
   494  }
   495  `, rName, rInt, rInt, rName)
   496  }
   497  
   498  func testAccAWSSpotFleetRequestConfigChangeSpotBidPrice(rName string, rInt int) string {
   499  	return fmt.Sprintf(`
   500  resource "aws_key_pair" "debugging" {
   501  	key_name = "tmp-key-%s"
   502  	public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
   503  }
   504  
   505  resource "aws_iam_policy" "test-policy" {
   506    name = "test-policy-%d"
   507    path = "/"
   508    description = "Spot Fleet Request ACCTest Policy"
   509    policy = <<EOF
   510  {
   511    "Version": "2012-10-17",
   512    "Statement": [{
   513      "Effect": "Allow",
   514      "Action": [
   515         "ec2:DescribeImages",
   516         "ec2:DescribeSubnets",
   517         "ec2:RequestSpotInstances",
   518         "ec2:TerminateInstances",
   519         "ec2:DescribeInstanceStatus",
   520         "iam:PassRole"
   521          ],
   522      "Resource": ["*"]
   523    }]
   524  }
   525  EOF
   526  }
   527  
   528  resource "aws_iam_policy_attachment" "test-attach" {
   529      name = "test-attachment-%d"
   530      roles = ["${aws_iam_role.test-role.name}"]
   531      policy_arn = "${aws_iam_policy.test-policy.arn}"
   532  }
   533  
   534  resource "aws_iam_role" "test-role" {
   535      name = "test-role-%s"
   536      assume_role_policy = <<EOF
   537  {
   538    "Version": "2012-10-17",
   539    "Statement": [
   540      {
   541        "Sid": "",
   542        "Effect": "Allow",
   543        "Principal": {
   544          "Service": [
   545            "spotfleet.amazonaws.com",
   546            "ec2.amazonaws.com"
   547          ]
   548        },
   549        "Action": "sts:AssumeRole"
   550      }
   551    ]
   552  }
   553  EOF
   554  }
   555  
   556  resource "aws_spot_fleet_request" "foo" {
   557      iam_fleet_role = "${aws_iam_role.test-role.arn}"
   558      spot_price = "0.01"
   559      target_capacity = 2
   560      valid_until = "2019-11-04T20:44:20Z"
   561      terminate_instances_with_expiration = true
   562      launch_specification {
   563          instance_type = "m1.small"
   564          ami = "ami-d06a90b0"
   565          key_name = "${aws_key_pair.debugging.key_name}"
   566      }
   567      depends_on = ["aws_iam_policy_attachment.test-attach"]
   568  }
   569  `, rName, rInt, rInt, rName)
   570  }
   571  
   572  func testAccAWSSpotFleetRequestConfigWithAzs(rName string, rInt int) string {
   573  	return fmt.Sprintf(`
   574  resource "aws_key_pair" "debugging" {
   575  	key_name = "tmp-key-%s"
   576  	public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
   577  }
   578  
   579  resource "aws_iam_policy" "test-policy" {
   580    name = "test-policy-%d"
   581    path = "/"
   582    description = "Spot Fleet Request ACCTest Policy"
   583    policy = <<EOF
   584  {
   585    "Version": "2012-10-17",
   586    "Statement": [{
   587      "Effect": "Allow",
   588      "Action": [
   589         "ec2:DescribeImages",
   590         "ec2:DescribeSubnets",
   591         "ec2:RequestSpotInstances",
   592         "ec2:TerminateInstances",
   593         "ec2:DescribeInstanceStatus",
   594         "iam:PassRole"
   595          ],
   596      "Resource": ["*"]
   597    }]
   598  }
   599  EOF
   600  }
   601  
   602  resource "aws_iam_policy_attachment" "test-attach" {
   603      name = "test-attachment-%d"
   604      roles = ["${aws_iam_role.test-role.name}"]
   605      policy_arn = "${aws_iam_policy.test-policy.arn}"
   606  }
   607  
   608  resource "aws_iam_role" "test-role" {
   609      name = "test-role-%s"
   610      assume_role_policy = <<EOF
   611  {
   612    "Version": "2012-10-17",
   613    "Statement": [
   614      {
   615        "Sid": "",
   616        "Effect": "Allow",
   617        "Principal": {
   618          "Service": [
   619            "spotfleet.amazonaws.com",
   620            "ec2.amazonaws.com"
   621          ]
   622        },
   623        "Action": "sts:AssumeRole"
   624      }
   625    ]
   626  }
   627  EOF
   628  }
   629  
   630  resource "aws_spot_fleet_request" "foo" {
   631      iam_fleet_role = "${aws_iam_role.test-role.arn}"
   632      spot_price = "0.005"
   633      target_capacity = 2
   634      valid_until = "2019-11-04T20:44:20Z"
   635      terminate_instances_with_expiration = true
   636      launch_specification {
   637          instance_type = "m1.small"
   638          ami = "ami-d06a90b0"
   639          key_name = "${aws_key_pair.debugging.key_name}"
   640  	availability_zone = "us-west-2a"
   641      }
   642      launch_specification {
   643          instance_type = "m1.small"
   644          ami = "ami-d06a90b0"
   645          key_name = "${aws_key_pair.debugging.key_name}"
   646  	availability_zone = "us-west-2b"
   647      }
   648      depends_on = ["aws_iam_policy_attachment.test-attach"]
   649  }
   650  `, rName, rInt, rInt, rName)
   651  }
   652  
   653  func testAccAWSSpotFleetRequestConfigWithSubnet(rName string, rInt int) string {
   654  	return fmt.Sprintf(`
   655  resource "aws_key_pair" "debugging" {
   656  	key_name = "tmp-key-%s"
   657  	public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
   658  }
   659  
   660  resource "aws_iam_policy" "test-policy" {
   661    name = "test-policy-%d"
   662    path = "/"
   663    description = "Spot Fleet Request ACCTest Policy"
   664    policy = <<EOF
   665  {
   666    "Version": "2012-10-17",
   667    "Statement": [{
   668      "Effect": "Allow",
   669      "Action": [
   670         "ec2:DescribeImages",
   671         "ec2:DescribeSubnets",
   672         "ec2:RequestSpotInstances",
   673         "ec2:TerminateInstances",
   674         "ec2:DescribeInstanceStatus",
   675         "iam:PassRole"
   676          ],
   677      "Resource": ["*"]
   678    }]
   679  }
   680  EOF
   681  }
   682  
   683  resource "aws_iam_policy_attachment" "test-attach" {
   684      name = "test-attachment-%d"
   685      roles = ["${aws_iam_role.test-role.name}"]
   686      policy_arn = "${aws_iam_policy.test-policy.arn}"
   687  }
   688  
   689  resource "aws_iam_role" "test-role" {
   690      name = "test-role-%s"
   691      assume_role_policy = <<EOF
   692  {
   693    "Version": "2012-10-17",
   694    "Statement": [
   695      {
   696        "Sid": "",
   697        "Effect": "Allow",
   698        "Principal": {
   699          "Service": [
   700            "spotfleet.amazonaws.com",
   701            "ec2.amazonaws.com"
   702          ]
   703        },
   704        "Action": "sts:AssumeRole"
   705      }
   706    ]
   707  }
   708  EOF
   709  }
   710  
   711  resource "aws_vpc" "foo" {
   712      cidr_block = "10.1.0.0/16"
   713  }
   714  
   715  resource "aws_subnet" "foo" {
   716      cidr_block = "10.1.1.0/24"
   717      vpc_id = "${aws_vpc.foo.id}"
   718      availability_zone = "us-west-2a"
   719  }
   720  
   721  resource "aws_subnet" "bar" {
   722      cidr_block = "10.1.20.0/24"
   723      vpc_id = "${aws_vpc.foo.id}"
   724      availability_zone = "us-west-2b"
   725  }
   726  
   727  resource "aws_spot_fleet_request" "foo" {
   728      iam_fleet_role = "${aws_iam_role.test-role.arn}"
   729      spot_price = "0.005"
   730      target_capacity = 4
   731      valid_until = "2019-11-04T20:44:20Z"
   732      terminate_instances_with_expiration = true
   733      launch_specification {
   734          instance_type = "m3.large"
   735          ami = "ami-d0f506b0"
   736          key_name = "${aws_key_pair.debugging.key_name}"
   737  	subnet_id = "${aws_subnet.foo.id}"
   738      }
   739      launch_specification {
   740          instance_type = "m3.large"
   741          ami = "ami-d0f506b0"
   742          key_name = "${aws_key_pair.debugging.key_name}"
   743  	subnet_id = "${aws_subnet.bar.id}"
   744      }
   745      depends_on = ["aws_iam_policy_attachment.test-attach"]
   746  }
   747  `, rName, rInt, rInt, rName)
   748  }
   749  
   750  func testAccAWSSpotFleetRequestConfigMultipleInstanceTypesinSameAz(rName string, rInt int) string {
   751  	return fmt.Sprintf(`
   752  resource "aws_key_pair" "debugging" {
   753  	key_name = "tmp-key-%s"
   754  	public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
   755  }
   756  
   757  resource "aws_iam_policy" "test-policy" {
   758    name = "test-policy-%d"
   759    path = "/"
   760    description = "Spot Fleet Request ACCTest Policy"
   761    policy = <<EOF
   762  {
   763    "Version": "2012-10-17",
   764    "Statement": [{
   765      "Effect": "Allow",
   766      "Action": [
   767         "ec2:DescribeImages",
   768         "ec2:DescribeSubnets",
   769         "ec2:RequestSpotInstances",
   770         "ec2:TerminateInstances",
   771         "ec2:DescribeInstanceStatus",
   772         "iam:PassRole"
   773          ],
   774      "Resource": ["*"]
   775    }]
   776  }
   777  EOF
   778  }
   779  
   780  resource "aws_iam_policy_attachment" "test-attach" {
   781      name = "test-attachment-%d"
   782      roles = ["${aws_iam_role.test-role.name}"]
   783      policy_arn = "${aws_iam_policy.test-policy.arn}"
   784  }
   785  
   786  resource "aws_iam_role" "test-role" {
   787      name = "test-role-%s"
   788      assume_role_policy = <<EOF
   789  {
   790    "Version": "2012-10-17",
   791    "Statement": [
   792      {
   793        "Sid": "",
   794        "Effect": "Allow",
   795        "Principal": {
   796          "Service": [
   797            "spotfleet.amazonaws.com",
   798            "ec2.amazonaws.com"
   799          ]
   800        },
   801        "Action": "sts:AssumeRole"
   802      }
   803    ]
   804  }
   805  EOF
   806  }
   807  
   808  resource "aws_spot_fleet_request" "foo" {
   809      iam_fleet_role = "${aws_iam_role.test-role.arn}"
   810      spot_price = "0.005"
   811      target_capacity = 2
   812      valid_until = "2019-11-04T20:44:20Z"
   813      terminate_instances_with_expiration = true
   814      launch_specification {
   815          instance_type = "m1.small"
   816          ami = "ami-d06a90b0"
   817          key_name = "${aws_key_pair.debugging.key_name}"
   818          availability_zone = "us-west-2a"
   819      }
   820      launch_specification {
   821          instance_type = "m3.large"
   822          ami = "ami-d06a90b0"
   823          key_name = "${aws_key_pair.debugging.key_name}"
   824          availability_zone = "us-west-2a"
   825      }
   826      depends_on = ["aws_iam_policy_attachment.test-attach"]
   827  }
   828  `, rName, rInt, rInt, rName)
   829  }
   830  
   831  func testAccAWSSpotFleetRequestConfigMultipleInstanceTypesinSameSubnet(rName string, rInt int) string {
   832  	return fmt.Sprintf(`
   833  resource "aws_key_pair" "debugging" {
   834  	key_name = "tmp-key-%s"
   835  	public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
   836  }
   837  
   838  resource "aws_iam_policy" "test-policy" {
   839    name = "test-policy-%d"
   840    path = "/"
   841    description = "Spot Fleet Request ACCTest Policy"
   842    policy = <<EOF
   843  {
   844    "Version": "2012-10-17",
   845    "Statement": [{
   846      "Effect": "Allow",
   847      "Action": [
   848         "ec2:DescribeImages",
   849         "ec2:DescribeSubnets",
   850         "ec2:RequestSpotInstances",
   851         "ec2:TerminateInstances",
   852         "ec2:DescribeInstanceStatus",
   853         "iam:PassRole"
   854          ],
   855      "Resource": ["*"]
   856    }]
   857  }
   858  EOF
   859  }
   860  
   861  resource "aws_iam_policy_attachment" "test-attach" {
   862      name = "test-attachment-%d"
   863      roles = ["${aws_iam_role.test-role.name}"]
   864      policy_arn = "${aws_iam_policy.test-policy.arn}"
   865  }
   866  
   867  resource "aws_iam_role" "test-role" {
   868      name = "test-role-%s"
   869      assume_role_policy = <<EOF
   870  {
   871    "Version": "2012-10-17",
   872    "Statement": [
   873      {
   874        "Sid": "",
   875        "Effect": "Allow",
   876        "Principal": {
   877          "Service": [
   878            "spotfleet.amazonaws.com",
   879            "ec2.amazonaws.com"
   880          ]
   881        },
   882        "Action": "sts:AssumeRole"
   883      }
   884    ]
   885  }
   886  EOF
   887  }
   888  
   889  resource "aws_vpc" "foo" {
   890      cidr_block = "10.1.0.0/16"
   891  }
   892  
   893  resource "aws_subnet" "foo" {
   894      cidr_block = "10.1.1.0/24"
   895      vpc_id = "${aws_vpc.foo.id}"
   896      availability_zone = "us-west-2a"
   897  }
   898  
   899  resource "aws_spot_fleet_request" "foo" {
   900      iam_fleet_role = "${aws_iam_role.test-role.arn}"
   901      spot_price = "0.005"
   902      target_capacity = 4
   903      valid_until = "2019-11-04T20:44:20Z"
   904      terminate_instances_with_expiration = true
   905      launch_specification {
   906          instance_type = "m3.large"
   907          ami = "ami-d0f506b0"
   908          key_name = "${aws_key_pair.debugging.key_name}"
   909  	subnet_id = "${aws_subnet.foo.id}"
   910      }
   911      launch_specification {
   912          instance_type = "r3.large"
   913          ami = "ami-d0f506b0"
   914          key_name = "${aws_key_pair.debugging.key_name}"
   915  	subnet_id = "${aws_subnet.foo.id}"
   916      }
   917      depends_on = ["aws_iam_policy_attachment.test-attach"]
   918  }
   919  `, rName, rInt, rInt, rName)
   920  }
   921  
   922  func testAccAWSSpotFleetRequestConfigOverridingSpotPrice(rName string, rInt int) string {
   923  	return fmt.Sprintf(`
   924  resource "aws_key_pair" "debugging" {
   925  	key_name = "tmp-key-%s"
   926  	public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
   927  }
   928  
   929  resource "aws_iam_policy" "test-policy" {
   930    name = "test-policy-%d"
   931    path = "/"
   932    description = "Spot Fleet Request ACCTest Policy"
   933    policy = <<EOF
   934  {
   935    "Version": "2012-10-17",
   936    "Statement": [{
   937      "Effect": "Allow",
   938      "Action": [
   939         "ec2:DescribeImages",
   940         "ec2:DescribeSubnets",
   941         "ec2:RequestSpotInstances",
   942         "ec2:TerminateInstances",
   943         "ec2:DescribeInstanceStatus",
   944         "iam:PassRole"
   945          ],
   946      "Resource": ["*"]
   947    }]
   948  }
   949  EOF
   950  }
   951  
   952  resource "aws_iam_policy_attachment" "test-attach" {
   953      name = "test-attachment-%d"
   954      roles = ["${aws_iam_role.test-role.name}"]
   955      policy_arn = "${aws_iam_policy.test-policy.arn}"
   956  }
   957  
   958  resource "aws_iam_role" "test-role" {
   959      name = "test-role-%s"
   960      assume_role_policy = <<EOF
   961  {
   962    "Version": "2012-10-17",
   963    "Statement": [
   964      {
   965        "Sid": "",
   966        "Effect": "Allow",
   967        "Principal": {
   968          "Service": [
   969            "spotfleet.amazonaws.com",
   970            "ec2.amazonaws.com"
   971          ]
   972        },
   973        "Action": "sts:AssumeRole"
   974      }
   975    ]
   976  }
   977  EOF
   978  }
   979  
   980  resource "aws_spot_fleet_request" "foo" {
   981      iam_fleet_role = "${aws_iam_role.test-role.arn}"
   982      spot_price = "0.005"
   983      target_capacity = 2
   984      valid_until = "2019-11-04T20:44:20Z"
   985      terminate_instances_with_expiration = true
   986      launch_specification {
   987          instance_type = "m1.small"
   988          ami = "ami-d06a90b0"
   989          key_name = "${aws_key_pair.debugging.key_name}"
   990          availability_zone = "us-west-2a"
   991      }
   992      launch_specification {
   993          instance_type = "m3.large"
   994          ami = "ami-d06a90b0"
   995          key_name = "${aws_key_pair.debugging.key_name}"
   996          availability_zone = "us-west-2a"
   997          spot_price = "0.01"
   998      }
   999      depends_on = ["aws_iam_policy_attachment.test-attach"]
  1000  }
  1001  `, rName, rInt, rInt, rName)
  1002  }
  1003  
  1004  func testAccAWSSpotFleetRequestConfigDiversifiedAllocation(rName string, rInt int) string {
  1005  	return fmt.Sprintf(`
  1006  resource "aws_key_pair" "debugging" {
  1007  	key_name = "tmp-key-%s"
  1008  	public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
  1009  }
  1010  
  1011  resource "aws_iam_policy" "test-policy" {
  1012    name = "test-policy-%d"
  1013    path = "/"
  1014    description = "Spot Fleet Request ACCTest Policy"
  1015    policy = <<EOF
  1016  {
  1017    "Version": "2012-10-17",
  1018    "Statement": [{
  1019      "Effect": "Allow",
  1020      "Action": [
  1021         "ec2:DescribeImages",
  1022         "ec2:DescribeSubnets",
  1023         "ec2:RequestSpotInstances",
  1024         "ec2:TerminateInstances",
  1025         "ec2:DescribeInstanceStatus",
  1026         "iam:PassRole"
  1027          ],
  1028      "Resource": ["*"]
  1029    }]
  1030  }
  1031  EOF
  1032  }
  1033  
  1034  resource "aws_iam_policy_attachment" "test-attach" {
  1035      name = "test-attachment-%d"
  1036      roles = ["${aws_iam_role.test-role.name}"]
  1037      policy_arn = "${aws_iam_policy.test-policy.arn}"
  1038  }
  1039  
  1040  resource "aws_iam_role" "test-role" {
  1041      name = "test-role-%s"
  1042      assume_role_policy = <<EOF
  1043  {
  1044    "Version": "2012-10-17",
  1045    "Statement": [
  1046      {
  1047        "Sid": "",
  1048        "Effect": "Allow",
  1049        "Principal": {
  1050          "Service": [
  1051            "spotfleet.amazonaws.com",
  1052            "ec2.amazonaws.com"
  1053          ]
  1054        },
  1055        "Action": "sts:AssumeRole"
  1056      }
  1057    ]
  1058  }
  1059  EOF
  1060  }
  1061  
  1062  resource "aws_spot_fleet_request" "foo" {
  1063      iam_fleet_role = "${aws_iam_role.test-role.arn}"
  1064      spot_price = "0.7"
  1065      target_capacity = 30
  1066      valid_until = "2019-11-04T20:44:20Z"
  1067      allocation_strategy = "diversified"
  1068      terminate_instances_with_expiration = true
  1069      launch_specification {
  1070          instance_type = "m1.small"
  1071          ami = "ami-d06a90b0"
  1072          key_name = "${aws_key_pair.debugging.key_name}"
  1073          availability_zone = "us-west-2a"
  1074      }
  1075      launch_specification {
  1076          instance_type = "m3.large"
  1077          ami = "ami-d06a90b0"
  1078          key_name = "${aws_key_pair.debugging.key_name}"
  1079          availability_zone = "us-west-2a"
  1080      }
  1081      launch_specification {
  1082          instance_type = "r3.large"
  1083          ami = "ami-d06a90b0"
  1084          key_name = "${aws_key_pair.debugging.key_name}"
  1085          availability_zone = "us-west-2a"
  1086      }
  1087      depends_on = ["aws_iam_policy_attachment.test-attach"]
  1088  }
  1089  `, rName, rInt, rInt, rName)
  1090  }
  1091  
  1092  func testAccAWSSpotFleetRequestConfigWithWeightedCapacity(rName string, rInt int) string {
  1093  	return fmt.Sprintf(`
  1094  resource "aws_key_pair" "debugging" {
  1095  	key_name = "tmp-key-%s"
  1096  	public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
  1097  }
  1098  
  1099  resource "aws_iam_policy" "test-policy" {
  1100    name = "test-policy-%d"
  1101    path = "/"
  1102    description = "Spot Fleet Request ACCTest Policy"
  1103    policy = <<EOF
  1104  {
  1105    "Version": "2012-10-17",
  1106    "Statement": [{
  1107      "Effect": "Allow",
  1108      "Action": [
  1109         "ec2:DescribeImages",
  1110         "ec2:DescribeSubnets",
  1111         "ec2:RequestSpotInstances",
  1112         "ec2:TerminateInstances",
  1113         "ec2:DescribeInstanceStatus",
  1114         "iam:PassRole"
  1115          ],
  1116      "Resource": ["*"]
  1117    }]
  1118  }
  1119  EOF
  1120  }
  1121  
  1122  resource "aws_iam_policy_attachment" "test-attach" {
  1123      name = "test-attachment-%d"
  1124      roles = ["${aws_iam_role.test-role.name}"]
  1125      policy_arn = "${aws_iam_policy.test-policy.arn}"
  1126  }
  1127  
  1128  resource "aws_iam_role" "test-role" {
  1129      name = "test-role-%s"
  1130      assume_role_policy = <<EOF
  1131  {
  1132    "Version": "2012-10-17",
  1133    "Statement": [
  1134      {
  1135        "Sid": "",
  1136        "Effect": "Allow",
  1137        "Principal": {
  1138          "Service": [
  1139            "spotfleet.amazonaws.com",
  1140            "ec2.amazonaws.com"
  1141          ]
  1142        },
  1143        "Action": "sts:AssumeRole"
  1144      }
  1145    ]
  1146  }
  1147  EOF
  1148  }
  1149  
  1150  resource "aws_spot_fleet_request" "foo" {
  1151      iam_fleet_role = "${aws_iam_role.test-role.arn}"
  1152      spot_price = "0.7"
  1153      target_capacity = 10
  1154      valid_until = "2019-11-04T20:44:20Z"
  1155      terminate_instances_with_expiration = true
  1156      launch_specification {
  1157          instance_type = "m3.large"
  1158          ami = "ami-d06a90b0"
  1159          key_name = "${aws_key_pair.debugging.key_name}"
  1160          availability_zone = "us-west-2a"
  1161          weighted_capacity = "6"
  1162      }
  1163      launch_specification {
  1164          instance_type = "r3.large"
  1165          ami = "ami-d06a90b0"
  1166          key_name = "${aws_key_pair.debugging.key_name}"
  1167          availability_zone = "us-west-2a"
  1168          weighted_capacity = "3"
  1169      }
  1170      depends_on = ["aws_iam_policy_attachment.test-attach"]
  1171  }
  1172  `, rName, rInt, rInt, rName)
  1173  }
  1174  
  1175  func testAccAWSSpotFleetRequestEBSConfig(rName string, rInt int) string {
  1176  	return fmt.Sprintf(`
  1177  resource "aws_iam_policy" "test-policy" {
  1178    name = "test-policy-%d"
  1179    path = "/"
  1180    description = "Spot Fleet Request ACCTest Policy"
  1181    policy = <<EOF
  1182  {
  1183    "Version": "2012-10-17",
  1184    "Statement": [{
  1185      "Effect": "Allow",
  1186      "Action": [
  1187         "ec2:DescribeImages",
  1188         "ec2:DescribeSubnets",
  1189         "ec2:RequestSpotInstances",
  1190         "ec2:TerminateInstances",
  1191         "ec2:DescribeInstanceStatus",
  1192         "iam:PassRole"
  1193          ],
  1194      "Resource": ["*"]
  1195    }]
  1196  }
  1197  EOF
  1198  }
  1199  
  1200  resource "aws_iam_policy_attachment" "test-attach" {
  1201      name = "test-attachment-%d"
  1202      roles = ["${aws_iam_role.test-role.name}"]
  1203      policy_arn = "${aws_iam_policy.test-policy.arn}"
  1204  }
  1205  
  1206  resource "aws_iam_role" "test-role" {
  1207      name = "test-role-%s"
  1208      assume_role_policy = <<EOF
  1209  {
  1210    "Version": "2012-10-17",
  1211    "Statement": [
  1212      {
  1213        "Sid": "",
  1214        "Effect": "Allow",
  1215        "Principal": {
  1216          "Service": [
  1217            "spotfleet.amazonaws.com",
  1218            "ec2.amazonaws.com"
  1219          ]
  1220        },
  1221        "Action": "sts:AssumeRole"
  1222      }
  1223    ]
  1224  }
  1225  EOF
  1226  }
  1227  
  1228  resource "aws_spot_fleet_request" "foo" {
  1229      iam_fleet_role = "${aws_iam_role.test-role.arn}"
  1230      spot_price = "0.005"
  1231      target_capacity = 1
  1232      valid_until = "2019-11-04T20:44:20Z"
  1233      terminate_instances_with_expiration = true
  1234      launch_specification {
  1235          instance_type = "m1.small"
  1236          ami = "ami-d06a90b0"
  1237  
  1238  	ebs_block_device {
  1239              device_name = "/dev/xvda"
  1240  	    volume_type = "gp2"
  1241  	    volume_size = "8"
  1242          }
  1243  	
  1244  	ebs_block_device {
  1245              device_name = "/dev/xvdcz"
  1246  	    volume_type = "gp2"
  1247  	    volume_size = "100"
  1248          }
  1249      }
  1250      depends_on = ["aws_iam_policy_attachment.test-attach"]
  1251  }
  1252  `, rInt, rInt, rName)
  1253  }