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 3 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
21 changes: 19 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,17 @@ 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,
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 +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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
47 changes: 46 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,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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to:

resource.TestCheckResourceAttr("aws_elastic_beanstalk_environment.tfenvtest", "platform_arn", platformArn),

"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 {
Expand Down Expand Up @@ -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"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two nits:

  • The formatting seems a bit off here (maybe spaces vs tabs?)
  • The depends_on is unnecessary as its already explicitly declared by aws_elastic_beanstalk_application.tftest.name

}
`, 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