-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closes #3004: adds support for modifying Beanstalk tags #3513
Changes from all commits
13b7b88
652531c
6c194ca
5659931
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -283,6 +287,53 @@ func TestAccAWSBeanstalkEnv_resource(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSBeanstalkEnv_tags(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is currently failing with:
The first test step needs to include this as the first check so FYI you can run the acceptance test locally with |
||
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( | ||
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), | ||
testAccCheckBeanstalkEnvTagsMatch(&app, map[string]string{}), | ||
), | ||
}, | ||
|
||
{ | ||
Config: testAccBeanstalkTagsTemplate(appName, envName, "test1", "test2"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), | ||
testAccCheckBeanstalkEnvTagsMatch(&app, map[string]string{"firstTag": "test1", "secondTag": "test2"}), | ||
), | ||
}, | ||
|
||
{ | ||
Config: testAccBeanstalkTagsTemplate(appName, envName, "test2", "test1"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), | ||
testAccCheckBeanstalkEnvTagsMatch(&app, map[string]string{"firstTag": "test2", "secondTag": "test1"}), | ||
), | ||
}, | ||
|
||
{ | ||
Config: testAccBeanstalkEnvConfig_empty_settings(appName, envName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), | ||
testAccCheckBeanstalkEnvTagsMatch(&app, map[string]string{}), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSBeanstalkEnv_vpc(t *testing.T) { | ||
var app elasticbeanstalk.EnvironmentDescription | ||
|
||
|
@@ -629,6 +680,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] | ||
|
@@ -933,6 +1010,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" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should ensure this new attribute has an associated test of some sort in
TestAccAWSBeanstalkEnv_basic
: