github.com/bradfeehan/terraform@v0.7.0-rc3.0.20170529055808-34b45c5ad841/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_placementTenancy(t *testing.T) { 329 var sfr ec2.SpotFleetRequestConfig 330 rName := acctest.RandString(10) 331 rInt := acctest.RandInt() 332 333 resource.Test(t, resource.TestCase{ 334 PreCheck: func() { testAccPreCheck(t) }, 335 Providers: testAccProviders, 336 CheckDestroy: testAccCheckAWSSpotFleetRequestDestroy, 337 Steps: []resource.TestStep{ 338 { 339 Config: testAccAWSSpotFleetRequestTenancyConfig(rName, rInt), 340 Check: resource.ComposeAggregateTestCheckFunc( 341 testAccCheckAWSSpotFleetRequestExists( 342 "aws_spot_fleet_request.foo", &sfr), 343 resource.TestCheckResourceAttr( 344 "aws_spot_fleet_request.foo", "spot_request_state", "active"), 345 testAccCheckAWSSpotFleetRequest_PlacementAttributes(&sfr), 346 ), 347 }, 348 }, 349 }) 350 } 351 352 func TestAccAWSSpotFleetRequest_CannotUseEmptyKeyName(t *testing.T) { 353 _, errs := validateSpotFleetRequestKeyName("", "key_name") 354 if len(errs) == 0 { 355 t.Fatal("Expected the key name to trigger a validation error") 356 } 357 } 358 359 func testAccCheckAWSSpotFleetRequestConfigRecreated(t *testing.T, 360 before, after *ec2.SpotFleetRequestConfig) resource.TestCheckFunc { 361 return func(s *terraform.State) error { 362 if before.SpotFleetRequestId == after.SpotFleetRequestId { 363 t.Fatalf("Expected change of Spot Fleet Request IDs, but both were %v", before.SpotFleetRequestId) 364 } 365 return nil 366 } 367 } 368 369 func testAccCheckAWSSpotFleetRequestExists( 370 n string, sfr *ec2.SpotFleetRequestConfig) resource.TestCheckFunc { 371 return func(s *terraform.State) error { 372 rs, ok := s.RootModule().Resources[n] 373 if !ok { 374 return fmt.Errorf("Not found: %s", n) 375 } 376 377 if rs.Primary.ID == "" { 378 return errors.New("No Spot fleet request with that id exists") 379 } 380 381 conn := testAccProvider.Meta().(*AWSClient).ec2conn 382 383 params := &ec2.DescribeSpotFleetRequestsInput{ 384 SpotFleetRequestIds: []*string{&rs.Primary.ID}, 385 } 386 resp, err := conn.DescribeSpotFleetRequests(params) 387 388 if err != nil { 389 return err 390 } 391 392 if v := len(resp.SpotFleetRequestConfigs); v != 1 { 393 return fmt.Errorf("Expected 1 request returned, got %d", v) 394 } 395 396 *sfr = *resp.SpotFleetRequestConfigs[0] 397 398 return nil 399 } 400 } 401 402 func testAccCheckAWSSpotFleetRequest_EBSAttributes( 403 sfr *ec2.SpotFleetRequestConfig) resource.TestCheckFunc { 404 return func(s *terraform.State) error { 405 if len(sfr.SpotFleetRequestConfig.LaunchSpecifications) == 0 { 406 return errors.New("Missing launch specification") 407 } 408 409 spec := *sfr.SpotFleetRequestConfig.LaunchSpecifications[0] 410 411 ebs := spec.BlockDeviceMappings 412 if len(ebs) < 2 { 413 return fmt.Errorf("Expected %d block device mappings, got %d", 2, len(ebs)) 414 } 415 416 if *ebs[0].DeviceName != "/dev/xvda" { 417 return fmt.Errorf("Expected device 0's name to be %s, got %s", "/dev/xvda", *ebs[0].DeviceName) 418 } 419 if *ebs[1].DeviceName != "/dev/xvdcz" { 420 return fmt.Errorf("Expected device 1's name to be %s, got %s", "/dev/xvdcz", *ebs[1].DeviceName) 421 } 422 423 return nil 424 } 425 } 426 427 func testAccCheckAWSSpotFleetRequest_PlacementAttributes( 428 sfr *ec2.SpotFleetRequestConfig) resource.TestCheckFunc { 429 return func(s *terraform.State) error { 430 if len(sfr.SpotFleetRequestConfig.LaunchSpecifications) == 0 { 431 return errors.New("Missing launch specification") 432 } 433 434 spec := *sfr.SpotFleetRequestConfig.LaunchSpecifications[0] 435 436 placement := spec.Placement 437 if placement == nil { 438 return fmt.Errorf("Expected placement to be set, got nil") 439 } 440 if *placement.Tenancy != "dedicated" { 441 return fmt.Errorf("Expected placement tenancy to be %q, got %q", "dedicated", placement.Tenancy) 442 } 443 444 return nil 445 } 446 } 447 448 func testAccCheckAWSSpotFleetRequestDestroy(s *terraform.State) error { 449 conn := testAccProvider.Meta().(*AWSClient).ec2conn 450 451 for _, rs := range s.RootModule().Resources { 452 if rs.Type != "aws_spot_fleet_request" { 453 continue 454 } 455 456 _, err := conn.CancelSpotFleetRequests(&ec2.CancelSpotFleetRequestsInput{ 457 SpotFleetRequestIds: []*string{aws.String(rs.Primary.ID)}, 458 TerminateInstances: aws.Bool(true), 459 }) 460 461 if err != nil { 462 return fmt.Errorf("Error cancelling spot request (%s): %s", rs.Primary.ID, err) 463 } 464 } 465 466 return nil 467 } 468 469 func testAccAWSSpotFleetRequestConfig(rName string, rInt int) string { 470 return fmt.Sprintf(` 471 resource "aws_key_pair" "debugging" { 472 key_name = "tmp-key-%s" 473 public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" 474 } 475 476 resource "aws_iam_policy" "test-policy" { 477 name = "test-policy-%d" 478 path = "/" 479 description = "Spot Fleet Request ACCTest Policy" 480 policy = <<EOF 481 { 482 "Version": "2012-10-17", 483 "Statement": [{ 484 "Effect": "Allow", 485 "Action": [ 486 "ec2:DescribeImages", 487 "ec2:DescribeSubnets", 488 "ec2:RequestSpotInstances", 489 "ec2:TerminateInstances", 490 "ec2:DescribeInstanceStatus", 491 "iam:PassRole" 492 ], 493 "Resource": ["*"] 494 }] 495 } 496 EOF 497 } 498 499 resource "aws_iam_policy_attachment" "test-attach" { 500 name = "test-attachment-%d" 501 roles = ["${aws_iam_role.test-role.name}"] 502 policy_arn = "${aws_iam_policy.test-policy.arn}" 503 } 504 505 resource "aws_iam_role" "test-role" { 506 name = "test-role-%s" 507 assume_role_policy = <<EOF 508 { 509 "Version": "2012-10-17", 510 "Statement": [ 511 { 512 "Sid": "", 513 "Effect": "Allow", 514 "Principal": { 515 "Service": [ 516 "spotfleet.amazonaws.com", 517 "ec2.amazonaws.com" 518 ] 519 }, 520 "Action": "sts:AssumeRole" 521 } 522 ] 523 } 524 EOF 525 } 526 527 resource "aws_spot_fleet_request" "foo" { 528 iam_fleet_role = "${aws_iam_role.test-role.arn}" 529 spot_price = "0.005" 530 target_capacity = 2 531 valid_until = "2019-11-04T20:44:20Z" 532 terminate_instances_with_expiration = true 533 launch_specification { 534 instance_type = "m1.small" 535 ami = "ami-d06a90b0" 536 key_name = "${aws_key_pair.debugging.key_name}" 537 } 538 depends_on = ["aws_iam_policy_attachment.test-attach"] 539 } 540 `, rName, rInt, rInt, rName) 541 } 542 543 func testAccAWSSpotFleetRequestConfigChangeSpotBidPrice(rName string, rInt int) string { 544 return fmt.Sprintf(` 545 resource "aws_key_pair" "debugging" { 546 key_name = "tmp-key-%s" 547 public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" 548 } 549 550 resource "aws_iam_policy" "test-policy" { 551 name = "test-policy-%d" 552 path = "/" 553 description = "Spot Fleet Request ACCTest Policy" 554 policy = <<EOF 555 { 556 "Version": "2012-10-17", 557 "Statement": [{ 558 "Effect": "Allow", 559 "Action": [ 560 "ec2:DescribeImages", 561 "ec2:DescribeSubnets", 562 "ec2:RequestSpotInstances", 563 "ec2:TerminateInstances", 564 "ec2:DescribeInstanceStatus", 565 "iam:PassRole" 566 ], 567 "Resource": ["*"] 568 }] 569 } 570 EOF 571 } 572 573 resource "aws_iam_policy_attachment" "test-attach" { 574 name = "test-attachment-%d" 575 roles = ["${aws_iam_role.test-role.name}"] 576 policy_arn = "${aws_iam_policy.test-policy.arn}" 577 } 578 579 resource "aws_iam_role" "test-role" { 580 name = "test-role-%s" 581 assume_role_policy = <<EOF 582 { 583 "Version": "2012-10-17", 584 "Statement": [ 585 { 586 "Sid": "", 587 "Effect": "Allow", 588 "Principal": { 589 "Service": [ 590 "spotfleet.amazonaws.com", 591 "ec2.amazonaws.com" 592 ] 593 }, 594 "Action": "sts:AssumeRole" 595 } 596 ] 597 } 598 EOF 599 } 600 601 resource "aws_spot_fleet_request" "foo" { 602 iam_fleet_role = "${aws_iam_role.test-role.arn}" 603 spot_price = "0.01" 604 target_capacity = 2 605 valid_until = "2019-11-04T20:44:20Z" 606 terminate_instances_with_expiration = true 607 launch_specification { 608 instance_type = "m1.small" 609 ami = "ami-d06a90b0" 610 key_name = "${aws_key_pair.debugging.key_name}" 611 } 612 depends_on = ["aws_iam_policy_attachment.test-attach"] 613 } 614 `, rName, rInt, rInt, rName) 615 } 616 617 func testAccAWSSpotFleetRequestConfigWithAzs(rName string, rInt int) string { 618 return fmt.Sprintf(` 619 resource "aws_key_pair" "debugging" { 620 key_name = "tmp-key-%s" 621 public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" 622 } 623 624 resource "aws_iam_policy" "test-policy" { 625 name = "test-policy-%d" 626 path = "/" 627 description = "Spot Fleet Request ACCTest Policy" 628 policy = <<EOF 629 { 630 "Version": "2012-10-17", 631 "Statement": [{ 632 "Effect": "Allow", 633 "Action": [ 634 "ec2:DescribeImages", 635 "ec2:DescribeSubnets", 636 "ec2:RequestSpotInstances", 637 "ec2:TerminateInstances", 638 "ec2:DescribeInstanceStatus", 639 "iam:PassRole" 640 ], 641 "Resource": ["*"] 642 }] 643 } 644 EOF 645 } 646 647 resource "aws_iam_policy_attachment" "test-attach" { 648 name = "test-attachment-%d" 649 roles = ["${aws_iam_role.test-role.name}"] 650 policy_arn = "${aws_iam_policy.test-policy.arn}" 651 } 652 653 resource "aws_iam_role" "test-role" { 654 name = "test-role-%s" 655 assume_role_policy = <<EOF 656 { 657 "Version": "2012-10-17", 658 "Statement": [ 659 { 660 "Sid": "", 661 "Effect": "Allow", 662 "Principal": { 663 "Service": [ 664 "spotfleet.amazonaws.com", 665 "ec2.amazonaws.com" 666 ] 667 }, 668 "Action": "sts:AssumeRole" 669 } 670 ] 671 } 672 EOF 673 } 674 675 resource "aws_spot_fleet_request" "foo" { 676 iam_fleet_role = "${aws_iam_role.test-role.arn}" 677 spot_price = "0.005" 678 target_capacity = 2 679 valid_until = "2019-11-04T20:44:20Z" 680 terminate_instances_with_expiration = true 681 launch_specification { 682 instance_type = "m1.small" 683 ami = "ami-d06a90b0" 684 key_name = "${aws_key_pair.debugging.key_name}" 685 availability_zone = "us-west-2a" 686 } 687 launch_specification { 688 instance_type = "m1.small" 689 ami = "ami-d06a90b0" 690 key_name = "${aws_key_pair.debugging.key_name}" 691 availability_zone = "us-west-2b" 692 } 693 depends_on = ["aws_iam_policy_attachment.test-attach"] 694 } 695 `, rName, rInt, rInt, rName) 696 } 697 698 func testAccAWSSpotFleetRequestConfigWithSubnet(rName string, rInt int) string { 699 return fmt.Sprintf(` 700 resource "aws_key_pair" "debugging" { 701 key_name = "tmp-key-%s" 702 public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" 703 } 704 705 resource "aws_iam_policy" "test-policy" { 706 name = "test-policy-%d" 707 path = "/" 708 description = "Spot Fleet Request ACCTest Policy" 709 policy = <<EOF 710 { 711 "Version": "2012-10-17", 712 "Statement": [{ 713 "Effect": "Allow", 714 "Action": [ 715 "ec2:DescribeImages", 716 "ec2:DescribeSubnets", 717 "ec2:RequestSpotInstances", 718 "ec2:TerminateInstances", 719 "ec2:DescribeInstanceStatus", 720 "iam:PassRole" 721 ], 722 "Resource": ["*"] 723 }] 724 } 725 EOF 726 } 727 728 resource "aws_iam_policy_attachment" "test-attach" { 729 name = "test-attachment-%d" 730 roles = ["${aws_iam_role.test-role.name}"] 731 policy_arn = "${aws_iam_policy.test-policy.arn}" 732 } 733 734 resource "aws_iam_role" "test-role" { 735 name = "test-role-%s" 736 assume_role_policy = <<EOF 737 { 738 "Version": "2012-10-17", 739 "Statement": [ 740 { 741 "Sid": "", 742 "Effect": "Allow", 743 "Principal": { 744 "Service": [ 745 "spotfleet.amazonaws.com", 746 "ec2.amazonaws.com" 747 ] 748 }, 749 "Action": "sts:AssumeRole" 750 } 751 ] 752 } 753 EOF 754 } 755 756 resource "aws_vpc" "foo" { 757 cidr_block = "10.1.0.0/16" 758 } 759 760 resource "aws_subnet" "foo" { 761 cidr_block = "10.1.1.0/24" 762 vpc_id = "${aws_vpc.foo.id}" 763 availability_zone = "us-west-2a" 764 } 765 766 resource "aws_subnet" "bar" { 767 cidr_block = "10.1.20.0/24" 768 vpc_id = "${aws_vpc.foo.id}" 769 availability_zone = "us-west-2b" 770 } 771 772 resource "aws_spot_fleet_request" "foo" { 773 iam_fleet_role = "${aws_iam_role.test-role.arn}" 774 spot_price = "0.005" 775 target_capacity = 4 776 valid_until = "2019-11-04T20:44:20Z" 777 terminate_instances_with_expiration = true 778 launch_specification { 779 instance_type = "m3.large" 780 ami = "ami-d0f506b0" 781 key_name = "${aws_key_pair.debugging.key_name}" 782 subnet_id = "${aws_subnet.foo.id}" 783 } 784 launch_specification { 785 instance_type = "m3.large" 786 ami = "ami-d0f506b0" 787 key_name = "${aws_key_pair.debugging.key_name}" 788 subnet_id = "${aws_subnet.bar.id}" 789 } 790 depends_on = ["aws_iam_policy_attachment.test-attach"] 791 } 792 `, rName, rInt, rInt, rName) 793 } 794 795 func testAccAWSSpotFleetRequestConfigMultipleInstanceTypesinSameAz(rName string, rInt int) string { 796 return fmt.Sprintf(` 797 resource "aws_key_pair" "debugging" { 798 key_name = "tmp-key-%s" 799 public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" 800 } 801 802 resource "aws_iam_policy" "test-policy" { 803 name = "test-policy-%d" 804 path = "/" 805 description = "Spot Fleet Request ACCTest Policy" 806 policy = <<EOF 807 { 808 "Version": "2012-10-17", 809 "Statement": [{ 810 "Effect": "Allow", 811 "Action": [ 812 "ec2:DescribeImages", 813 "ec2:DescribeSubnets", 814 "ec2:RequestSpotInstances", 815 "ec2:TerminateInstances", 816 "ec2:DescribeInstanceStatus", 817 "iam:PassRole" 818 ], 819 "Resource": ["*"] 820 }] 821 } 822 EOF 823 } 824 825 resource "aws_iam_policy_attachment" "test-attach" { 826 name = "test-attachment-%d" 827 roles = ["${aws_iam_role.test-role.name}"] 828 policy_arn = "${aws_iam_policy.test-policy.arn}" 829 } 830 831 resource "aws_iam_role" "test-role" { 832 name = "test-role-%s" 833 assume_role_policy = <<EOF 834 { 835 "Version": "2012-10-17", 836 "Statement": [ 837 { 838 "Sid": "", 839 "Effect": "Allow", 840 "Principal": { 841 "Service": [ 842 "spotfleet.amazonaws.com", 843 "ec2.amazonaws.com" 844 ] 845 }, 846 "Action": "sts:AssumeRole" 847 } 848 ] 849 } 850 EOF 851 } 852 853 resource "aws_spot_fleet_request" "foo" { 854 iam_fleet_role = "${aws_iam_role.test-role.arn}" 855 spot_price = "0.005" 856 target_capacity = 2 857 valid_until = "2019-11-04T20:44:20Z" 858 terminate_instances_with_expiration = true 859 launch_specification { 860 instance_type = "m1.small" 861 ami = "ami-d06a90b0" 862 key_name = "${aws_key_pair.debugging.key_name}" 863 availability_zone = "us-west-2a" 864 } 865 launch_specification { 866 instance_type = "m3.large" 867 ami = "ami-d06a90b0" 868 key_name = "${aws_key_pair.debugging.key_name}" 869 availability_zone = "us-west-2a" 870 } 871 depends_on = ["aws_iam_policy_attachment.test-attach"] 872 } 873 `, rName, rInt, rInt, rName) 874 } 875 876 func testAccAWSSpotFleetRequestConfigMultipleInstanceTypesinSameSubnet(rName string, rInt int) string { 877 return fmt.Sprintf(` 878 resource "aws_key_pair" "debugging" { 879 key_name = "tmp-key-%s" 880 public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" 881 } 882 883 resource "aws_iam_policy" "test-policy" { 884 name = "test-policy-%d" 885 path = "/" 886 description = "Spot Fleet Request ACCTest Policy" 887 policy = <<EOF 888 { 889 "Version": "2012-10-17", 890 "Statement": [{ 891 "Effect": "Allow", 892 "Action": [ 893 "ec2:DescribeImages", 894 "ec2:DescribeSubnets", 895 "ec2:RequestSpotInstances", 896 "ec2:TerminateInstances", 897 "ec2:DescribeInstanceStatus", 898 "iam:PassRole" 899 ], 900 "Resource": ["*"] 901 }] 902 } 903 EOF 904 } 905 906 resource "aws_iam_policy_attachment" "test-attach" { 907 name = "test-attachment-%d" 908 roles = ["${aws_iam_role.test-role.name}"] 909 policy_arn = "${aws_iam_policy.test-policy.arn}" 910 } 911 912 resource "aws_iam_role" "test-role" { 913 name = "test-role-%s" 914 assume_role_policy = <<EOF 915 { 916 "Version": "2012-10-17", 917 "Statement": [ 918 { 919 "Sid": "", 920 "Effect": "Allow", 921 "Principal": { 922 "Service": [ 923 "spotfleet.amazonaws.com", 924 "ec2.amazonaws.com" 925 ] 926 }, 927 "Action": "sts:AssumeRole" 928 } 929 ] 930 } 931 EOF 932 } 933 934 resource "aws_vpc" "foo" { 935 cidr_block = "10.1.0.0/16" 936 } 937 938 resource "aws_subnet" "foo" { 939 cidr_block = "10.1.1.0/24" 940 vpc_id = "${aws_vpc.foo.id}" 941 availability_zone = "us-west-2a" 942 } 943 944 resource "aws_spot_fleet_request" "foo" { 945 iam_fleet_role = "${aws_iam_role.test-role.arn}" 946 spot_price = "0.005" 947 target_capacity = 4 948 valid_until = "2019-11-04T20:44:20Z" 949 terminate_instances_with_expiration = true 950 launch_specification { 951 instance_type = "m3.large" 952 ami = "ami-d0f506b0" 953 key_name = "${aws_key_pair.debugging.key_name}" 954 subnet_id = "${aws_subnet.foo.id}" 955 } 956 launch_specification { 957 instance_type = "r3.large" 958 ami = "ami-d0f506b0" 959 key_name = "${aws_key_pair.debugging.key_name}" 960 subnet_id = "${aws_subnet.foo.id}" 961 } 962 depends_on = ["aws_iam_policy_attachment.test-attach"] 963 } 964 `, rName, rInt, rInt, rName) 965 } 966 967 func testAccAWSSpotFleetRequestConfigOverridingSpotPrice(rName string, rInt int) string { 968 return fmt.Sprintf(` 969 resource "aws_key_pair" "debugging" { 970 key_name = "tmp-key-%s" 971 public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" 972 } 973 974 resource "aws_iam_policy" "test-policy" { 975 name = "test-policy-%d" 976 path = "/" 977 description = "Spot Fleet Request ACCTest Policy" 978 policy = <<EOF 979 { 980 "Version": "2012-10-17", 981 "Statement": [{ 982 "Effect": "Allow", 983 "Action": [ 984 "ec2:DescribeImages", 985 "ec2:DescribeSubnets", 986 "ec2:RequestSpotInstances", 987 "ec2:TerminateInstances", 988 "ec2:DescribeInstanceStatus", 989 "iam:PassRole" 990 ], 991 "Resource": ["*"] 992 }] 993 } 994 EOF 995 } 996 997 resource "aws_iam_policy_attachment" "test-attach" { 998 name = "test-attachment-%d" 999 roles = ["${aws_iam_role.test-role.name}"] 1000 policy_arn = "${aws_iam_policy.test-policy.arn}" 1001 } 1002 1003 resource "aws_iam_role" "test-role" { 1004 name = "test-role-%s" 1005 assume_role_policy = <<EOF 1006 { 1007 "Version": "2012-10-17", 1008 "Statement": [ 1009 { 1010 "Sid": "", 1011 "Effect": "Allow", 1012 "Principal": { 1013 "Service": [ 1014 "spotfleet.amazonaws.com", 1015 "ec2.amazonaws.com" 1016 ] 1017 }, 1018 "Action": "sts:AssumeRole" 1019 } 1020 ] 1021 } 1022 EOF 1023 } 1024 1025 resource "aws_spot_fleet_request" "foo" { 1026 iam_fleet_role = "${aws_iam_role.test-role.arn}" 1027 spot_price = "0.005" 1028 target_capacity = 2 1029 valid_until = "2019-11-04T20:44:20Z" 1030 terminate_instances_with_expiration = true 1031 launch_specification { 1032 instance_type = "m1.small" 1033 ami = "ami-d06a90b0" 1034 key_name = "${aws_key_pair.debugging.key_name}" 1035 availability_zone = "us-west-2a" 1036 } 1037 launch_specification { 1038 instance_type = "m3.large" 1039 ami = "ami-d06a90b0" 1040 key_name = "${aws_key_pair.debugging.key_name}" 1041 availability_zone = "us-west-2a" 1042 spot_price = "0.01" 1043 } 1044 depends_on = ["aws_iam_policy_attachment.test-attach"] 1045 } 1046 `, rName, rInt, rInt, rName) 1047 } 1048 1049 func testAccAWSSpotFleetRequestConfigDiversifiedAllocation(rName string, rInt int) string { 1050 return fmt.Sprintf(` 1051 resource "aws_key_pair" "debugging" { 1052 key_name = "tmp-key-%s" 1053 public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" 1054 } 1055 1056 resource "aws_iam_policy" "test-policy" { 1057 name = "test-policy-%d" 1058 path = "/" 1059 description = "Spot Fleet Request ACCTest Policy" 1060 policy = <<EOF 1061 { 1062 "Version": "2012-10-17", 1063 "Statement": [{ 1064 "Effect": "Allow", 1065 "Action": [ 1066 "ec2:DescribeImages", 1067 "ec2:DescribeSubnets", 1068 "ec2:RequestSpotInstances", 1069 "ec2:TerminateInstances", 1070 "ec2:DescribeInstanceStatus", 1071 "iam:PassRole" 1072 ], 1073 "Resource": ["*"] 1074 }] 1075 } 1076 EOF 1077 } 1078 1079 resource "aws_iam_policy_attachment" "test-attach" { 1080 name = "test-attachment-%d" 1081 roles = ["${aws_iam_role.test-role.name}"] 1082 policy_arn = "${aws_iam_policy.test-policy.arn}" 1083 } 1084 1085 resource "aws_iam_role" "test-role" { 1086 name = "test-role-%s" 1087 assume_role_policy = <<EOF 1088 { 1089 "Version": "2012-10-17", 1090 "Statement": [ 1091 { 1092 "Sid": "", 1093 "Effect": "Allow", 1094 "Principal": { 1095 "Service": [ 1096 "spotfleet.amazonaws.com", 1097 "ec2.amazonaws.com" 1098 ] 1099 }, 1100 "Action": "sts:AssumeRole" 1101 } 1102 ] 1103 } 1104 EOF 1105 } 1106 1107 resource "aws_spot_fleet_request" "foo" { 1108 iam_fleet_role = "${aws_iam_role.test-role.arn}" 1109 spot_price = "0.7" 1110 target_capacity = 30 1111 valid_until = "2019-11-04T20:44:20Z" 1112 allocation_strategy = "diversified" 1113 terminate_instances_with_expiration = true 1114 launch_specification { 1115 instance_type = "m1.small" 1116 ami = "ami-d06a90b0" 1117 key_name = "${aws_key_pair.debugging.key_name}" 1118 availability_zone = "us-west-2a" 1119 } 1120 launch_specification { 1121 instance_type = "m3.large" 1122 ami = "ami-d06a90b0" 1123 key_name = "${aws_key_pair.debugging.key_name}" 1124 availability_zone = "us-west-2a" 1125 } 1126 launch_specification { 1127 instance_type = "r3.large" 1128 ami = "ami-d06a90b0" 1129 key_name = "${aws_key_pair.debugging.key_name}" 1130 availability_zone = "us-west-2a" 1131 } 1132 depends_on = ["aws_iam_policy_attachment.test-attach"] 1133 } 1134 `, rName, rInt, rInt, rName) 1135 } 1136 1137 func testAccAWSSpotFleetRequestConfigWithWeightedCapacity(rName string, rInt int) string { 1138 return fmt.Sprintf(` 1139 resource "aws_key_pair" "debugging" { 1140 key_name = "tmp-key-%s" 1141 public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" 1142 } 1143 1144 resource "aws_iam_policy" "test-policy" { 1145 name = "test-policy-%d" 1146 path = "/" 1147 description = "Spot Fleet Request ACCTest Policy" 1148 policy = <<EOF 1149 { 1150 "Version": "2012-10-17", 1151 "Statement": [{ 1152 "Effect": "Allow", 1153 "Action": [ 1154 "ec2:DescribeImages", 1155 "ec2:DescribeSubnets", 1156 "ec2:RequestSpotInstances", 1157 "ec2:TerminateInstances", 1158 "ec2:DescribeInstanceStatus", 1159 "iam:PassRole" 1160 ], 1161 "Resource": ["*"] 1162 }] 1163 } 1164 EOF 1165 } 1166 1167 resource "aws_iam_policy_attachment" "test-attach" { 1168 name = "test-attachment-%d" 1169 roles = ["${aws_iam_role.test-role.name}"] 1170 policy_arn = "${aws_iam_policy.test-policy.arn}" 1171 } 1172 1173 resource "aws_iam_role" "test-role" { 1174 name = "test-role-%s" 1175 assume_role_policy = <<EOF 1176 { 1177 "Version": "2012-10-17", 1178 "Statement": [ 1179 { 1180 "Sid": "", 1181 "Effect": "Allow", 1182 "Principal": { 1183 "Service": [ 1184 "spotfleet.amazonaws.com", 1185 "ec2.amazonaws.com" 1186 ] 1187 }, 1188 "Action": "sts:AssumeRole" 1189 } 1190 ] 1191 } 1192 EOF 1193 } 1194 1195 resource "aws_spot_fleet_request" "foo" { 1196 iam_fleet_role = "${aws_iam_role.test-role.arn}" 1197 spot_price = "0.7" 1198 target_capacity = 10 1199 valid_until = "2019-11-04T20:44:20Z" 1200 terminate_instances_with_expiration = true 1201 launch_specification { 1202 instance_type = "m3.large" 1203 ami = "ami-d06a90b0" 1204 key_name = "${aws_key_pair.debugging.key_name}" 1205 availability_zone = "us-west-2a" 1206 weighted_capacity = "6" 1207 } 1208 launch_specification { 1209 instance_type = "r3.large" 1210 ami = "ami-d06a90b0" 1211 key_name = "${aws_key_pair.debugging.key_name}" 1212 availability_zone = "us-west-2a" 1213 weighted_capacity = "3" 1214 } 1215 depends_on = ["aws_iam_policy_attachment.test-attach"] 1216 } 1217 `, rName, rInt, rInt, rName) 1218 } 1219 1220 func testAccAWSSpotFleetRequestEBSConfig(rName string, rInt int) string { 1221 return fmt.Sprintf(` 1222 resource "aws_iam_policy" "test-policy" { 1223 name = "test-policy-%d" 1224 path = "/" 1225 description = "Spot Fleet Request ACCTest Policy" 1226 policy = <<EOF 1227 { 1228 "Version": "2012-10-17", 1229 "Statement": [{ 1230 "Effect": "Allow", 1231 "Action": [ 1232 "ec2:DescribeImages", 1233 "ec2:DescribeSubnets", 1234 "ec2:RequestSpotInstances", 1235 "ec2:TerminateInstances", 1236 "ec2:DescribeInstanceStatus", 1237 "iam:PassRole" 1238 ], 1239 "Resource": ["*"] 1240 }] 1241 } 1242 EOF 1243 } 1244 1245 resource "aws_iam_policy_attachment" "test-attach" { 1246 name = "test-attachment-%d" 1247 roles = ["${aws_iam_role.test-role.name}"] 1248 policy_arn = "${aws_iam_policy.test-policy.arn}" 1249 } 1250 1251 resource "aws_iam_role" "test-role" { 1252 name = "test-role-%s" 1253 assume_role_policy = <<EOF 1254 { 1255 "Version": "2012-10-17", 1256 "Statement": [ 1257 { 1258 "Sid": "", 1259 "Effect": "Allow", 1260 "Principal": { 1261 "Service": [ 1262 "spotfleet.amazonaws.com", 1263 "ec2.amazonaws.com" 1264 ] 1265 }, 1266 "Action": "sts:AssumeRole" 1267 } 1268 ] 1269 } 1270 EOF 1271 } 1272 1273 resource "aws_spot_fleet_request" "foo" { 1274 iam_fleet_role = "${aws_iam_role.test-role.arn}" 1275 spot_price = "0.005" 1276 target_capacity = 1 1277 valid_until = "2019-11-04T20:44:20Z" 1278 terminate_instances_with_expiration = true 1279 launch_specification { 1280 instance_type = "m1.small" 1281 ami = "ami-d06a90b0" 1282 1283 ebs_block_device { 1284 device_name = "/dev/xvda" 1285 volume_type = "gp2" 1286 volume_size = "8" 1287 } 1288 1289 ebs_block_device { 1290 device_name = "/dev/xvdcz" 1291 volume_type = "gp2" 1292 volume_size = "100" 1293 } 1294 } 1295 depends_on = ["aws_iam_policy_attachment.test-attach"] 1296 } 1297 `, rInt, rInt, rName) 1298 } 1299 1300 func testAccAWSSpotFleetRequestTenancyConfig(rName string, rInt int) string { 1301 return fmt.Sprintf(` 1302 resource "aws_key_pair" "debugging" { 1303 key_name = "tmp-key-%s" 1304 public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" 1305 } 1306 1307 resource "aws_iam_policy" "test-policy" { 1308 name = "test-policy-%d" 1309 path = "/" 1310 description = "Spot Fleet Request ACCTest Policy" 1311 policy = <<EOF 1312 { 1313 "Version": "2012-10-17", 1314 "Statement": [{ 1315 "Effect": "Allow", 1316 "Action": [ 1317 "ec2:DescribeImages", 1318 "ec2:DescribeSubnets", 1319 "ec2:RequestSpotInstances", 1320 "ec2:TerminateInstances", 1321 "ec2:DescribeInstanceStatus", 1322 "iam:PassRole" 1323 ], 1324 "Resource": ["*"] 1325 }] 1326 } 1327 EOF 1328 } 1329 1330 resource "aws_iam_policy_attachment" "test-attach" { 1331 name = "test-attachment-%d" 1332 roles = ["${aws_iam_role.test-role.name}"] 1333 policy_arn = "${aws_iam_policy.test-policy.arn}" 1334 } 1335 1336 resource "aws_iam_role" "test-role" { 1337 name = "test-role-%s" 1338 assume_role_policy = <<EOF 1339 { 1340 "Version": "2012-10-17", 1341 "Statement": [ 1342 { 1343 "Sid": "", 1344 "Effect": "Allow", 1345 "Principal": { 1346 "Service": [ 1347 "spotfleet.amazonaws.com", 1348 "ec2.amazonaws.com" 1349 ] 1350 }, 1351 "Action": "sts:AssumeRole" 1352 } 1353 ] 1354 } 1355 EOF 1356 } 1357 1358 resource "aws_spot_fleet_request" "foo" { 1359 iam_fleet_role = "${aws_iam_role.test-role.arn}" 1360 spot_price = "0.005" 1361 target_capacity = 2 1362 valid_until = "2019-11-04T20:44:20Z" 1363 terminate_instances_with_expiration = true 1364 launch_specification { 1365 instance_type = "m1.small" 1366 ami = "ami-d06a90b0" 1367 key_name = "${aws_key_pair.debugging.key_name}" 1368 placement_tenancy = "dedicated" 1369 } 1370 depends_on = ["aws_iam_policy_attachment.test-attach"] 1371 } 1372 `, rName, rInt, rInt, rName) 1373 }