From 32dafb1c176ba474d00858f0ca0571291a11499f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bie=C5=84kowski?= Date: Fri, 31 Aug 2018 17:06:17 +0200 Subject: [PATCH 1/5] Add support for PlatformArn to ElasticBeanstalk --- ...ource_aws_elastic_beanstalk_environment.go | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_elastic_beanstalk_environment.go b/aws/resource_aws_elastic_beanstalk_environment.go index 1a556fdd984..7ca3d656ec8 100644 --- a/aws/resource_aws_elastic_beanstalk_environment.go +++ b/aws/resource_aws_elastic_beanstalk_environment.go @@ -121,12 +121,17 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, - ConflictsWith: []string{"template_name"}, + ConflictsWith: []string{"platform_arn", "template_name"}, + }, + "platform_arn": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"solution_stack_name", "template_name"}, }, "template_name": { Type: schema.TypeString, Optional: true, - ConflictsWith: []string{"solution_stack_name"}, + ConflictsWith: []string{"solution_stack_name", "platform_arn"}, }, "wait_for_ready_timeout": { Type: schema.TypeString, @@ -211,6 +216,7 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i version := d.Get("version_label").(string) settings := d.Get("setting").(*schema.Set) solutionStack := d.Get("solution_stack_name").(string) + platformArn := d.Get("platform_arn").(string) templateName := d.Get("template_name").(string) // TODO set tags @@ -254,6 +260,10 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i createOpts.SolutionStackName = aws.String(solutionStack) } + if platformArn != "" { + createOpts.PlatformArn = aws.String(platformArn) + } + if templateName != "" { createOpts.TemplateName = aws.String(templateName) } @@ -400,6 +410,13 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i updateOpts.OptionSettings = add } + if d.HasChange("platform_arn") { + hasChange = true + if v, ok := d.GetOk("platform_arn"); ok { + updateOpts.PlatformArn = aws.String(v.(string)) + } + } + if d.HasChange("template_name") { hasChange = true if v, ok := d.GetOk("template_name"); ok { From e0cfdc8d07460938244bc7a3ee5388e6b0c14d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bie=C5=84kowski?= Date: Mon, 8 Oct 2018 19:19:50 +0200 Subject: [PATCH 2/5] Add docs for platform_arn parameter --- website/docs/r/elastic_beanstalk_environment.html.markdown | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/website/docs/r/elastic_beanstalk_environment.html.markdown b/website/docs/r/elastic_beanstalk_environment.html.markdown index c7ffc4eafc4..c7dd63d29c4 100644 --- a/website/docs/r/elastic_beanstalk_environment.html.markdown +++ b/website/docs/r/elastic_beanstalk_environment.html.markdown @@ -50,6 +50,8 @@ The following arguments are supported: off of. Example stacks can be found in the [Amazon API documentation][1] * `template_name` – (Optional) The name of the Elastic Beanstalk Configuration template to use in deployment +* `platform_arn` – (Optional) The [ARN][2] of the Elastic Beanstalk [Platform][3] + to use in deployment * `wait_for_ready_timeout` - (Default: `20m`) The maximum [duration](https://golang.org/pkg/time/#ParseDuration) that Terraform should wait for an Elastic Beanstalk Environment to be in a ready state before timing @@ -126,7 +128,8 @@ In addition to all arguments above, the following attributes are exported: [1]: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.platforms.html - +[2]: https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html +[3]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-beanstalk-environment.html#cfn-beanstalk-environment-platformarn ## Import From 0bc8f7ebf7a7a0beaae70899aabb007b1a0448cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bie=C5=84kowski?= Date: Mon, 8 Oct 2018 20:36:00 +0200 Subject: [PATCH 3/5] Cover new parameter with acceptance test --- ..._aws_elastic_beanstalk_environment_test.go | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_elastic_beanstalk_environment_test.go b/aws/resource_aws_elastic_beanstalk_environment_test.go index b8058e2e46b..ef74be189c0 100644 --- a/aws/resource_aws_elastic_beanstalk_environment_test.go +++ b/aws/resource_aws_elastic_beanstalk_environment_test.go @@ -173,7 +173,6 @@ func TestAccAWSBeanstalkEnv_basic(t *testing.T) { }, }, }) - } func TestAccAWSBeanstalkEnv_tier(t *testing.T) { @@ -539,6 +538,32 @@ func TestAccAWSBeanstalkEnv_settingWithJsonValue(t *testing.T) { }) } +func TestAccAWSBeanstalkEnv_platformArn(t *testing.T) { + var app elasticbeanstalk.EnvironmentDescription + + rString := acctest.RandString(8) + appName := fmt.Sprintf("tf_acc_app_env_platform_arn_%s", rString) + envName := fmt.Sprintf("tf-acc-env-platform-arn-%s", rString) + platformArn := "arn:aws:elasticbeanstalk:us-east-1::platform/Go 1 running on 64bit Amazon Linux/2.9.0" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBeanstalkEnvDestroy, + Steps: []resource.TestStep{ + { + Config: testAccBeanstalkEnvConfig_platform_arn(appName, envName, platformArn), + Check: resource.ComposeTestCheckFunc( + testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), + resource.TestMatchResourceAttr( + "aws_elastic_beanstalk_environment.tfenvtest", "platform_arn", + regexp.MustCompile(fmt.Sprintf("^%s$", platformArn))), + ), + }, + }, + }) +} + func testAccVerifyBeanstalkConfig(env *elasticbeanstalk.EnvironmentDescription, expected []string) resource.TestCheckFunc { return func(s *terraform.State) error { if env == nil { @@ -810,6 +835,26 @@ func testAccBeanstalkEnvConfig(appName, envName string) string { `, appName, envName) } +func testAccBeanstalkEnvConfig_platform_arn(appName, envName, platformArn string) string { + return fmt.Sprintf(` +provider "aws" { + region = "us-east-1" +} + +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}" + platform_arn = "%s" + depends_on = ["aws_elastic_beanstalk_application.tftest"] +} +`, appName, envName, platformArn) +} + func testAccBeanstalkEnvConfig_empty_settings(appName, envName string) string { return fmt.Sprintf(` resource "aws_elastic_beanstalk_application" "tftest" { From 06343b6dce74cdf9ea4838bdd9ccf96e4fde529c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bie=C5=84kowski?= Date: Mon, 8 Oct 2018 22:16:04 +0200 Subject: [PATCH 4/5] PR review --- aws/resource_aws_elastic_beanstalk_environment.go | 4 ++++ aws/resource_aws_elastic_beanstalk_environment_test.go | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/aws/resource_aws_elastic_beanstalk_environment.go b/aws/resource_aws_elastic_beanstalk_environment.go index 7ca3d656ec8..8ea6792ec05 100644 --- a/aws/resource_aws_elastic_beanstalk_environment.go +++ b/aws/resource_aws_elastic_beanstalk_environment.go @@ -625,6 +625,10 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int return err } + if err := d.Set("platform_arn", env.PlatformArn); err != nil { + return err + } + if err := d.Set("autoscaling_groups", flattenBeanstalkAsg(resources.EnvironmentResources.AutoScalingGroups)); err != nil { return err } diff --git a/aws/resource_aws_elastic_beanstalk_environment_test.go b/aws/resource_aws_elastic_beanstalk_environment_test.go index ef74be189c0..a411d1ff53a 100644 --- a/aws/resource_aws_elastic_beanstalk_environment_test.go +++ b/aws/resource_aws_elastic_beanstalk_environment_test.go @@ -555,9 +555,7 @@ func TestAccAWSBeanstalkEnv_platformArn(t *testing.T) { Config: testAccBeanstalkEnvConfig_platform_arn(appName, envName, platformArn), Check: resource.ComposeTestCheckFunc( testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app), - resource.TestMatchResourceAttr( - "aws_elastic_beanstalk_environment.tfenvtest", "platform_arn", - regexp.MustCompile(fmt.Sprintf("^%s$", platformArn))), + resource.TestCheckResourceAttr("aws_elastic_beanstalk_environment.tfenvtest", "platform_arn", platformArn), ), }, }, @@ -849,8 +847,7 @@ resource "aws_elastic_beanstalk_application" "tftest" { resource "aws_elastic_beanstalk_environment" "tfenvtest" { name = "%s" application = "${aws_elastic_beanstalk_application.tftest.name}" - platform_arn = "%s" - depends_on = ["aws_elastic_beanstalk_application.tftest"] + platform_arn = "%s" } `, appName, envName, platformArn) } From fb673bd0ae17b9f178f11f468ab90d8e9ec3dccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bie=C5=84kowski?= Date: Tue, 9 Oct 2018 09:54:26 +0200 Subject: [PATCH 5/5] Use computed: true with new platform_arn parameter --- aws/resource_aws_elastic_beanstalk_environment.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_elastic_beanstalk_environment.go b/aws/resource_aws_elastic_beanstalk_environment.go index 8ea6792ec05..ae7ae16d518 100644 --- a/aws/resource_aws_elastic_beanstalk_environment.go +++ b/aws/resource_aws_elastic_beanstalk_environment.go @@ -126,6 +126,7 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource { "platform_arn": { Type: schema.TypeString, Optional: true, + Computed: true, ConflictsWith: []string{"solution_stack_name", "template_name"}, }, "template_name": {