diff --git a/aws/resource_aws_elastic_beanstalk_environment.go b/aws/resource_aws_elastic_beanstalk_environment.go index 1a556fdd984..ae7ae16d518 100644 --- a/aws/resource_aws_elastic_beanstalk_environment.go +++ b/aws/resource_aws_elastic_beanstalk_environment.go @@ -121,12 +121,18 @@ 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, + Computed: 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 +217,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 +261,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 +411,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 { @@ -608,6 +626,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 b8058e2e46b..a411d1ff53a 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,30 @@ 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.TestCheckResourceAttr("aws_elastic_beanstalk_environment.tfenvtest", "platform_arn", platformArn), + ), + }, + }, + }) +} + func testAccVerifyBeanstalkConfig(env *elasticbeanstalk.EnvironmentDescription, expected []string) resource.TestCheckFunc { return func(s *terraform.State) error { if env == nil { @@ -810,6 +833,25 @@ 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" +} +`, appName, envName, platformArn) +} + func testAccBeanstalkEnvConfig_empty_settings(appName, envName string) string { return fmt.Sprintf(` resource "aws_elastic_beanstalk_application" "tftest" { 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