github.com/boyvanduuren/terraform@v0.7.0-rc2.0.20160805175930-de822d909c40/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"regexp"
     7  	"testing"
     8  
     9  	"github.com/aws/aws-sdk-go/aws"
    10  	"github.com/aws/aws-sdk-go/aws/awserr"
    11  	"github.com/aws/aws-sdk-go/service/elasticbeanstalk"
    12  	"github.com/hashicorp/terraform/helper/acctest"
    13  	"github.com/hashicorp/terraform/helper/resource"
    14  	"github.com/hashicorp/terraform/terraform"
    15  )
    16  
    17  func TestAccAWSBeanstalkEnv_basic(t *testing.T) {
    18  	var app elasticbeanstalk.EnvironmentDescription
    19  
    20  	resource.Test(t, resource.TestCase{
    21  		PreCheck:     func() { testAccPreCheck(t) },
    22  		Providers:    testAccProviders,
    23  		CheckDestroy: testAccCheckBeanstalkEnvDestroy,
    24  		Steps: []resource.TestStep{
    25  			resource.TestStep{
    26  				Config: testAccBeanstalkEnvConfig,
    27  				Check: resource.ComposeTestCheckFunc(
    28  					testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
    29  				),
    30  			},
    31  		},
    32  	})
    33  }
    34  
    35  func TestAccAWSBeanstalkEnv_tier(t *testing.T) {
    36  	var app elasticbeanstalk.EnvironmentDescription
    37  	beanstalkQueuesNameRegexp := regexp.MustCompile("https://sqs.+?awseb[^,]+")
    38  
    39  	resource.Test(t, resource.TestCase{
    40  		PreCheck:     func() { testAccPreCheck(t) },
    41  		Providers:    testAccProviders,
    42  		CheckDestroy: testAccCheckBeanstalkEnvDestroy,
    43  		Steps: []resource.TestStep{
    44  			resource.TestStep{
    45  				Config: testAccBeanstalkWorkerEnvConfig,
    46  				Check: resource.ComposeTestCheckFunc(
    47  					testAccCheckBeanstalkEnvTier("aws_elastic_beanstalk_environment.tfenvtest", &app),
    48  					resource.TestMatchResourceAttr(
    49  						"aws_elastic_beanstalk_environment.tfenvtest", "queues.0", beanstalkQueuesNameRegexp),
    50  				),
    51  			},
    52  		},
    53  	})
    54  }
    55  
    56  func TestAccAWSBeanstalkEnv_outputs(t *testing.T) {
    57  	var app elasticbeanstalk.EnvironmentDescription
    58  	beanstalkAsgNameRegexp := regexp.MustCompile("awseb.+?AutoScalingGroup[^,]+")
    59  	beanstalkElbNameRegexp := regexp.MustCompile("awseb.+?EBLoa[^,]+")
    60  	beanstalkInstancesNameRegexp := regexp.MustCompile("i-([0-9a-fA-F]{8}|[0-9a-fA-F]{17})")
    61  	beanstalkLcNameRegexp := regexp.MustCompile("awseb.+?AutoScalingLaunch[^,]+")
    62  
    63  	resource.Test(t, resource.TestCase{
    64  		PreCheck:     func() { testAccPreCheck(t) },
    65  		Providers:    testAccProviders,
    66  		CheckDestroy: testAccCheckBeanstalkEnvDestroy,
    67  		Steps: []resource.TestStep{
    68  			resource.TestStep{
    69  				Config: testAccBeanstalkEnvConfig,
    70  				Check: resource.ComposeTestCheckFunc(
    71  					testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
    72  					resource.TestMatchResourceAttr(
    73  						"aws_elastic_beanstalk_environment.tfenvtest", "autoscaling_groups.0", beanstalkAsgNameRegexp),
    74  					resource.TestMatchResourceAttr(
    75  						"aws_elastic_beanstalk_environment.tfenvtest", "load_balancers.0", beanstalkElbNameRegexp),
    76  					resource.TestMatchResourceAttr(
    77  						"aws_elastic_beanstalk_environment.tfenvtest", "instances.0", beanstalkInstancesNameRegexp),
    78  					resource.TestMatchResourceAttr(
    79  						"aws_elastic_beanstalk_environment.tfenvtest", "launch_configurations.0", beanstalkLcNameRegexp),
    80  				),
    81  			},
    82  		},
    83  	})
    84  }
    85  
    86  func TestAccAWSBeanstalkEnv_cname_prefix(t *testing.T) {
    87  	var app elasticbeanstalk.EnvironmentDescription
    88  	cnamePrefix := acctest.RandString(8)
    89  	beanstalkCnameRegexp := regexp.MustCompile("^" + cnamePrefix + ".+?elasticbeanstalk.com$")
    90  
    91  	resource.Test(t, resource.TestCase{
    92  		PreCheck:     func() { testAccPreCheck(t) },
    93  		Providers:    testAccProviders,
    94  		CheckDestroy: testAccCheckBeanstalkEnvDestroy,
    95  		Steps: []resource.TestStep{
    96  			resource.TestStep{
    97  				Config: testAccBeanstalkEnvCnamePrefixConfig(cnamePrefix),
    98  				Check: resource.ComposeTestCheckFunc(
    99  					testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
   100  					resource.TestMatchResourceAttr(
   101  						"aws_elastic_beanstalk_environment.tfenvtest", "cname", beanstalkCnameRegexp),
   102  				),
   103  			},
   104  		},
   105  	})
   106  }
   107  
   108  func TestAccAWSBeanstalkEnv_config(t *testing.T) {
   109  	var app elasticbeanstalk.EnvironmentDescription
   110  
   111  	resource.Test(t, resource.TestCase{
   112  		PreCheck:     func() { testAccPreCheck(t) },
   113  		Providers:    testAccProviders,
   114  		CheckDestroy: testAccCheckBeanstalkEnvDestroy,
   115  		Steps: []resource.TestStep{
   116  			resource.TestStep{
   117  				Config: testAccBeanstalkConfigTemplate,
   118  				Check: resource.ComposeTestCheckFunc(
   119  					testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tftest", &app),
   120  					testAccCheckBeanstalkEnvConfigValue("aws_elastic_beanstalk_environment.tftest", "1"),
   121  				),
   122  			},
   123  
   124  			resource.TestStep{
   125  				Config: testAccBeanstalkConfigTemplateUpdate,
   126  				Check: resource.ComposeTestCheckFunc(
   127  					testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tftest", &app),
   128  					testAccCheckBeanstalkEnvConfigValue("aws_elastic_beanstalk_environment.tftest", "2"),
   129  				),
   130  			},
   131  
   132  			resource.TestStep{
   133  				Config: testAccBeanstalkConfigTemplateUpdate,
   134  				Check: resource.ComposeTestCheckFunc(
   135  					testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tftest", &app),
   136  					testAccCheckBeanstalkEnvConfigValue("aws_elastic_beanstalk_environment.tftest", "3"),
   137  				),
   138  			},
   139  		},
   140  	})
   141  }
   142  
   143  func TestAccAWSBeanstalkEnv_resource(t *testing.T) {
   144  	var app elasticbeanstalk.EnvironmentDescription
   145  
   146  	resource.Test(t, resource.TestCase{
   147  		PreCheck:     func() { testAccPreCheck(t) },
   148  		Providers:    testAccProviders,
   149  		CheckDestroy: testAccCheckBeanstalkEnvDestroy,
   150  		Steps: []resource.TestStep{
   151  			resource.TestStep{
   152  				Config: testAccBeanstalkResourceOptionSetting,
   153  				Check: resource.ComposeTestCheckFunc(
   154  					testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
   155  				),
   156  			},
   157  		},
   158  	})
   159  }
   160  
   161  func TestAccAWSBeanstalkEnv_vpc(t *testing.T) {
   162  	var app elasticbeanstalk.EnvironmentDescription
   163  
   164  	resource.Test(t, resource.TestCase{
   165  		PreCheck: func() {
   166  			testAccPreCheck(t)
   167  		},
   168  		Providers:    testAccProviders,
   169  		CheckDestroy: testAccCheckBeanstalkEnvDestroy,
   170  		Steps: []resource.TestStep{
   171  			resource.TestStep{
   172  				Config: testAccBeanstalkEnv_VPC(acctest.RandString(5)),
   173  				Check: resource.ComposeTestCheckFunc(
   174  					testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.default", &app),
   175  				),
   176  			},
   177  		},
   178  	})
   179  }
   180  
   181  func TestAccAWSBeanstalkEnv_template_change(t *testing.T) {
   182  	var app elasticbeanstalk.EnvironmentDescription
   183  
   184  	rInt := acctest.RandInt()
   185  
   186  	resource.Test(t, resource.TestCase{
   187  		PreCheck: func() {
   188  			testAccPreCheck(t)
   189  		},
   190  		Providers:    testAccProviders,
   191  		CheckDestroy: testAccCheckBeanstalkEnvDestroy,
   192  		Steps: []resource.TestStep{
   193  			resource.TestStep{
   194  				Config: testAccBeanstalkEnv_TemplateChange_stack(rInt),
   195  				Check: resource.ComposeTestCheckFunc(
   196  					testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.environment", &app),
   197  				),
   198  			},
   199  			resource.TestStep{
   200  				Config: testAccBeanstalkEnv_TemplateChange_temp(rInt),
   201  				Check: resource.ComposeTestCheckFunc(
   202  					testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.environment", &app),
   203  				),
   204  			},
   205  			resource.TestStep{
   206  				Config: testAccBeanstalkEnv_TemplateChange_stack(rInt),
   207  				Check: resource.ComposeTestCheckFunc(
   208  					testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.environment", &app),
   209  				),
   210  			},
   211  		},
   212  	})
   213  }
   214  
   215  func testAccCheckBeanstalkEnvDestroy(s *terraform.State) error {
   216  	conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn
   217  
   218  	for _, rs := range s.RootModule().Resources {
   219  		if rs.Type != "aws_elastic_beanstalk_environment" {
   220  			continue
   221  		}
   222  
   223  		// Try to find the environment
   224  		describeBeanstalkEnvOpts := &elasticbeanstalk.DescribeEnvironmentsInput{
   225  			EnvironmentIds: []*string{aws.String(rs.Primary.ID)},
   226  		}
   227  		resp, err := conn.DescribeEnvironments(describeBeanstalkEnvOpts)
   228  		if err == nil {
   229  			switch {
   230  			case len(resp.Environments) > 1:
   231  				return fmt.Errorf("Error %d environments match, expected 1", len(resp.Environments))
   232  			case len(resp.Environments) == 1:
   233  				if *resp.Environments[0].Status == "Terminated" {
   234  					return nil
   235  				}
   236  				return fmt.Errorf("Elastic Beanstalk ENV still exists.")
   237  			default:
   238  				return nil
   239  			}
   240  		}
   241  
   242  		// Verify the error is what we want
   243  		ec2err, ok := err.(awserr.Error)
   244  		if !ok {
   245  			return err
   246  		}
   247  		if ec2err.Code() != "InvalidBeanstalkEnvID.NotFound" {
   248  			return err
   249  		}
   250  	}
   251  
   252  	return nil
   253  }
   254  
   255  func testAccCheckBeanstalkEnvExists(n string, app *elasticbeanstalk.EnvironmentDescription) resource.TestCheckFunc {
   256  	return func(s *terraform.State) error {
   257  		rs, ok := s.RootModule().Resources[n]
   258  		if !ok {
   259  			return fmt.Errorf("Not found: %s", n)
   260  		}
   261  
   262  		if rs.Primary.ID == "" {
   263  			return fmt.Errorf("Elastic Beanstalk ENV is not set")
   264  		}
   265  
   266  		env, err := describeBeanstalkEnv(testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn, aws.String(rs.Primary.ID))
   267  		if err != nil {
   268  			return err
   269  		}
   270  
   271  		*app = *env
   272  
   273  		return nil
   274  	}
   275  }
   276  
   277  func testAccCheckBeanstalkEnvTier(n string, app *elasticbeanstalk.EnvironmentDescription) resource.TestCheckFunc {
   278  	return func(s *terraform.State) error {
   279  		rs, ok := s.RootModule().Resources[n]
   280  		if !ok {
   281  			return fmt.Errorf("Not found: %s", n)
   282  		}
   283  
   284  		if rs.Primary.ID == "" {
   285  			return fmt.Errorf("Elastic Beanstalk ENV is not set")
   286  		}
   287  
   288  		env, err := describeBeanstalkEnv(testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn, aws.String(rs.Primary.ID))
   289  		if err != nil {
   290  			return err
   291  		}
   292  		if *env.Tier.Name != "Worker" {
   293  			return fmt.Errorf("Beanstalk Environment tier is %s, expected Worker", *env.Tier.Name)
   294  		}
   295  
   296  		*app = *env
   297  
   298  		return nil
   299  	}
   300  }
   301  
   302  func testAccCheckBeanstalkEnvConfigValue(n string, expectedValue string) resource.TestCheckFunc {
   303  	return func(s *terraform.State) error {
   304  		conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn
   305  
   306  		rs, ok := s.RootModule().Resources[n]
   307  		if !ok {
   308  			return fmt.Errorf("Not found: %s", n)
   309  		}
   310  
   311  		if rs.Primary.ID == "" {
   312  			return fmt.Errorf("Elastic Beanstalk ENV is not set")
   313  		}
   314  
   315  		resp, err := conn.DescribeConfigurationOptions(&elasticbeanstalk.DescribeConfigurationOptionsInput{
   316  			ApplicationName: aws.String(rs.Primary.Attributes["application"]),
   317  			EnvironmentName: aws.String(rs.Primary.Attributes["name"]),
   318  			Options: []*elasticbeanstalk.OptionSpecification{
   319  				{
   320  					Namespace:  aws.String("aws:elasticbeanstalk:application:environment"),
   321  					OptionName: aws.String("TEMPLATE"),
   322  				},
   323  			},
   324  		})
   325  		if err != nil {
   326  			return err
   327  		}
   328  
   329  		if len(resp.Options) != 1 {
   330  			return fmt.Errorf("Found %d options, expected 1.", len(resp.Options))
   331  		}
   332  
   333  		log.Printf("[DEBUG] %d Elastic Beanstalk Option values returned.", len(resp.Options[0].ValueOptions))
   334  
   335  		for _, value := range resp.Options[0].ValueOptions {
   336  			if *value != expectedValue {
   337  				return fmt.Errorf("Option setting value: %s. Expected %s", *value, expectedValue)
   338  			}
   339  		}
   340  
   341  		return nil
   342  	}
   343  }
   344  
   345  func describeBeanstalkEnv(conn *elasticbeanstalk.ElasticBeanstalk,
   346  	envID *string) (*elasticbeanstalk.EnvironmentDescription, error) {
   347  	describeBeanstalkEnvOpts := &elasticbeanstalk.DescribeEnvironmentsInput{
   348  		EnvironmentIds: []*string{envID},
   349  	}
   350  
   351  	log.Printf("[DEBUG] Elastic Beanstalk Environment TEST describe opts: %s", describeBeanstalkEnvOpts)
   352  
   353  	resp, err := conn.DescribeEnvironments(describeBeanstalkEnvOpts)
   354  	if err != nil {
   355  		return &elasticbeanstalk.EnvironmentDescription{}, err
   356  	}
   357  	if len(resp.Environments) == 0 {
   358  		return &elasticbeanstalk.EnvironmentDescription{}, fmt.Errorf("Elastic Beanstalk ENV not found.")
   359  	}
   360  	if len(resp.Environments) > 1 {
   361  		return &elasticbeanstalk.EnvironmentDescription{}, fmt.Errorf("Found %d environments, expected 1.", len(resp.Environments))
   362  	}
   363  	return resp.Environments[0], nil
   364  }
   365  
   366  const testAccBeanstalkEnvConfig = `
   367  resource "aws_elastic_beanstalk_application" "tftest" {
   368    name = "tf-test-name"
   369    description = "tf-test-desc"
   370  }
   371  
   372  resource "aws_elastic_beanstalk_environment" "tfenvtest" {
   373    name = "tf-test-name"
   374    application = "${aws_elastic_beanstalk_application.tftest.name}"
   375    solution_stack_name = "64bit Amazon Linux running Python"
   376  }
   377  `
   378  
   379  const testAccBeanstalkWorkerEnvConfig = `
   380  resource "aws_iam_instance_profile" "tftest" {
   381    name = "tftest_profile"
   382    roles = ["${aws_iam_role.tftest.name}"]
   383  }
   384  
   385  resource "aws_iam_role" "tftest" {
   386    name = "tftest_role"
   387    path = "/"
   388    assume_role_policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Effect\":\"Allow\",\"Sid\":\"\"}]}"
   389  }
   390  
   391  resource "aws_iam_role_policy" "tftest" {
   392    name = "tftest_policy"
   393    role = "${aws_iam_role.tftest.id}"
   394    policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"QueueAccess\",\"Action\":[\"sqs:ChangeMessageVisibility\",\"sqs:DeleteMessage\",\"sqs:ReceiveMessage\"],\"Effect\":\"Allow\",\"Resource\":\"*\"}]}"
   395  }
   396  
   397  resource "aws_elastic_beanstalk_application" "tftest" {
   398    name = "tf-test-name"
   399    description = "tf-test-desc"
   400  }
   401  
   402  resource "aws_elastic_beanstalk_environment" "tfenvtest" {
   403    name = "tf-test-name"
   404    application = "${aws_elastic_beanstalk_application.tftest.name}"
   405    tier = "Worker"
   406    solution_stack_name = "64bit Amazon Linux running Python"
   407  
   408    setting {
   409      namespace = "aws:autoscaling:launchconfiguration"
   410      name      = "IamInstanceProfile"
   411      value     = "${aws_iam_instance_profile.tftest.name}"
   412    }
   413  }
   414  `
   415  
   416  func testAccBeanstalkEnvCnamePrefixConfig(randString string) string {
   417  	return fmt.Sprintf(`
   418  resource "aws_elastic_beanstalk_application" "tftest" {
   419  name = "tf-test-name"
   420  description = "tf-test-desc"
   421  }
   422  
   423  resource "aws_elastic_beanstalk_environment" "tfenvtest" {
   424  name = "tf-test-name"
   425  application = "${aws_elastic_beanstalk_application.tftest.name}"
   426  cname_prefix = "%s"
   427  solution_stack_name = "64bit Amazon Linux running Python"
   428  }
   429  `, randString)
   430  }
   431  
   432  const testAccBeanstalkConfigTemplate = `
   433  resource "aws_elastic_beanstalk_application" "tftest" {
   434    name = "tf-test-name"
   435    description = "tf-test-desc"
   436  }
   437  
   438  resource "aws_elastic_beanstalk_environment" "tftest" {
   439    name = "tf-test-name"
   440    application = "${aws_elastic_beanstalk_application.tftest.name}"
   441    template_name = "${aws_elastic_beanstalk_configuration_template.tftest.name}"
   442  }
   443  
   444  resource "aws_elastic_beanstalk_configuration_template" "tftest" {
   445    name        = "tf-test-original"
   446    application = "${aws_elastic_beanstalk_application.tftest.name}"
   447    solution_stack_name = "64bit Amazon Linux running Python"
   448  
   449    setting {
   450      namespace = "aws:elasticbeanstalk:application:environment"
   451      name      = "TEMPLATE"
   452      value     = "1"
   453   }
   454  }
   455  `
   456  
   457  const testAccBeanstalkConfigTemplateUpdate = `
   458  resource "aws_elastic_beanstalk_application" "tftest" {
   459    name = "tf-test-name"
   460    description = "tf-test-desc"
   461  }
   462  
   463  resource "aws_elastic_beanstalk_environment" "tftest" {
   464    name = "tf-test-name"
   465    application = "${aws_elastic_beanstalk_application.tftest.name}"
   466    template_name = "${aws_elastic_beanstalk_configuration_template.tftest.name}"
   467  }
   468  
   469  resource "aws_elastic_beanstalk_configuration_template" "tftest" {
   470    name        = "tf-test-updated"
   471    application = "${aws_elastic_beanstalk_application.tftest.name}"
   472    solution_stack_name = "64bit Amazon Linux running Python"
   473  
   474    setting {
   475      namespace = "aws:elasticbeanstalk:application:environment"
   476      name      = "TEMPLATE"
   477      value     = "2"
   478    }
   479  }
   480  `
   481  
   482  const testAccBeanstalkConfigTemplateOverride = `
   483  resource "aws_elastic_beanstalk_application" "tftest" {
   484    name = "tf-test-name"
   485    description = "tf-test-desc"
   486  }
   487  
   488  resource "aws_elastic_beanstalk_environment" "tftest" {
   489    name = "tf-test-name"
   490    application = "${aws_elastic_beanstalk_application.tftest.name}"
   491    template_name = "${aws_elastic_beanstalk_configuration_template.tftest.name}"
   492  
   493    setting {
   494      namespace = "aws:elasticbeanstalk:application:environment"
   495      name      = "TEMPLATE"
   496      value     = "3"
   497    }
   498  }
   499  
   500  resource "aws_elastic_beanstalk_configuration_template" "tftest" {
   501    name        = "tf-test-updated"
   502    application = "${aws_elastic_beanstalk_application.tftest.name}"
   503    solution_stack_name = "64bit Amazon Linux running Python"
   504  
   505    setting {
   506      namespace = "aws:elasticbeanstalk:application:environment"
   507      name      = "TEMPLATE"
   508      value     = "2"
   509    }
   510  }
   511  `
   512  const testAccBeanstalkResourceOptionSetting = `
   513  resource "aws_elastic_beanstalk_application" "tftest" {
   514    name = "tf-test-name"
   515    description = "tf-test-desc"
   516  }
   517  
   518  resource "aws_elastic_beanstalk_environment" "tfenvtest" {
   519    name = "tf-test-name"
   520    application = "${aws_elastic_beanstalk_application.tftest.name}"
   521    solution_stack_name = "64bit Amazon Linux running Python"
   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 = "6"
   535    }
   536  
   537    setting {
   538      namespace = "aws:autoscaling:scheduledaction"
   539      resource = "ScheduledAction01"
   540      name = "Recurrence"
   541      value = "0 8 * * *"
   542    }
   543  }
   544  `
   545  
   546  func testAccBeanstalkEnv_VPC(name string) string {
   547  	return fmt.Sprintf(`
   548  resource "aws_vpc" "tf_b_test" {
   549    cidr_block = "10.0.0.0/16"
   550  }
   551  
   552  resource "aws_internet_gateway" "tf_b_test" {
   553    vpc_id = "${aws_vpc.tf_b_test.id}"
   554  }
   555  
   556  resource "aws_route" "r" {
   557    route_table_id = "${aws_vpc.tf_b_test.main_route_table_id}"
   558    destination_cidr_block = "0.0.0.0/0"
   559    gateway_id = "${aws_internet_gateway.tf_b_test.id}"
   560  }
   561  
   562  resource "aws_subnet" "main" {
   563    vpc_id     = "${aws_vpc.tf_b_test.id}"
   564    cidr_block = "10.0.0.0/24"
   565  }
   566  
   567  resource "aws_security_group" "default" {
   568    name = "tf-b-test-%s"
   569    vpc_id = "${aws_vpc.tf_b_test.id}"
   570  }
   571  
   572  resource "aws_elastic_beanstalk_application" "default" {
   573    name = "tf-test-name"
   574    description = "tf-test-desc"
   575  }
   576  
   577  resource "aws_elastic_beanstalk_environment" "default" {
   578    name = "tf-test-name"
   579    application = "${aws_elastic_beanstalk_application.default.name}"
   580    solution_stack_name = "64bit Amazon Linux running Python"
   581  
   582    setting {
   583      namespace = "aws:ec2:vpc"
   584      name      = "VPCId"
   585      value     = "${aws_vpc.tf_b_test.id}"
   586    }
   587  
   588    setting {
   589      namespace = "aws:ec2:vpc"
   590      name      = "Subnets"
   591      value     = "${aws_subnet.main.id}"
   592    }
   593  
   594    setting {
   595      namespace = "aws:ec2:vpc"
   596      name      = "AssociatePublicIpAddress"
   597      value     = "true"
   598    }
   599  
   600    setting {
   601      namespace = "aws:autoscaling:launchconfiguration"
   602      name      = "SecurityGroups"
   603      value     = "${aws_security_group.default.id}"
   604    }
   605  }
   606  `, name)
   607  }
   608  
   609  func testAccBeanstalkEnv_TemplateChange_stack(r int) string {
   610  	return fmt.Sprintf(`
   611  provider "aws" {
   612    region = "us-east-1"
   613  }
   614  
   615  resource "aws_elastic_beanstalk_application" "app" {
   616    name        = "beanstalk-app-%d"
   617    description = ""
   618  }
   619  
   620  resource "aws_elastic_beanstalk_environment" "environment" {
   621    name        = "beanstalk-env-%d"
   622    application = "${aws_elastic_beanstalk_application.app.name}"
   623  
   624    # Go 1.4
   625  
   626    solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.0 running Go 1.4"
   627  }
   628  
   629  resource "aws_elastic_beanstalk_configuration_template" "template" {
   630    name        = "beanstalk-config-%d"
   631    application = "${aws_elastic_beanstalk_application.app.name}"
   632  
   633    # Go 1.5
   634    solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.3 running Go 1.5"
   635  }
   636  `, r, r, r)
   637  }
   638  
   639  func testAccBeanstalkEnv_TemplateChange_temp(r int) string {
   640  	return fmt.Sprintf(`
   641  provider "aws" {
   642    region = "us-east-1"
   643  }
   644  
   645  resource "aws_elastic_beanstalk_application" "app" {
   646    name        = "beanstalk-app-%d"
   647    description = ""
   648  }
   649  
   650  resource "aws_elastic_beanstalk_environment" "environment" {
   651    name        = "beanstalk-env-%d"
   652    application = "${aws_elastic_beanstalk_application.app.name}"
   653  
   654    # Go 1.4
   655  
   656    template_name = "${aws_elastic_beanstalk_configuration_template.template.name}"
   657  }
   658  
   659  resource "aws_elastic_beanstalk_configuration_template" "template" {
   660    name        = "beanstalk-config-%d"
   661    application = "${aws_elastic_beanstalk_application.app.name}"
   662  
   663    # Go 1.5
   664    solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.3 running Go 1.5"
   665  }
   666  `, r, r, r)
   667  }