@@ -3,7 +3,9 @@ package aws
3
3
import (
4
4
"fmt"
5
5
"log"
6
+ "reflect"
6
7
"regexp"
8
+ "sort"
7
9
"testing"
8
10
9
11
"github.com/aws/aws-sdk-go/aws"
@@ -212,6 +214,93 @@ func TestAccAWSBeanstalkEnv_template_change(t *testing.T) {
212
214
})
213
215
}
214
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 \n got:\n \n %#v\n " , testStrings , foundEnvs )
298
+ }
299
+
300
+ return nil
301
+ }
302
+ }
303
+
215
304
func testAccCheckBeanstalkEnvDestroy (s * terraform.State ) error {
216
305
conn := testAccProvider .Meta ().(* AWSClient ).elasticbeanstalkconn
217
306
@@ -376,6 +465,71 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" {
376
465
}
377
466
`
378
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
+
379
533
const testAccBeanstalkWorkerEnvConfig = `
380
534
resource "aws_iam_instance_profile" "tftest" {
381
535
name = "tftest_profile"
0 commit comments