github.com/mohanarpit/terraform@v0.6.16-0.20160909104007-291f29853544/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{"TF_LOG", "TF_SOME_VAR"}), 239 ), 240 }, 241 resource.TestStep{ 242 Config: testAccBeanstalkEnvConfig_empty_settings(rInt), 243 Check: resource.ComposeTestCheckFunc( 244 testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), 245 testAccVerifyBeanstalkConfig(&app, []string{}), 246 ), 247 }, 248 }, 249 }) 250 } 251 252 func testAccVerifyBeanstalkConfig(env *elasticbeanstalk.EnvironmentDescription, expected []string) resource.TestCheckFunc { 253 return func(s *terraform.State) error { 254 if env == nil { 255 return fmt.Errorf("Nil environment in testAccVerifyBeanstalkConfig") 256 } 257 conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn 258 259 resp, err := conn.DescribeConfigurationSettings(&elasticbeanstalk.DescribeConfigurationSettingsInput{ 260 ApplicationName: env.ApplicationName, 261 EnvironmentName: env.EnvironmentName, 262 }) 263 264 if err != nil { 265 return fmt.Errorf("Error describing config settings in testAccVerifyBeanstalkConfig: %s", err) 266 } 267 268 // should only be 1 environment 269 if len(resp.ConfigurationSettings) != 1 { 270 return fmt.Errorf("Expected only 1 set of Configuration Settings in testAccVerifyBeanstalkConfig, got (%d)", len(resp.ConfigurationSettings)) 271 } 272 273 cs := resp.ConfigurationSettings[0] 274 275 var foundEnvs []string 276 testStrings := []string{"TF_LOG", "TF_SOME_VAR"} 277 for _, os := range cs.OptionSettings { 278 for _, k := range testStrings { 279 if *os.OptionName == k { 280 foundEnvs = append(foundEnvs, k) 281 } 282 } 283 } 284 285 // if expected is zero, then we should not have found any of the predefined 286 // env vars 287 if len(expected) == 0 { 288 if len(foundEnvs) > 0 { 289 return fmt.Errorf("Found configs we should not have: %#v", foundEnvs) 290 } 291 return nil 292 } 293 294 sort.Strings(testStrings) 295 sort.Strings(expected) 296 if !reflect.DeepEqual(testStrings, expected) { 297 return fmt.Errorf("Error matching strings, expected:\n\n%#v\n\ngot:\n\n%#v\n", testStrings, foundEnvs) 298 } 299 300 return nil 301 } 302 } 303 304 func testAccCheckBeanstalkEnvDestroy(s *terraform.State) error { 305 conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn 306 307 for _, rs := range s.RootModule().Resources { 308 if rs.Type != "aws_elastic_beanstalk_environment" { 309 continue 310 } 311 312 // Try to find the environment 313 describeBeanstalkEnvOpts := &elasticbeanstalk.DescribeEnvironmentsInput{ 314 EnvironmentIds: []*string{aws.String(rs.Primary.ID)}, 315 } 316 resp, err := conn.DescribeEnvironments(describeBeanstalkEnvOpts) 317 if err == nil { 318 switch { 319 case len(resp.Environments) > 1: 320 return fmt.Errorf("Error %d environments match, expected 1", len(resp.Environments)) 321 case len(resp.Environments) == 1: 322 if *resp.Environments[0].Status == "Terminated" { 323 return nil 324 } 325 return fmt.Errorf("Elastic Beanstalk ENV still exists.") 326 default: 327 return nil 328 } 329 } 330 331 // Verify the error is what we want 332 ec2err, ok := err.(awserr.Error) 333 if !ok { 334 return err 335 } 336 if ec2err.Code() != "InvalidBeanstalkEnvID.NotFound" { 337 return err 338 } 339 } 340 341 return nil 342 } 343 344 func testAccCheckBeanstalkEnvExists(n string, app *elasticbeanstalk.EnvironmentDescription) resource.TestCheckFunc { 345 return func(s *terraform.State) error { 346 rs, ok := s.RootModule().Resources[n] 347 if !ok { 348 return fmt.Errorf("Not found: %s", n) 349 } 350 351 if rs.Primary.ID == "" { 352 return fmt.Errorf("Elastic Beanstalk ENV is not set") 353 } 354 355 env, err := describeBeanstalkEnv(testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn, aws.String(rs.Primary.ID)) 356 if err != nil { 357 return err 358 } 359 360 *app = *env 361 362 return nil 363 } 364 } 365 366 func testAccCheckBeanstalkEnvTier(n string, app *elasticbeanstalk.EnvironmentDescription) resource.TestCheckFunc { 367 return func(s *terraform.State) error { 368 rs, ok := s.RootModule().Resources[n] 369 if !ok { 370 return fmt.Errorf("Not found: %s", n) 371 } 372 373 if rs.Primary.ID == "" { 374 return fmt.Errorf("Elastic Beanstalk ENV is not set") 375 } 376 377 env, err := describeBeanstalkEnv(testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn, aws.String(rs.Primary.ID)) 378 if err != nil { 379 return err 380 } 381 if *env.Tier.Name != "Worker" { 382 return fmt.Errorf("Beanstalk Environment tier is %s, expected Worker", *env.Tier.Name) 383 } 384 385 *app = *env 386 387 return nil 388 } 389 } 390 391 func testAccCheckBeanstalkEnvConfigValue(n string, expectedValue string) resource.TestCheckFunc { 392 return func(s *terraform.State) error { 393 conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn 394 395 rs, ok := s.RootModule().Resources[n] 396 if !ok { 397 return fmt.Errorf("Not found: %s", n) 398 } 399 400 if rs.Primary.ID == "" { 401 return fmt.Errorf("Elastic Beanstalk ENV is not set") 402 } 403 404 resp, err := conn.DescribeConfigurationOptions(&elasticbeanstalk.DescribeConfigurationOptionsInput{ 405 ApplicationName: aws.String(rs.Primary.Attributes["application"]), 406 EnvironmentName: aws.String(rs.Primary.Attributes["name"]), 407 Options: []*elasticbeanstalk.OptionSpecification{ 408 { 409 Namespace: aws.String("aws:elasticbeanstalk:application:environment"), 410 OptionName: aws.String("TEMPLATE"), 411 }, 412 }, 413 }) 414 if err != nil { 415 return err 416 } 417 418 if len(resp.Options) != 1 { 419 return fmt.Errorf("Found %d options, expected 1.", len(resp.Options)) 420 } 421 422 log.Printf("[DEBUG] %d Elastic Beanstalk Option values returned.", len(resp.Options[0].ValueOptions)) 423 424 for _, value := range resp.Options[0].ValueOptions { 425 if *value != expectedValue { 426 return fmt.Errorf("Option setting value: %s. Expected %s", *value, expectedValue) 427 } 428 } 429 430 return nil 431 } 432 } 433 434 func describeBeanstalkEnv(conn *elasticbeanstalk.ElasticBeanstalk, 435 envID *string) (*elasticbeanstalk.EnvironmentDescription, error) { 436 describeBeanstalkEnvOpts := &elasticbeanstalk.DescribeEnvironmentsInput{ 437 EnvironmentIds: []*string{envID}, 438 } 439 440 log.Printf("[DEBUG] Elastic Beanstalk Environment TEST describe opts: %s", describeBeanstalkEnvOpts) 441 442 resp, err := conn.DescribeEnvironments(describeBeanstalkEnvOpts) 443 if err != nil { 444 return &elasticbeanstalk.EnvironmentDescription{}, err 445 } 446 if len(resp.Environments) == 0 { 447 return &elasticbeanstalk.EnvironmentDescription{}, fmt.Errorf("Elastic Beanstalk ENV not found.") 448 } 449 if len(resp.Environments) > 1 { 450 return &elasticbeanstalk.EnvironmentDescription{}, fmt.Errorf("Found %d environments, expected 1.", len(resp.Environments)) 451 } 452 return resp.Environments[0], nil 453 } 454 455 const testAccBeanstalkEnvConfig = ` 456 resource "aws_elastic_beanstalk_application" "tftest" { 457 name = "tf-test-name" 458 description = "tf-test-desc" 459 } 460 461 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 462 name = "tf-test-name" 463 application = "${aws_elastic_beanstalk_application.tftest.name}" 464 solution_stack_name = "64bit Amazon Linux running Python" 465 } 466 ` 467 468 func testAccBeanstalkEnvConfig_empty_settings(r int) string { 469 return fmt.Sprintf(` 470 resource "aws_elastic_beanstalk_application" "tftest" { 471 name = "tf-test-name-%d" 472 description = "tf-test-desc" 473 } 474 475 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 476 name = "tf-test-name-%d" 477 application = "${aws_elastic_beanstalk_application.tftest.name}" 478 solution_stack_name = "64bit Amazon Linux running Python" 479 480 wait_for_ready_timeout = "15m" 481 }`, r, r) 482 } 483 484 func testAccBeanstalkEnvConfig_settings(r int) string { 485 return fmt.Sprintf(` 486 resource "aws_elastic_beanstalk_application" "tftest" { 487 name = "tf-test-name-%d" 488 description = "tf-test-desc" 489 } 490 491 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 492 name = "tf-test-name-%d" 493 application = "${aws_elastic_beanstalk_application.tftest.name}" 494 solution_stack_name = "64bit Amazon Linux running Python" 495 496 wait_for_ready_timeout = "15m" 497 498 setting { 499 namespace = "aws:elasticbeanstalk:application:environment" 500 name = "TF_LOG" 501 value = "true" 502 } 503 504 setting { 505 namespace = "aws:elasticbeanstalk:application:environment" 506 name = "TF_SOME_VAR" 507 value = "true" 508 } 509 510 setting { 511 namespace = "aws:autoscaling:scheduledaction" 512 resource = "ScheduledAction01" 513 name = "MinSize" 514 value = 2 515 } 516 517 setting { 518 namespace = "aws:autoscaling:scheduledaction" 519 resource = "ScheduledAction01" 520 name = "MaxSize" 521 value = 3 522 } 523 524 setting { 525 namespace = "aws:autoscaling:scheduledaction" 526 resource = "ScheduledAction01" 527 name = "StartTime" 528 value = "2016-07-28T04:07:02Z" 529 } 530 }`, r, r) 531 } 532 533 const testAccBeanstalkWorkerEnvConfig = ` 534 resource "aws_iam_instance_profile" "tftest" { 535 name = "tftest_profile" 536 roles = ["${aws_iam_role.tftest.name}"] 537 } 538 539 resource "aws_iam_role" "tftest" { 540 name = "tftest_role" 541 path = "/" 542 assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Effect\":\"Allow\",\"Sid\":\"\"}]}" 543 } 544 545 resource "aws_iam_role_policy" "tftest" { 546 name = "tftest_policy" 547 role = "${aws_iam_role.tftest.id}" 548 policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"QueueAccess\",\"Action\":[\"sqs:ChangeMessageVisibility\",\"sqs:DeleteMessage\",\"sqs:ReceiveMessage\"],\"Effect\":\"Allow\",\"Resource\":\"*\"}]}" 549 } 550 551 resource "aws_elastic_beanstalk_application" "tftest" { 552 name = "tf-test-name" 553 description = "tf-test-desc" 554 } 555 556 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 557 name = "tf-test-name" 558 application = "${aws_elastic_beanstalk_application.tftest.name}" 559 tier = "Worker" 560 solution_stack_name = "64bit Amazon Linux running Python" 561 562 setting { 563 namespace = "aws:autoscaling:launchconfiguration" 564 name = "IamInstanceProfile" 565 value = "${aws_iam_instance_profile.tftest.name}" 566 } 567 } 568 ` 569 570 func testAccBeanstalkEnvCnamePrefixConfig(randString string) string { 571 return fmt.Sprintf(` 572 resource "aws_elastic_beanstalk_application" "tftest" { 573 name = "tf-test-name" 574 description = "tf-test-desc" 575 } 576 577 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 578 name = "tf-test-name" 579 application = "${aws_elastic_beanstalk_application.tftest.name}" 580 cname_prefix = "%s" 581 solution_stack_name = "64bit Amazon Linux running Python" 582 } 583 `, randString) 584 } 585 586 const testAccBeanstalkConfigTemplate = ` 587 resource "aws_elastic_beanstalk_application" "tftest" { 588 name = "tf-test-name" 589 description = "tf-test-desc" 590 } 591 592 resource "aws_elastic_beanstalk_environment" "tftest" { 593 name = "tf-test-name" 594 application = "${aws_elastic_beanstalk_application.tftest.name}" 595 template_name = "${aws_elastic_beanstalk_configuration_template.tftest.name}" 596 } 597 598 resource "aws_elastic_beanstalk_configuration_template" "tftest" { 599 name = "tf-test-original" 600 application = "${aws_elastic_beanstalk_application.tftest.name}" 601 solution_stack_name = "64bit Amazon Linux running Python" 602 603 setting { 604 namespace = "aws:elasticbeanstalk:application:environment" 605 name = "TEMPLATE" 606 value = "1" 607 } 608 } 609 ` 610 611 const testAccBeanstalkConfigTemplateUpdate = ` 612 resource "aws_elastic_beanstalk_application" "tftest" { 613 name = "tf-test-name" 614 description = "tf-test-desc" 615 } 616 617 resource "aws_elastic_beanstalk_environment" "tftest" { 618 name = "tf-test-name" 619 application = "${aws_elastic_beanstalk_application.tftest.name}" 620 template_name = "${aws_elastic_beanstalk_configuration_template.tftest.name}" 621 } 622 623 resource "aws_elastic_beanstalk_configuration_template" "tftest" { 624 name = "tf-test-updated" 625 application = "${aws_elastic_beanstalk_application.tftest.name}" 626 solution_stack_name = "64bit Amazon Linux running Python" 627 628 setting { 629 namespace = "aws:elasticbeanstalk:application:environment" 630 name = "TEMPLATE" 631 value = "2" 632 } 633 } 634 ` 635 636 const testAccBeanstalkConfigTemplateOverride = ` 637 resource "aws_elastic_beanstalk_application" "tftest" { 638 name = "tf-test-name" 639 description = "tf-test-desc" 640 } 641 642 resource "aws_elastic_beanstalk_environment" "tftest" { 643 name = "tf-test-name" 644 application = "${aws_elastic_beanstalk_application.tftest.name}" 645 template_name = "${aws_elastic_beanstalk_configuration_template.tftest.name}" 646 647 setting { 648 namespace = "aws:elasticbeanstalk:application:environment" 649 name = "TEMPLATE" 650 value = "3" 651 } 652 } 653 654 resource "aws_elastic_beanstalk_configuration_template" "tftest" { 655 name = "tf-test-updated" 656 application = "${aws_elastic_beanstalk_application.tftest.name}" 657 solution_stack_name = "64bit Amazon Linux running Python" 658 659 setting { 660 namespace = "aws:elasticbeanstalk:application:environment" 661 name = "TEMPLATE" 662 value = "2" 663 } 664 } 665 ` 666 const testAccBeanstalkResourceOptionSetting = ` 667 resource "aws_elastic_beanstalk_application" "tftest" { 668 name = "tf-test-name" 669 description = "tf-test-desc" 670 } 671 672 resource "aws_elastic_beanstalk_environment" "tfenvtest" { 673 name = "tf-test-name" 674 application = "${aws_elastic_beanstalk_application.tftest.name}" 675 solution_stack_name = "64bit Amazon Linux running Python" 676 677 setting { 678 namespace = "aws:autoscaling:scheduledaction" 679 resource = "ScheduledAction01" 680 name = "MinSize" 681 value = "2" 682 } 683 684 setting { 685 namespace = "aws:autoscaling:scheduledaction" 686 resource = "ScheduledAction01" 687 name = "MaxSize" 688 value = "6" 689 } 690 691 setting { 692 namespace = "aws:autoscaling:scheduledaction" 693 resource = "ScheduledAction01" 694 name = "Recurrence" 695 value = "0 8 * * *" 696 } 697 } 698 ` 699 700 func testAccBeanstalkEnv_VPC(name string) string { 701 return fmt.Sprintf(` 702 resource "aws_vpc" "tf_b_test" { 703 cidr_block = "10.0.0.0/16" 704 } 705 706 resource "aws_internet_gateway" "tf_b_test" { 707 vpc_id = "${aws_vpc.tf_b_test.id}" 708 } 709 710 resource "aws_route" "r" { 711 route_table_id = "${aws_vpc.tf_b_test.main_route_table_id}" 712 destination_cidr_block = "0.0.0.0/0" 713 gateway_id = "${aws_internet_gateway.tf_b_test.id}" 714 } 715 716 resource "aws_subnet" "main" { 717 vpc_id = "${aws_vpc.tf_b_test.id}" 718 cidr_block = "10.0.0.0/24" 719 } 720 721 resource "aws_security_group" "default" { 722 name = "tf-b-test-%s" 723 vpc_id = "${aws_vpc.tf_b_test.id}" 724 } 725 726 resource "aws_elastic_beanstalk_application" "default" { 727 name = "tf-test-name" 728 description = "tf-test-desc" 729 } 730 731 resource "aws_elastic_beanstalk_environment" "default" { 732 name = "tf-test-name" 733 application = "${aws_elastic_beanstalk_application.default.name}" 734 solution_stack_name = "64bit Amazon Linux running Python" 735 736 setting { 737 namespace = "aws:ec2:vpc" 738 name = "VPCId" 739 value = "${aws_vpc.tf_b_test.id}" 740 } 741 742 setting { 743 namespace = "aws:ec2:vpc" 744 name = "Subnets" 745 value = "${aws_subnet.main.id}" 746 } 747 748 setting { 749 namespace = "aws:ec2:vpc" 750 name = "AssociatePublicIpAddress" 751 value = "true" 752 } 753 754 setting { 755 namespace = "aws:autoscaling:launchconfiguration" 756 name = "SecurityGroups" 757 value = "${aws_security_group.default.id}" 758 } 759 } 760 `, name) 761 } 762 763 func testAccBeanstalkEnv_TemplateChange_stack(r int) string { 764 return fmt.Sprintf(` 765 provider "aws" { 766 region = "us-east-1" 767 } 768 769 resource "aws_elastic_beanstalk_application" "app" { 770 name = "beanstalk-app-%d" 771 description = "" 772 } 773 774 resource "aws_elastic_beanstalk_environment" "environment" { 775 name = "beanstalk-env-%d" 776 application = "${aws_elastic_beanstalk_application.app.name}" 777 778 # Go 1.4 779 780 solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.0 running Go 1.4" 781 } 782 783 resource "aws_elastic_beanstalk_configuration_template" "template" { 784 name = "beanstalk-config-%d" 785 application = "${aws_elastic_beanstalk_application.app.name}" 786 787 # Go 1.5 788 solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.3 running Go 1.5" 789 } 790 `, r, r, r) 791 } 792 793 func testAccBeanstalkEnv_TemplateChange_temp(r int) string { 794 return fmt.Sprintf(` 795 provider "aws" { 796 region = "us-east-1" 797 } 798 799 resource "aws_elastic_beanstalk_application" "app" { 800 name = "beanstalk-app-%d" 801 description = "" 802 } 803 804 resource "aws_elastic_beanstalk_environment" "environment" { 805 name = "beanstalk-env-%d" 806 application = "${aws_elastic_beanstalk_application.app.name}" 807 808 # Go 1.4 809 810 template_name = "${aws_elastic_beanstalk_configuration_template.template.name}" 811 } 812 813 resource "aws_elastic_beanstalk_configuration_template" "template" { 814 name = "beanstalk-config-%d" 815 application = "${aws_elastic_beanstalk_application.app.name}" 816 817 # Go 1.5 818 solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.3 running Go 1.5" 819 } 820 `, r, r, r) 821 }