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