Skip to content

Commit

Permalink
Adds acceptance tests for EB environment ARN and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Feb 27, 2018
1 parent 652531c commit 6c194ca
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions aws/resource_aws_elastic_beanstalk_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,14 @@ func TestAccAWSBeanstalkEnv_basic(t *testing.T) {
Config: testAccBeanstalkEnvConfig(appName, envName),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
resource.TestMatchResourceAttr(
"aws_elastic_beanstalk_environment.tfenvtest", "arn",
regexp.MustCompile(fmt.Sprintf("^arn:[^:]+:elasticbeanstalk:[^:]+:[^:]+:environment/%s/%s$", appName, envName))),
),
},
},
})

}

func TestAccAWSBeanstalkEnv_tier(t *testing.T) {
Expand Down Expand Up @@ -283,6 +287,49 @@ func TestAccAWSBeanstalkEnv_resource(t *testing.T) {
})
}

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

rString := acctest.RandString(8)
appName := fmt.Sprintf("tf_acc_app_env_resource_%s", rString)
envName := fmt.Sprintf("tf-acc-env-resource-%s", rString)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBeanstalkEnvDestroy,
Steps: []resource.TestStep{
{
Config: testAccBeanstalkEnvConfig_empty_settings(appName, envName),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvTagsMatch(&app, map[string]string{}),
),
},

{
Config: testAccBeanstalkTagsTemplate(appName, envName, "test1", "test2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvTagsMatch(&app, map[string]string{"firstTag": "test1", "secondTag": "test2"}),
),
},

{
Config: testAccBeanstalkTagsTemplate(appName, envName, "test2", "test1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvTagsMatch(&app, map[string]string{"firstTag": "test2", "secondTag": "test1"}),
),
},

{
Config: testAccBeanstalkEnvConfig_empty_settings(appName, envName),
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvTagsMatch(&app, map[string]string{}),
),
},
},
})
}

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

Expand Down Expand Up @@ -629,6 +676,32 @@ func testAccCheckBeanstalkEnvConfigValue(n string, expectedValue string) resourc
}
}

func testAccCheckBeanstalkEnvTagsMatch(env *elasticbeanstalk.EnvironmentDescription, expectedValue map[string]string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if env == nil {
return fmt.Errorf("Nil environment in testAccCheckBeanstalkEnvTagsMatch")
}

conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn

tags, err := conn.ListTagsForResource(&elasticbeanstalk.ListTagsForResourceInput{
ResourceArn: env.EnvironmentArn,
})

if err != nil {
return err
}

foundTags := tagsToMapBeanstalk(tags.ResourceTags)

if !reflect.DeepEqual(foundTags, expectedValue) {
return fmt.Errorf("Tag value: %s. Expected %s", foundTags, expectedValue)
}

return nil
}
}

func testAccCheckBeanstalkApplicationVersionDeployed(n string, app *elasticbeanstalk.EnvironmentDescription) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -933,6 +1006,27 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" {
}`, appName, envName)
}

func testAccBeanstalkTagsTemplate(appName, envName, firstTag, secondTag string) string {
return fmt.Sprintf(`
resource "aws_elastic_beanstalk_application" "tftest" {
name = "%s"
description = "tf-test-desc"
}
resource "aws_elastic_beanstalk_environment" "tfenvtest" {
name = "%s"
application = "${aws_elastic_beanstalk_application.tftest.name}"
solution_stack_name = "64bit Amazon Linux running Python"
wait_for_ready_timeout = "15m"
tags {
firstTag = "%s"
secondTag = "%s"
}
}`, appName, envName, firstTag, secondTag)
}

func testAccBeanstalkEnv_VPC(sgName, appName, envName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "tf_b_test" {
Expand Down

0 comments on commit 6c194ca

Please sign in to comment.