Skip to content

Commit

Permalink
provider/aws: Fix issue updating ElasticBeanstalk Environment templat…
Browse files Browse the repository at this point in the history
…es (#7811)

* provider/aws: Fix issue removing templates from ElasticBeanstalk

* regression test
  • Loading branch information
catsby authored Jul 26, 2016
1 parent da43730 commit ff9ad3c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i

if d.HasChange("solution_stack_name") {
hasChange = true
updateOpts.SolutionStackName = aws.String(d.Get("solution_stack_name").(string))
if v, ok := d.GetOk("solution_stack_name"); ok {
updateOpts.SolutionStackName = aws.String(v.(string))
}
}

if d.HasChange("setting") {
Expand All @@ -332,7 +334,9 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i

if d.HasChange("template_name") {
hasChange = true
updateOpts.TemplateName = aws.String(d.Get("template_name").(string))
if v, ok := d.GetOk("template_name"); ok {
updateOpts.TemplateName = aws.String(v.(string))
}
}

if hasChange {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,40 @@ func TestAccAWSBeanstalkEnv_vpc(t *testing.T) {
})
}

func TestAccAWSBeanstalkEnv_template_change(t *testing.T) {
var app elasticbeanstalk.EnvironmentDescription

rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckBeanstalkEnvDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccBeanstalkEnv_TemplateChange_stack(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.environment", &app),
),
},
resource.TestStep{
Config: testAccBeanstalkEnv_TemplateChange_temp(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.environment", &app),
),
},
resource.TestStep{
Config: testAccBeanstalkEnv_TemplateChange_stack(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.environment", &app),
),
},
},
})
}

func testAccCheckBeanstalkEnvDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn

Expand Down Expand Up @@ -571,3 +605,63 @@ resource "aws_elastic_beanstalk_environment" "default" {
}
`, name)
}

func testAccBeanstalkEnv_TemplateChange_stack(r int) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}
resource "aws_elastic_beanstalk_application" "app" {
name = "beanstalk-app-%d"
description = ""
}
resource "aws_elastic_beanstalk_environment" "environment" {
name = "beanstalk-env-%d"
application = "${aws_elastic_beanstalk_application.app.name}"
# Go 1.4
solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.0 running Go 1.4"
}
resource "aws_elastic_beanstalk_configuration_template" "template" {
name = "beanstalk-config-%d"
application = "${aws_elastic_beanstalk_application.app.name}"
# Go 1.5
solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.3 running Go 1.5"
}
`, r, r, r)
}

func testAccBeanstalkEnv_TemplateChange_temp(r int) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}
resource "aws_elastic_beanstalk_application" "app" {
name = "beanstalk-app-%d"
description = ""
}
resource "aws_elastic_beanstalk_environment" "environment" {
name = "beanstalk-env-%d"
application = "${aws_elastic_beanstalk_application.app.name}"
# Go 1.4
template_name = "${aws_elastic_beanstalk_configuration_template.template.name}"
}
resource "aws_elastic_beanstalk_configuration_template" "template" {
name = "beanstalk-config-%d"
application = "${aws_elastic_beanstalk_application.app.name}"
# Go 1.5
solution_stack_name = "64bit Amazon Linux 2016.03 v2.1.3 running Go 1.5"
}
`, r, r, r)
}

0 comments on commit ff9ad3c

Please sign in to comment.