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

r/elastic_beanstalk_application_version: Scope labels to application #956

Merged
merged 1 commit into from
Jun 27, 2017
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
12 changes: 6 additions & 6 deletions aws/resource_aws_elastic_beanstalk_application_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package aws
import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/schema"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elasticbeanstalk"
"time"
"github.com/hashicorp/terraform/helper/schema"
)

func resourceAwsElasticBeanstalkApplicationVersion() *schema.Resource {
Expand Down Expand Up @@ -90,9 +89,9 @@ func resourceAwsElasticBeanstalkApplicationVersionRead(d *schema.ResourceData, m
conn := meta.(*AWSClient).elasticbeanstalkconn

resp, err := conn.DescribeApplicationVersions(&elasticbeanstalk.DescribeApplicationVersionsInput{
VersionLabels: []*string{aws.String(d.Id())},
ApplicationName: aws.String(d.Get("application").(string)),
VersionLabels: []*string{aws.String(d.Id())},
})

if err != nil {
return err
}
Expand All @@ -104,7 +103,8 @@ func resourceAwsElasticBeanstalkApplicationVersionRead(d *schema.ResourceData, m

return nil
} else if len(resp.ApplicationVersions) != 1 {
return fmt.Errorf("Error reading application version properties: found %d application versions, expected 1", len(resp.ApplicationVersions))
return fmt.Errorf("Error reading application version properties: found %d versions of label %q, expected 1",
len(resp.ApplicationVersions), d.Id())
}

if err := d.Set("description", resp.ApplicationVersions[0].Description); err != nil {
Expand Down
71 changes: 65 additions & 6 deletions aws/resource_aws_elastic_beanstalk_application_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

func TestAccAWSBeanstalkAppVersion_basic(t *testing.T) {

var appVersion elasticbeanstalk.ApplicationVersionDescription

resource.Test(t, resource.TestCase{
Expand All @@ -32,6 +31,26 @@ func TestAccAWSBeanstalkAppVersion_basic(t *testing.T) {
})
}

func TestAccAWSBeanstalkAppVersion_duplicateLabels(t *testing.T) {
var firstAppVersion elasticbeanstalk.ApplicationVersionDescription
var secondAppVersion elasticbeanstalk.ApplicationVersionDescription

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckApplicationVersionDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccBeanstalkApplicationVersionConfig_duplicateLabel(acctest.RandInt()),
Check: resource.ComposeTestCheckFunc(
testAccCheckApplicationVersionExists("aws_elastic_beanstalk_application_version.first", &firstAppVersion),
testAccCheckApplicationVersionExists("aws_elastic_beanstalk_application_version.second", &secondAppVersion),
),
},
},
})
}

func testAccCheckApplicationVersionDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn

Expand All @@ -41,7 +60,8 @@ func testAccCheckApplicationVersionDestroy(s *terraform.State) error {
}

describeApplicationVersionOpts := &elasticbeanstalk.DescribeApplicationVersionsInput{
VersionLabels: []*string{aws.String(rs.Primary.ID)},
ApplicationName: aws.String(rs.Primary.Attributes["application"]),
VersionLabels: []*string{aws.String(rs.Primary.ID)},
}
resp, err := conn.DescribeApplicationVersions(describeApplicationVersionOpts)
if err == nil {
Expand Down Expand Up @@ -76,7 +96,8 @@ func testAccCheckApplicationVersionExists(n string, app *elasticbeanstalk.Applic

conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn
describeApplicationVersionOpts := &elasticbeanstalk.DescribeApplicationVersionsInput{
VersionLabels: []*string{aws.String(rs.Primary.ID)},
ApplicationName: aws.String(rs.Primary.Attributes["application"]),
VersionLabels: []*string{aws.String(rs.Primary.ID)},
}

log.Printf("[DEBUG] Elastic Beanstalk Application Version TEST describe opts: %s", describeApplicationVersionOpts)
Expand Down Expand Up @@ -114,9 +135,47 @@ resource "aws_elastic_beanstalk_application" "default" {

resource "aws_elastic_beanstalk_application_version" "default" {
application = "${aws_elastic_beanstalk_application.default.name}"
name = "tf-test-version-label"
name = "tf-test-version-label-%d"
bucket = "${aws_s3_bucket.default.id}"
key = "${aws_s3_bucket_object.default.id}"
}
`, randInt, randInt, randInt)
}

func testAccBeanstalkApplicationVersionConfig_duplicateLabel(randInt int) string {
return fmt.Sprintf(`
resource "aws_s3_bucket" "default" {
bucket = "tftest.applicationversion.bucket-%d"
}

resource "aws_s3_bucket_object" "default" {
bucket = "${aws_s3_bucket.default.id}"
key = "beanstalk/python-v1.zip"
source = "test-fixtures/python-v1.zip"
}

resource "aws_elastic_beanstalk_application" "first" {
name = "tf-test-name-%d-first"
description = "tf-test-desc"
}

resource "aws_elastic_beanstalk_application_version" "first" {
application = "${aws_elastic_beanstalk_application.first.name}"
name = "tf-test-version-label-%d"
bucket = "${aws_s3_bucket.default.id}"
key = "${aws_s3_bucket_object.default.id}"
}

resource "aws_elastic_beanstalk_application" "second" {
name = "tf-test-name-%d-second"
description = "tf-test-desc"
}

resource "aws_elastic_beanstalk_application_version" "second" {
application = "${aws_elastic_beanstalk_application.second.name}"
name = "tf-test-version-label-%d"
bucket = "${aws_s3_bucket.default.id}"
key = "${aws_s3_bucket_object.default.id}"
}
`, randInt, randInt)
}
`, randInt, randInt, randInt, randInt, randInt)
}