Skip to content
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

Elastic Beanstalk support for PlatformArn #6093

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions aws/resource_aws_elastic_beanstalk_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
jbienkowski311 marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
44 changes: 43 additions & 1 deletion aws/resource_aws_elastic_beanstalk_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ func TestAccAWSBeanstalkEnv_basic(t *testing.T) {
},
},
})

}

func TestAccAWSBeanstalkEnv_tier(t *testing.T) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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" {
Expand Down
5 changes: 4 additions & 1 deletion website/docs/r/elastic_beanstalk_environment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down