github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "log" 6 "reflect" 7 "regexp" 8 "sort" 9 "testing" 10 11 "github.com/aws/aws-sdk-go/aws" 12 "github.com/aws/aws-sdk-go/aws/awserr" 13 "github.com/aws/aws-sdk-go/service/elasticbeanstalk" 14 "github.com/hashicorp/terraform/helper/acctest" 15 "github.com/hashicorp/terraform/helper/resource" 16 "github.com/hashicorp/terraform/terraform" 17 ) 18 19 func TestAccAWSBeanstalkEnv_basic(t *testing.T) { 20 var app elasticbeanstalk.EnvironmentDescription 21 22 resource.Test(t, resource.TestCase{ 23 PreCheck: func() { testAccPreCheck(t) }, 24 Providers: testAccProviders, 25 CheckDestroy: testAccCheckBeanstalkEnvDestroy, 26 Steps: []resource.TestStep{ 27 resource.TestStep{ 28 Config: testAccBeanstalkEnvConfig, 29 Check: resource.ComposeTestCheckFunc( 30 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), 31 ), 32 }, 33 }, 34 }) 35 } 36 37 func TestAccAWSBeanstalkEnv_tier(t *testing.T) { 38 var app elasticbeanstalk.EnvironmentDescription 39 beanstalkQueuesNameRegexp := regexp.MustCompile("https://sqs.+?awseb[^,]+") 40 41 resource.Test(t, resource.TestCase{ 42 PreCheck: func() { testAccPreCheck(t) }, 43 Providers: testAccProviders, 44 CheckDestroy: testAccCheckBeanstalkEnvDestroy, 45 Steps: []resource.TestStep{ 46 resource.TestStep{ 47 Config: testAccBeanstalkWorkerEnvConfig, 48 Check: resource.ComposeTestCheckFunc( 49 testAccCheckBeanstalkEnvTier("aws_elastic_beanstalk_environment.tfenvtest", &app), 50 resource.TestMatchResourceAttr( 51 "aws_elastic_beanstalk_environment.tfenvtest", "queues.0", beanstalkQueuesNameRegexp), 52 ), 53 }, 54 }, 55 }) 56 } 57 58 func TestAccAWSBeanstalkEnv_outputs(t *testing.T) { 59 var app elasticbeanstalk.EnvironmentDescription 60 beanstalkAsgNameRegexp := regexp.MustCompile("awseb.+?AutoScalingGroup[^,]+") 61 beanstalkElbNameRegexp := regexp.MustCompile("awseb.+?EBLoa[^,]+") 62 beanstalkInstancesNameRegexp := regexp.MustCompile("i-([0-9a-fA-F]{8}|[0-9a-fA-F]{17})") 63 beanstalkLcNameRegexp := regexp.MustCompile("awseb.+?AutoScalingLaunch[^,]+") 64 65 resource.Test(t, resource.TestCase{ 66 PreCheck: func() { testAccPreCheck(t) }, 67 Providers: testAccProviders, 68 CheckDestroy: testAccCheckBeanstalkEnvDestroy, 69 Steps: []resource.TestStep{ 70 resource.TestStep{ 71 Config: testAccBeanstalkEnvConfig, 72 Check: resource.ComposeTestCheckFunc( 73 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), 74 resource.TestMatchResourceAttr( 75 "aws_elastic_beanstalk_environment.tfenvtest", "autoscaling_groups.0", beanstalkAsgNameRegexp), 76 resource.TestMatchResourceAttr( 77 "aws_elastic_beanstalk_environment.tfenvtest", "load_balancers.0", beanstalkElbNameRegexp), 78 resource.TestMatchResourceAttr( 79 "aws_elastic_beanstalk_environment.tfenvtest", "instances.0", beanstalkInstancesNameRegexp), 80 resource.TestMatchResourceAttr( 81 "aws_elastic_beanstalk_environment.tfenvtest", "launch_configurations.0", beanstalkLcNameRegexp), 82 ), 83 }, 84 }, 85 }) 86 } 87 88 func TestAccAWSBeanstalkEnv_cname_prefix(t *testing.T) { 89 var app elasticbeanstalk.EnvironmentDescription 90 cnamePrefix := acctest.RandString(8) 91 beanstalkCnameRegexp := regexp.MustCompile("^" + cnamePrefix + ".+?elasticbeanstalk.com$") 92 93 resource.Test(t, resource.TestCase{ 94 PreCheck: func() { testAccPreCheck(t) }, 95 Providers: testAccProviders, 96 CheckDestroy: testAccCheckBeanstalkEnvDestroy, 97 Steps: []resource.TestStep{ 98 resource.TestStep{ 99 Config: testAccBeanstalkEnvCnamePrefixConfig(cnamePrefix), 100 Check: resource.ComposeTestCheckFunc( 101 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), 102 resource.TestMatchResourceAttr( 103 "aws_elastic_beanstalk_environment.tfenvtest", "cname", beanstalkCnameRegexp), 104 ), 105 }, 106 }, 107 }) 108 } 109 110 func TestAccAWSBeanstalkEnv_config(t *testing.T) { 111 var app elasticbeanstalk.EnvironmentDescription 112 113 resource.Test(t, resource.TestCase{ 114 PreCheck: func() { testAccPreCheck(t) }, 115 Providers: testAccProviders, 116 CheckDestroy: testAccCheckBeanstalkEnvDestroy, 117 Steps: []resource.TestStep{ 118 resource.TestStep{ 119 Config: testAccBeanstalkConfigTemplate, 120 Check: resource.ComposeTestCheckFunc( 121 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tftest", &app), 122 testAccCheckBeanstalkEnvConfigValue("aws_elastic_beanstalk_environment.tftest", "1"), 123 ), 124 }, 125 126 resource.TestStep{ 127 Config: testAccBeanstalkConfigTemplateUpdate, 128 Check: resource.ComposeTestCheckFunc( 129 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tftest", &app), 130 testAccCheckBeanstalkEnvConfigValue("aws_elastic_beanstalk_environment.tftest", "2"), 131 ), 132 }, 133 134 resource.TestStep{ 135 Config: testAccBeanstalkConfigTemplateUpdate, 136 Check: resource.ComposeTestCheckFunc( 137 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tftest", &app), 138 testAccCheckBeanstalkEnvConfigValue("aws_elastic_beanstalk_environment.tftest", "3"), 139 ), 140 }, 141 }, 142 }) 143 } 144 145 func TestAccAWSBeanstalkEnv_resource(t *testing.T) { 146 var app elasticbeanstalk.EnvironmentDescription 147 148 resource.Test(t, resource.TestCase{ 149 PreCheck: func() { testAccPreCheck(t) }, 150 Providers: testAccProviders, 151 CheckDestroy: testAccCheckBeanstalkEnvDestroy, 152 Steps: []resource.TestStep{ 153 resource.TestStep{ 154 Config: testAccBeanstalkResourceOptionSetting, 155 Check: resource.ComposeTestCheckFunc( 156 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), 157 ), 158 }, 159 }, 160 }) 161 } 162 163 func TestAccAWSBeanstalkEnv_vpc(t *testing.T) { 164 var app elasticbeanstalk.EnvironmentDescription 165 166 resource.Test(t, resource.TestCase{ 167 PreCheck: func() { 168 testAccPreCheck(t) 169 }, 170 Providers: testAccProviders, 171 CheckDestroy: testAccCheckBeanstalkEnvDestroy, 172 Steps: []resource.TestStep{ 173 resource.TestStep{ 174 Config: testAccBeanstalkEnv_VPC(acctest.RandString(5)), 175 Check: resource.ComposeTestCheckFunc( 176 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.default", &app), 177 ), 178 }, 179 }, 180 }) 181 } 182 183 func TestAccAWSBeanstalkEnv_template_change(t *testing.T) { 184 var app elasticbeanstalk.EnvironmentDescription 185 186 rInt := acctest.RandInt() 187 188 resource.Test(t, resource.TestCase{ 189 PreCheck: func() { 190 testAccPreCheck(t) 191 }, 192 Providers: testAccProviders, 193 CheckDestroy: testAccCheckBeanstalkEnvDestroy, 194 Steps: []resource.TestStep{ 195 resource.TestStep{ 196 Config: testAccBeanstalkEnv_TemplateChange_stack(rInt), 197 Check: resource.ComposeTestCheckFunc( 198 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.environment", &app), 199 ), 200 }, 201 resource.TestStep{ 202 Config: testAccBeanstalkEnv_TemplateChange_temp(rInt), 203 Check: resource.ComposeTestCheckFunc( 204 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.environment", &app), 205 ), 206 }, 207 resource.TestStep{ 208 Config: testAccBeanstalkEnv_TemplateChange_stack(rInt), 209 Check: resource.ComposeTestCheckFunc( 210 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.environment", &app), 211 ), 212 }, 213 }, 214 }) 215 } 216 217 func TestAccAWSBeanstalkEnv_basic_settings_update(t *testing.T) { 218 var app elasticbeanstalk.EnvironmentDescription 219 220 rInt := acctest.RandInt() 221 222 resource.Test(t, resource.TestCase{ 223 PreCheck: func() { testAccPreCheck(t) }, 224 Providers: testAccProviders, 225 CheckDestroy: testAccCheckBeanstalkEnvDestroy, 226 Steps: []resource.TestStep{ 227 resource.TestStep{ 228 Config: testAccBeanstalkEnvConfig_empty_settings(rInt), 229 Check: resource.ComposeTestCheckFunc( 230 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), 231 testAccVerifyBeanstalkConfig(&app, []string{}), 232 ), 233 }, 234 resource.TestStep{ 235 Config: testAccBeanstalkEnvConfig_settings(rInt), 236 Check: resource.ComposeTestCheckFunc( 237 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), 238 testAccVerifyBeanstalkConfig(&app, []string{"ENV_STATIC", "ENV_UPDATE"}), 239 ), 240 }, 241 resource.TestStep{ 242 Config: testAccBeanstalkEnvConfig_settings_update(rInt), 243 Check: resource.ComposeTestCheckFunc( 244 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), 245 testAccVerifyBeanstalkConfig(&app, []string{"ENV_STATIC", "ENV_UPDATE"}), 246 ), 247 }, 248 resource.TestStep{ 249 Config: testAccBeanstalkEnvConfig_empty_settings(rInt), 250 Check: resource.ComposeTestCheckFunc( 251 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), 252 testAccVerifyBeanstalkConfig(&app, []string{}), 253 ), 254 }, 255 }, 256 }) 257 } 258 259 func testAccVerifyBeanstalkConfig(env *elasticbeanstalk.EnvironmentDescription, expected []string) resource.TestCheckFunc { 260 return func(s *terraform.State) error { 261 if env == nil { 262 return fmt.Errorf("Nil environment in testAccVerifyBeanstalkConfig") 263 } 264 conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn 265 266 resp, err := conn.DescribeConfigurationSettings(&elasticbeanstalk.DescribeConfigurationSettingsInput{ 267 ApplicationName: env.ApplicationName, 268 EnvironmentName: env.EnvironmentName, 269 }) 270 271 if err != nil { 272 return fmt.Errorf("Error describing config settings in testAccVerifyBeanstalkConfig: %s", err) 273 } 274 275 // should only be 1 environment 276 if len(resp.ConfigurationSettings) != 1 { 277 return fmt.Errorf("Expected only 1 set of Configuration Settings in testAccVerifyBeanstalkConfig, got (%d)", len(resp.ConfigurationSettings)) 278 } 279 280 cs := resp.ConfigurationSettings[0] 281 282 var foundEnvs []string 283 testStrings := []string{"ENV_STATIC", "ENV_UPDATE"} 284 for _, os := range cs.OptionSettings { 285 for _, k := range testStrings { 286 if *os.OptionName == k { 287 foundEnvs = append(foundEnvs, k) 288 } 289 } 290 } 291 292 // if expected is zero, then we should not have found any of the predefined 293 // env vars 294 if len(expected) == 0 { 295 if len(foundEnvs) > 0 { 296 return fmt.Errorf("Found configs we should not have: %#v", foundEnvs) 297 } 298 return nil 299 } 300 301 sort.Strings(testStrings) 302 sort.Strings(expected) 303 if !reflect.DeepEqual(testStrings, expected) { 304 return fmt.Errorf("Error matching strings, expected:\n\n%#v\n\ngot:\n\n%#v\n", testStrings, foundEnvs) 305 } 306 307 return nil 308 } 309 } 310 311 func testAccCheckBeanstalkEnvDestroy(s *terraform.State) error { 312 conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn 313 314 for _, rs := range s.RootModule().Resources { 315 if rs.Type != "aws_elastic_beanstalk_environment" { 316 continue 317 } 318 319 // Try to find the environment 320 describeBeanstalkEnvOpts := &elasticbeanstalk.DescribeEnvironmentsInput{ 321 EnvironmentIds: []*string{aws.String(rs.Primary.ID)}, 322 } 323 resp, err := conn.DescribeEnvironments(describeBeanstalkEnvOpts) 324 if err == nil { 325 switch { 326 case len(resp.Environments) > 1: 327 return fmt.Errorf("Error %d environments match, expected 1", len(resp.Environments)) 328 case len(resp.Environments) == 1: 329 if *resp.Environments[0].Status == "Terminated" { 330 return nil 331 } 332 return fmt.Errorf("Elastic Beanstalk ENV still exists.") 333 default: 334 return nil 335 } 336 } 337 338 // Verify the error is what we want 339 ec2err, ok := err.(awserr.Error) 340 if !ok { 341 return err 342 } 343 if ec2err.Code() != "InvalidBeanstalkEnvID.NotFound" { 344 return err 345 } 346 } 347 348 return nil 349 } 350 351 func testAccCheckBeanstalkEnvExists(n string, app *elasticbeanstalk.EnvironmentDescription) resource.TestCheckFunc { 352 return func(s *terraform.State) error { 353 rs, ok := s.RootModule().Resources[n] 354 if !ok { 355 return fmt.Errorf("Not found: %s", n) 356 } 357 358 if rs.Primary.ID == "" { 359 return fmt.Errorf("Elastic Beanstalk ENV is not set") 360 } 361 362 env, err := describeBeanstalkEnv(testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn, aws.String(rs.Primary.ID)) 363 if err != nil { 364 return err 365 } 366 367 *app = *env 368 369 return nil 370 } 371 } 372 373 func testAccCheckBeanstalkEnvTier(n string, app *elasticbeanstalk.EnvironmentDescription) resource.TestCheckFunc { 374 return func(s *terraform.State) error { 375 rs, ok := s.RootModule().Resources[n] 376 if !ok { 377 return fmt.Errorf("Not found: %s", n) 378 } 379 380 if rs.Primary.ID == "" { 381 return fmt.Errorf("Elastic Beanstalk ENV is not set") 382 } 383 384 env, err := describeBeanstalkEnv(testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn, aws.String(rs.Primary.ID)) 385 if err != nil { 386 return err 387 } 388 if *env.Tier.Name != "Worker" { 389 return fmt.Errorf("Beanstalk Environment tier is %s, expected Worker", *env.Tier.Name) 390 } 391 392 *app = *env 393 394 return nil 395 } 396 } 397 398 func testAccCheckBeanstalkEnvConfigValue(n string, expectedValue string) resource.TestCheckFunc { 399 return func(s *terraform.State) error { 400 conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn 401 402 rs, ok := s.RootModule().Resources[n] 403 if !ok { 404 return fmt.Errorf("Not found: %s", n) 405 } 406 407 if rs.Primary.ID == "" { 408 return fmt.Errorf("Elastic Beanstalk ENV is not set") 409 } 410 411 resp, err := conn.DescribeConfigurationOptions(&elasticbeanstalk.DescribeConfigurationOptionsInput{ 412 ApplicationName: aws.String(rs.Primary.Attributes["application"]), 413 EnvironmentName: aws.String(rs.Primary.Attributes["name"]), 414 Options: []*elasticbeanstalk.OptionSpecification{ 415 { 416 Namespace: aws.String("aws:elasticbeanstalk:application:environment"), 417 OptionName: aws.String("TEMPLATE"), 418 }, 419 }, 420 }) 421 if err != nil { 422 return err 423 } 424 425 if len(resp.Options) != 1 { 426 return fmt.Errorf("Found %d options, expected 1.", len(resp.Options)) 427 } 428 429 log.Printf("[DEBUG] %d Elastic Beanstalk Option values returned.", len(resp.Options[0].ValueOptions)) 430 431 for _, value := range resp.Options[0].ValueOptions { 432 if *value != expectedValue { 433 return fmt.Errorf("Option setting value: %s. Expected %s", *value, expectedValue) 434 } 435 } 436 437 return nil 438 } 439 } 440 441 func describeBeanstalkEnv(conn *elasticbeanstalk.ElasticBeanstalk, 442 envID *string) (*elasticbeanstalk.EnvironmentDescription, error) { 443 describeBeanstalkEnvOpts := &elasticbeanstalk.DescribeEnvironmentsInput{ 444 EnvironmentIds: []*string{envID}, 445 } 446 447 log.Printf("[DEBUG] Elastic Beanstalk Environment TEST describe opts: %s", describeBeanstalkEnvOpts) 448 449 resp, err := conn.DescribeEnvironments(describeBeanstalkEnvOpts) 450 if err != nil { 451 return &elasticbeanstalk.EnvironmentDescription{}, err 452 } 453 if len(resp.Environments) == 0 { 454 return &elasticbeanstalk.EnvironmentDescription{}, fmt.Errorf("Elastic Beanstalk ENV not found.") 455 } 456 if len(resp.Environments) > 1 { 457 return &elasticbeanstalk.EnvironmentDescription{}, fmt.Errorf("Found %d environments, expected 1.", len(resp.Environments)) 458 } 459 return resp.Environments[0], nil 460 } 461 462 const testAccBeanstalkEnvConfig = ` 463 resource "aws_elastic_beanstalk_application" "tftest" { 464 name = "tf-test-name" 465 description = "tf-test-desc" 466 } 467 468 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 469 name = "tf-test-name" 470 application = "${aws_elastic_beanstalk_application.tftest.name}" 471 solution_stack_name = "64bit Amazon Linux running Python" 472 } 473 ` 474 475 func testAccBeanstalkEnvConfig_empty_settings(r int) string { 476 return fmt.Sprintf(` 477 resource "aws_elastic_beanstalk_application" "tftest" { 478 name = "tf-test-name-%d" 479 description = "tf-test-desc" 480 } 481 482 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 483 name = "tf-test-name-%d" 484 application = "${aws_elastic_beanstalk_application.tftest.name}" 485 solution_stack_name = "64bit Amazon Linux running Python" 486 487 wait_for_ready_timeout = "15m" 488 }`, r, r) 489 } 490 491 func testAccBeanstalkEnvConfig_settings(r int) string { 492 return fmt.Sprintf(` 493 resource "aws_elastic_beanstalk_application" "tftest" { 494 name = "tf-test-name-%d" 495 description = "tf-test-desc" 496 } 497 498 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 499 name = "tf-test-name-%d" 500 application = "${aws_elastic_beanstalk_application.tftest.name}" 501 solution_stack_name = "64bit Amazon Linux running Python" 502 503 wait_for_ready_timeout = "15m" 504 505 setting { 506 namespace = "aws:elasticbeanstalk:application:environment" 507 name = "ENV_STATIC" 508 value = "true" 509 } 510 511 setting { 512 namespace = "aws:elasticbeanstalk:application:environment" 513 name = "ENV_UPDATE" 514 value = "true" 515 } 516 517 setting { 518 namespace = "aws:elasticbeanstalk:application:environment" 519 name = "ENV_REMOVE" 520 value = "true" 521 } 522 523 setting { 524 namespace = "aws:autoscaling:scheduledaction" 525 resource = "ScheduledAction01" 526 name = "MinSize" 527 value = 2 528 } 529 530 setting { 531 namespace = "aws:autoscaling:scheduledaction" 532 resource = "ScheduledAction01" 533 name = "MaxSize" 534 value = 3 535 } 536 537 setting { 538 namespace = "aws:autoscaling:scheduledaction" 539 resource = "ScheduledAction01" 540 name = "StartTime" 541 value = "2016-07-28T04:07:02Z" 542 } 543 }`, r, r) 544 } 545 546 func testAccBeanstalkEnvConfig_settings_update(r int) string { 547 return fmt.Sprintf(` 548 resource "aws_elastic_beanstalk_application" "tftest" { 549 name = "tf-test-name-%d" 550 description = "tf-test-desc" 551 } 552 553 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 554 name = "tf-test-name-%d" 555 application = "${aws_elastic_beanstalk_application.tftest.name}" 556 solution_stack_name = "64bit Amazon Linux running Python" 557 558 wait_for_ready_timeout = "15m" 559 560 setting { 561 namespace = "aws:elasticbeanstalk:application:environment" 562 name = "ENV_STATIC" 563 value = "true" 564 } 565 566 setting { 567 namespace = "aws:elasticbeanstalk:application:environment" 568 name = "ENV_UPDATE" 569 value = "false" 570 } 571 572 setting { 573 namespace = "aws:elasticbeanstalk:application:environment" 574 name = "ENV_ADD" 575 value = "true" 576 } 577 578 setting { 579 namespace = "aws:autoscaling:scheduledaction" 580 resource = "ScheduledAction01" 581 name = "MinSize" 582 value = 2 583 } 584 585 setting { 586 namespace = "aws:autoscaling:scheduledaction" 587 resource = "ScheduledAction01" 588 name = "MaxSize" 589 value = 3 590 } 591 592 setting { 593 namespace = "aws:autoscaling:scheduledaction" 594 resource = "ScheduledAction01" 595 name = "StartTime" 596 value = "2016-07-28T04:07:02Z" 597 } 598 }`, r, r) 599 } 600 601 const testAccBeanstalkWorkerEnvConfig = ` 602 resource "aws_iam_instance_profile" "tftest" { 603 name = "tftest_profile" 604 roles = ["${aws_iam_role.tftest.name}"] 605 } 606 607 resource "aws_iam_role" "tftest" { 608 name = "tftest_role" 609 path = "/" 610 assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Effect\":\"Allow\",\"Sid\":\"\"}]}" 611 } 612 613 resource "aws_iam_role_policy" "tftest" { 614 name = "tftest_policy" 615 role = "${aws_iam_role.tftest.id}" 616 policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"QueueAccess\",\"Action\":[\"sqs:ChangeMessageVisibility\",\"sqs:DeleteMessage\",\"sqs:ReceiveMessage\"],\"Effect\":\"Allow\",\"Resource\":\"*\"}]}" 617 } 618 619 resource "aws_elastic_beanstalk_application" "tftest" { 620 name = "tf-test-name" 621 description = "tf-test-desc" 622 } 623 624 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 625 name = "tf-test-name" 626 application = "${aws_elastic_beanstalk_application.tftest.name}" 627 tier = "Worker" 628 solution_stack_name = "64bit Amazon Linux running Python" 629 630 setting { 631 namespace = "aws:autoscaling:launchconfiguration" 632 name = "IamInstanceProfile" 633 value = "${aws_iam_instance_profile.tftest.name}" 634 } 635 } 636 ` 637 638 func testAccBeanstalkEnvCnamePrefixConfig(randString string) string { 639 return fmt.Sprintf(` 640 resource "aws_elastic_beanstalk_application" "tftest" { 641 name = "tf-test-name" 642 description = "tf-test-desc" 643 } 644 645 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 646 name = "tf-test-name" 647 application = "${aws_elastic_beanstalk_application.tftest.name}" 648 cname_prefix = "%s" 649 solution_stack_name = "64bit Amazon Linux running Python" 650 } 651 `, randString) 652 } 653 654 const testAccBeanstalkConfigTemplate = ` 655 resource "aws_elastic_beanstalk_application" "tftest" { 656 name = "tf-test-name" 657 description = "tf-test-desc" 658 } 659 660 resource "aws_elastic_beanstalk_environment" "tftest" { 661 name = "tf-test-name" 662 application = "${aws_elastic_beanstalk_application.tftest.name}" 663 template_name = "${aws_elastic_beanstalk_configuration_template.tftest.name}" 664 } 665 666 resource "aws_elastic_beanstalk_configuration_template" "tftest" { 667 name = "tf-test-original" 668 application = "${aws_elastic_beanstalk_application.tftest.name}" 669 solution_stack_name = "64bit Amazon Linux running Python" 670 671 setting { 672 namespace = "aws:elasticbeanstalk:application:environment" 673 name = "TEMPLATE" 674 value = "1" 675 } 676 } 677 ` 678 679 const testAccBeanstalkConfigTemplateUpdate = ` 680 resource "aws_elastic_beanstalk_application" "tftest" { 681 name = "tf-test-name" 682 description = "tf-test-desc" 683 } 684 685 resource "aws_elastic_beanstalk_environment" "tftest" { 686 name = "tf-test-name" 687 application = "${aws_elastic_beanstalk_application.tftest.name}" 688 template_name = "${aws_elastic_beanstalk_configuration_template.tftest.name}" 689 } 690 691 resource "aws_elastic_beanstalk_configuration_template" "tftest" { 692 name = "tf-test-updated" 693 application = "${aws_elastic_beanstalk_application.tftest.name}" 694 solution_stack_name = "64bit Amazon Linux running Python" 695 696 setting { 697 namespace = "aws:elasticbeanstalk:application:environment" 698 name = "TEMPLATE" 699 value = "2" 700 } 701 } 702 ` 703 704 const testAccBeanstalkConfigTemplateOverride = ` 705 resource "aws_elastic_beanstalk_application" "tftest" { 706 name = "tf-test-name" 707 description = "tf-test-desc" 708 } 709 710 resource "aws_elastic_beanstalk_environment" "tftest" { 711 name = "tf-test-name" 712 application = "${aws_elastic_beanstalk_application.tftest.name}" 713 template_name = "${aws_elastic_beanstalk_configuration_template.tftest.name}" 714 715 setting { 716 namespace = "aws:elasticbeanstalk:application:environment" 717 name = "TEMPLATE" 718 value = "3" 719 } 720 } 721 722 resource "aws_elastic_beanstalk_configuration_template" "tftest" { 723 name = "tf-test-updated" 724 application = "${aws_elastic_beanstalk_application.tftest.name}" 725 solution_stack_name = "64bit Amazon Linux running Python" 726 727 setting { 728 namespace = "aws:elasticbeanstalk:application:environment" 729 name = "TEMPLATE" 730 value = "2" 731 } 732 } 733 ` 734 const testAccBeanstalkResourceOptionSetting = ` 735 resource "aws_elastic_beanstalk_application" "tftest" { 736 name = "tf-test-name" 737 description = "tf-test-desc" 738 } 739 740 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 741 name = "tf-test-name" 742 application = "${aws_elastic_beanstalk_application.tftest.name}" 743 solution_stack_name = "64bit Amazon Linux running Python" 744 745 setting { 746 namespace = "aws:autoscaling:scheduledaction" 747 resource = "ScheduledAction01" 748 name = "MinSize" 749 value = "2" 750 } 751 752 setting { 753 namespace = "aws:autoscaling:scheduledaction" 754 resource = "ScheduledAction01" 755 name = "MaxSize" 756 value = "6" 757 } 758 759 setting { 760 namespace = "aws:autoscaling:scheduledaction" 761 resource = "ScheduledAction01" 762 name = "Recurrence" 763 value = "0 8 * * *" 764 } 765 } 766 ` 767 768 func testAccBeanstalkEnv_VPC(name string) string { 769 return fmt.Sprintf(` 770 resource "aws_vpc" "tf_b_test" { 771 cidr_block = "10.0.0.0/16" 772 } 773 774 resource "aws_internet_gateway" "tf_b_test" { 775 vpc_id = "${aws_vpc.tf_b_test.id}" 776 } 777 778 resource "aws_route" "r" { 779 route_table_id = "${aws_vpc.tf_b_test.main_route_table_id}" 780 destination_cidr_block = "0.0.0.0/0" 781 gateway_id = "${aws_internet_gateway.tf_b_test.id}" 782 } 783 784 resource "aws_subnet" "main" { 785 vpc_id = "${aws_vpc.tf_b_test.id}" 786 cidr_block = "10.0.0.0/24" 787 } 788 789 resource "aws_security_group" "default" { 790 name = "tf-b-test-%s" 791 vpc_id = "${aws_vpc.tf_b_test.id}" 792 } 793 794 resource "aws_elastic_beanstalk_application" "default" { 795 name = "tf-test-name" 796 description = "tf-test-desc" 797 } 798 799 resource "aws_elastic_beanstalk_environment" "default" { 800 name = "tf-test-name" 801 application = "${aws_elastic_beanstalk_application.default.name}" 802 solution_stack_name = "64bit Amazon Linux running Python" 803 804 setting { 805 namespace = "aws:ec2:vpc" 806 name = "VPCId" 807 value = "${aws_vpc.tf_b_test.id}" 808 } 809 810 setting { 811 namespace = "aws:ec2:vpc" 812 name = "Subnets" 813 value = "${aws_subnet.main.id}" 814 } 815 816 setting { 817 namespace = "aws:ec2:vpc" 818 name = "AssociatePublicIpAddress" 819 value = "true" 820 } 821 822 setting { 823 namespace = "aws:autoscaling:launchconfiguration" 824 name = "SecurityGroups" 825 value = "${aws_security_group.default.id}" 826 } 827 } 828 `, name) 829 } 830 831 func testAccBeanstalkEnv_TemplateChange_stack(r int) string { 832 return fmt.Sprintf(` 833 provider "aws" { 834 region = "us-east-1" 835 } 836 837 resource "aws_elastic_beanstalk_application" "app" { 838 name = "beanstalk-app-%d" 839 description = "" 840 } 841 842 resource "aws_elastic_beanstalk_environment" "environment" { 843 name = "beanstalk-env-%d" 844 application = "${aws_elastic_beanstalk_application.app.name}" 845 846 # Go 1.4 847 848 solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.0 running Go 1.4" 849 } 850 851 resource "aws_elastic_beanstalk_configuration_template" "template" { 852 name = "beanstalk-config-%d" 853 application = "${aws_elastic_beanstalk_application.app.name}" 854 855 # Go 1.5 856 solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.3 running Go 1.5" 857 } 858 `, r, r, r) 859 } 860 861 func testAccBeanstalkEnv_TemplateChange_temp(r int) string { 862 return fmt.Sprintf(` 863 provider "aws" { 864 region = "us-east-1" 865 } 866 867 resource "aws_elastic_beanstalk_application" "app" { 868 name = "beanstalk-app-%d" 869 description = "" 870 } 871 872 resource "aws_elastic_beanstalk_environment" "environment" { 873 name = "beanstalk-env-%d" 874 application = "${aws_elastic_beanstalk_application.app.name}" 875 876 # Go 1.4 877 878 template_name = "${aws_elastic_beanstalk_configuration_template.template.name}" 879 } 880 881 resource "aws_elastic_beanstalk_configuration_template" "template" { 882 name = "beanstalk-config-%d" 883 application = "${aws_elastic_beanstalk_application.app.name}" 884 885 # Go 1.5 886 solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.3 running Go 1.5" 887 } 888 `, r, r, r) 889 }