From 8d018ae8575e4eb9b0ae53261a5eab3350cf1c92 Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 11 Nov 2015 18:23:35 -0700 Subject: [PATCH 01/26] Added new resource as_elastic_beanstalk_application_version. --- builtin/providers/aws/provider.go | 1 + ...s_elastic_beanstalk_application_version.go | 161 ++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go diff --git a/builtin/providers/aws/provider.go b/builtin/providers/aws/provider.go index dccfd82cdbeb..4deda664bcb6 100644 --- a/builtin/providers/aws/provider.go +++ b/builtin/providers/aws/provider.go @@ -195,6 +195,7 @@ func Provider() terraform.ResourceProvider { "aws_elasticache_cluster": resourceAwsElasticacheCluster(), "aws_elastic_beanstalk_application": resourceAwsElasticBeanstalkApplication(), "aws_elastic_beanstalk_configuration_template": resourceAwsElasticBeanstalkConfigurationTemplate(), + "aws_elastic_beanstalk_application_version": resourceAwsElasticBeanstalkApplicationVersion(), "aws_elastic_beanstalk_environment": resourceAwsElasticBeanstalkEnvironment(), "aws_elasticache_parameter_group": resourceAwsElasticacheParameterGroup(), "aws_elasticache_security_group": resourceAwsElasticacheSecurityGroup(), diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go new file mode 100644 index 000000000000..ccc79962d90f --- /dev/null +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go @@ -0,0 +1,161 @@ +package aws + +import ( + "github.com/hashicorp/terraform/helper/schema" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/elasticbeanstalk" + "log" + "fmt" +) + +func resourceAwsElasticBeanstalkApplicationVersion() *schema.Resource { + return &schema.Resource{ + Create: resourceAwsElasticBeanstalkApplicationVersionCreate, + Read: resourceAwsElasticBeanstalkApplicationVersionRead, + Update: resourceAwsElasticBeanstalkApplicationVersionUpdate, + Delete: resourceAwsElasticBeanstalkApplicationVersionDelete, + + Schema: map[string]*schema.Schema{ + "application": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "auto": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + }, + "description": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + "bucket": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "key": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + }, + } +} + +func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, meta interface {}) error { + conn := meta.(*AWSClient).elasticbeanstalkconn + + application := d.Get("application").(string) + auto := d.Get("auto").(bool) + description := d.Get("description").(string) + bucket := d.Get("bucket").(string) + key := d.Get("key").(string) + name := d.Get("name").(string) + + s3Location := elasticbeanstalk.S3Location{ + S3Bucket: aws.String(bucket), + S3Key: aws.String(key), + } + + createOpts := elasticbeanstalk.CreateApplicationVersionInput{ + ApplicationName: aws.String(application), + AutoCreateApplication: aws.Bool(auto), + Description: aws.String(description), + SourceBundle: &s3Location, + VersionLabel: aws.String(name), + } + + log.Printf("[DEBUG] Elastic Beanstalk Application Version create opts: %s", createOpts) + _, err := conn.CreateApplicationVersion(&createOpts) + if err != nil { + return err + } + + d.SetId(name) + log.Printf("[INFO] Elastic Beanstalk Application Version Label: %s", name) + + return resourceAwsElasticBeanstalkApplicationVersionRead(d, meta) +} + +func resourceAwsElasticBeanstalkApplicationVersionRead(d *schema.ResourceData, meta interface{}) error { + beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + + name := d.Id() + + resp, err := beanstalkConn.DescribeApplicationVersions(&elasticbeanstalk.DescribeApplicationVersionsInput{ + VersionLabels: []*string{aws.String(name)}, + }) + + if err != nil { + return err + } + + if len(resp.ApplicationVersions) == 0 { + log.Printf("[DEBUG] Elastic Beanstalk application version read: application version not found") + + d.SetId("") + + 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)) + } + + if err := d.Set("description", resp.ApplicationVersions[0].Description); err != nil { + return err + } + + return nil +} + +func resourceAwsElasticBeanstalkApplicationVersionUpdate(d *schema.ResourceData, meta interface{}) error { + beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + + if d.HasChange("description") { + if err := resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(beanstalkConn, d); err != nil { + return err + } + } + + return resourceAwsElasticBeanstalkApplicationVersionRead(d, meta) + +} + +func resourceAwsElasticBeanstalkApplicationVersionDelete(d *schema.ResourceData, meta interface{}) error { + beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + + application := d.Get("application").(string) + name := d.Id() + + _, err := beanstalkConn.DeleteApplicationVersion(&elasticbeanstalk.DeleteApplicationVersionInput{ + ApplicationName: aws.String(application), + VersionLabel: aws.String(name), + }) + + d.SetId("") + + return err +} + +func resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(beanstalkConn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { + application := d.Get("application").(string) + description := d.Get("description").(string) + name := d.Get("name").(string) + + log.Printf("[DEBUG] Elastic Beanstalk application version: %s, update description: %s", name, description) + + _, err := beanstalkConn.UpdateApplicationVersion(&elasticbeanstalk.UpdateApplicationVersionInput{ + ApplicationName: aws.String(application), + Description: aws.String(description), + VersionLabel: aws.String(name), + }) + + return err +} \ No newline at end of file From c408511afd2d830d02b6658d4d21c16e527a71dd Mon Sep 17 00:00:00 2001 From: David Harris Date: Thu, 12 Nov 2015 23:43:39 -0700 Subject: [PATCH 02/26] Adding version_label option to beanstalk_environment resource. --- .../resource_aws_elastic_beanstalk_environment.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go index 7a63f1a8868e..3c7c2677861d 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -53,6 +53,10 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "version_label": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, "cname": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -93,6 +97,7 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i cname := d.Get("cname").(string) app := d.Get("application").(string) desc := d.Get("description").(string) + version := d.Get("version_label").(string) settings := d.Get("setting").(*schema.Set) solutionStack := d.Get("solution_stack_name").(string) templateName := d.Get("template_name").(string) @@ -103,6 +108,7 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i createOpts := elasticbeanstalk.CreateEnvironmentInput{ EnvironmentName: aws.String(name), ApplicationName: aws.String(app), + VersionLabel: aws.String(version), OptionSettings: extractOptionSettings(settings), Tags: tagsFromMapBeanstalk(d.Get("tags").(map[string]interface{})), } @@ -178,12 +184,14 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i func resourceAwsElasticBeanstalkEnvironmentDescriptionUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { name := d.Get("name").(string) desc := d.Get("description").(string) + version := d.Get("version_label").(string) envId := d.Id() log.Printf("[DEBUG] Elastic Beanstalk application: %s, update description: %s", name, desc) _, err := conn.UpdateEnvironment(&elasticbeanstalk.UpdateEnvironmentInput{ EnvironmentId: aws.String(envId), + VersionLabel: aws.String(version), Description: aws.String(desc), }) @@ -273,6 +281,10 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int return err } + if err := d.Set("version_label", env.VersionLabel); err != nil { + return err + } + return resourceAwsElasticBeanstalkEnvironmentSettingsRead(d, meta) } From 3307b09e7f07c6d9d5500e67e4307c2a19119644 Mon Sep 17 00:00:00 2001 From: David Harris Date: Sat, 14 Nov 2015 21:39:48 -0700 Subject: [PATCH 03/26] Handle InvalidParameterValue error when running terraform destroy on an application version. --- ...s_elastic_beanstalk_application_version.go | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go index ccc79962d90f..23f7185d5840 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go @@ -1,12 +1,15 @@ package aws import ( + "fmt" + "log" + "github.com/hashicorp/terraform/helper/schema" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elasticbeanstalk" - "log" - "fmt" + ) func resourceAwsElasticBeanstalkApplicationVersion() *schema.Resource { @@ -50,7 +53,7 @@ func resourceAwsElasticBeanstalkApplicationVersion() *schema.Resource { } } -func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, meta interface {}) error { +func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).elasticbeanstalkconn application := d.Get("application").(string) @@ -62,15 +65,15 @@ func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, s3Location := elasticbeanstalk.S3Location{ S3Bucket: aws.String(bucket), - S3Key: aws.String(key), + S3Key: aws.String(key), } createOpts := elasticbeanstalk.CreateApplicationVersionInput{ - ApplicationName: aws.String(application), + ApplicationName: aws.String(application), AutoCreateApplication: aws.Bool(auto), - Description: aws.String(description), - SourceBundle: &s3Location, - VersionLabel: aws.String(name), + Description: aws.String(description), + SourceBundle: &s3Location, + VersionLabel: aws.String(name), } log.Printf("[DEBUG] Elastic Beanstalk Application Version create opts: %s", createOpts) @@ -136,11 +139,18 @@ func resourceAwsElasticBeanstalkApplicationVersionDelete(d *schema.ResourceData, _, err := beanstalkConn.DeleteApplicationVersion(&elasticbeanstalk.DeleteApplicationVersionInput{ ApplicationName: aws.String(application), - VersionLabel: aws.String(name), + VersionLabel: aws.String(name), }) d.SetId("") + if awserr, ok := err.(awserr.Error); ok { + // application version is pending delete, or no longer exists. + if awserr.Code() == "InvalidParameterValue" { + return nil + } + + } return err } @@ -154,8 +164,8 @@ func resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(beanstalkCon _, err := beanstalkConn.UpdateApplicationVersion(&elasticbeanstalk.UpdateApplicationVersionInput{ ApplicationName: aws.String(application), Description: aws.String(description), - VersionLabel: aws.String(name), + VersionLabel: aws.String(name), }) return err -} \ No newline at end of file +} From 4c3fd07cc961aca203ef65c2b535f3a703765980 Mon Sep 17 00:00:00 2001 From: David Harris Date: Mon, 16 Nov 2015 13:55:02 -0700 Subject: [PATCH 04/26] Add an update check for version_label and create function to update environment when version_label changes. --- ...ource_aws_elastic_beanstalk_environment.go | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go index 3c7c2677861d..404437d1298f 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -178,20 +178,24 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i } } + if d.HasChange("version_label") { + if err := resourceAwsElasticBeanstalkEnvironmentApplicationVersionUpdate(conn, d); err != nil { + return err + } + } + return resourceAwsElasticBeanstalkEnvironmentRead(d, meta) } func resourceAwsElasticBeanstalkEnvironmentDescriptionUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { name := d.Get("name").(string) desc := d.Get("description").(string) - version := d.Get("version_label").(string) envId := d.Id() log.Printf("[DEBUG] Elastic Beanstalk application: %s, update description: %s", name, desc) _, err := conn.UpdateEnvironment(&elasticbeanstalk.UpdateEnvironmentInput{ EnvironmentId: aws.String(envId), - VersionLabel: aws.String(version), Description: aws.String(desc), }) @@ -245,6 +249,21 @@ func resourceAwsElasticBeanstalkEnvironmentSolutionStackUpdate(conn *elasticbean return err } +func resourceAwsElasticBeanstalkEnvironmentApplicationVersionUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { + name := d.Get("name").(string) + version := d.Get("version_label").(string) + envId := d.Id() + + log.Printf("[Debug] Elastic Beanstalk application: %s, update version: %s", name, version) + + _, err := conn.UpdateEnvironment(&elasticbeanstalk.UpdateEnvironmentInput{ + EnvironmentId: aws.String(envId), + VersionLabel: aws.String(version), + }) + + return err +} + func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).elasticbeanstalkconn From 7b76e60f331e0409976b7515e8f665ef3642ed62 Mon Sep 17 00:00:00 2001 From: David Harris Date: Tue, 17 Nov 2015 09:34:57 -0700 Subject: [PATCH 05/26] Adding basic test for Elastic Beanstalk Application Version. --- ...stic_beanstalk_application_version_test.go | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go new file mode 100644 index 000000000000..84a43ba73f34 --- /dev/null +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go @@ -0,0 +1,130 @@ +package aws + +import ( + "testing" + + "fmt" + "io/ioutil" + "log" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" + "github.com/aws/aws-sdk-go/service/elasticbeanstalk" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +var s3File, s3Err = ioutil.TempFile("", "tf.zip") + +func TestAccAWSBeanstalkAppVersion_basic(t *testing.T) { + ioutil.WriteFile(s3File.Name(), []byte("{anything will do }"), 0644) + + var appVersion elasticbeanstalk.ApplicationVersionDescription + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + if s3Err != nil { + panic(s3Err) + } + testAccPreCheck(t) + }, + Providers: testAccProviders, + CheckDestroy: testAccCheckApplicationVersionDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccApplicationVersionConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckApplicationVersionExists("aws_elastic_beanstalk_application_version.default", &appVersion), + ), + }, + }, + }) +} + +func testAccCheckApplicationVersionDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_elastic_beanstalk_application_version" { + continue + } + + describeApplicationVersionOpts := &elasticbeanstalk.DescribeApplicationVersionsInput{ + VersionLabels: []*string{aws.String(rs.Primary.ID)}, + } + resp, err := conn.DescribeApplicationVersions(describeApplicationVersionOpts) + if err == nil { + if len(resp.ApplicationVersions) > 0 { + return fmt.Errorf("Elastic Beanstalk Application Verson still exists.") + } + + return nil + } + ec2err, ok := err.(awserr.Error) + if !ok { + return err + } + if ec2err.Code() != "InvalidParameterValue" { + return err + } + } + + return nil +} + +func testAccCheckApplicationVersionExists(n string, app *elasticbeanstalk.ApplicationVersionDescription) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("Elastic Beanstalk Application Version is not set") + } + + conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn + describeApplicationVersionOpts := &elasticbeanstalk.DescribeApplicationVersionsInput{ + VersionLabels: []*string{aws.String(rs.Primary.ID)}, + } + + log.Printf("[DEBUG] Elastic Beanstalk Application Version TEST describe opts: %s", describeApplicationVersionOpts) + + resp, err := conn.DescribeApplicationVersions(describeApplicationVersionOpts) + if err != nil { + return err + } + if len(resp.ApplicationVersions) == 0 { + return fmt.Errorf("Elastic Beanstalk Application Version not found.") + } + + *app = *resp.ApplicationVersions[0] + + return nil + } +} + +var randomBeanstalkBucket = randInt +var testAccApplicationVersionConfig = 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/go-v1.zip" + source = "%s" +} + +resource "aws_elastic_beanstalk_application" "default" { + name = "tf-test-name" + description = "tf-test-desc" +} + +resource "aws_elastic_beanstalk_application_version" "default" { + application = "tf-test-name" + name = "tf-test-version-label" + bucket = "${aws_s3_bucket.default.id}" + key = "${aws_s3_bucket_object.default.id}" +} +`, randomBeanstalkBucket, s3File.Name()) From 6c944b371e3800a1f4b673fd2635313b7c13c019 Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 18 Nov 2015 19:15:39 -0700 Subject: [PATCH 06/26] Renaming AWSClient connections to conn for consistency. --- ...aws_elastic_beanstalk_application_version.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go index 23f7185d5840..e784a6d9fc6e 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go @@ -9,7 +9,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elasticbeanstalk" - ) func resourceAwsElasticBeanstalkApplicationVersion() *schema.Resource { @@ -89,11 +88,11 @@ func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, } func resourceAwsElasticBeanstalkApplicationVersionRead(d *schema.ResourceData, meta interface{}) error { - beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + conn := meta.(*AWSClient).elasticbeanstalkconn name := d.Id() - resp, err := beanstalkConn.DescribeApplicationVersions(&elasticbeanstalk.DescribeApplicationVersionsInput{ + resp, err := conn.DescribeApplicationVersions(&elasticbeanstalk.DescribeApplicationVersionsInput{ VersionLabels: []*string{aws.String(name)}, }) @@ -119,10 +118,10 @@ func resourceAwsElasticBeanstalkApplicationVersionRead(d *schema.ResourceData, m } func resourceAwsElasticBeanstalkApplicationVersionUpdate(d *schema.ResourceData, meta interface{}) error { - beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + conn := meta.(*AWSClient).elasticbeanstalkconn if d.HasChange("description") { - if err := resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(beanstalkConn, d); err != nil { + if err := resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(conn, d); err != nil { return err } } @@ -132,12 +131,12 @@ func resourceAwsElasticBeanstalkApplicationVersionUpdate(d *schema.ResourceData, } func resourceAwsElasticBeanstalkApplicationVersionDelete(d *schema.ResourceData, meta interface{}) error { - beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + conn := meta.(*AWSClient).elasticbeanstalkconn application := d.Get("application").(string) name := d.Id() - _, err := beanstalkConn.DeleteApplicationVersion(&elasticbeanstalk.DeleteApplicationVersionInput{ + _, err := conn.DeleteApplicationVersion(&elasticbeanstalk.DeleteApplicationVersionInput{ ApplicationName: aws.String(application), VersionLabel: aws.String(name), }) @@ -154,14 +153,14 @@ func resourceAwsElasticBeanstalkApplicationVersionDelete(d *schema.ResourceData, return err } -func resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(beanstalkConn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { +func resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { application := d.Get("application").(string) description := d.Get("description").(string) name := d.Get("name").(string) log.Printf("[DEBUG] Elastic Beanstalk application version: %s, update description: %s", name, description) - _, err := beanstalkConn.UpdateApplicationVersion(&elasticbeanstalk.UpdateApplicationVersionInput{ + _, err := conn.UpdateApplicationVersion(&elasticbeanstalk.UpdateApplicationVersionInput{ ApplicationName: aws.String(application), Description: aws.String(description), VersionLabel: aws.String(name), From 68bd845689c9347d4953853ba53c3428453ab2ec Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 18 Nov 2015 19:40:07 -0700 Subject: [PATCH 07/26] Fixed failed testAccBeanstalkEnvConfig by updating solution_stack_name. --- .../aws/resource_aws_elastic_beanstalk_environment_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go index 26281eccef70..94bab808e378 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go @@ -105,7 +105,7 @@ resource "aws_elastic_beanstalk_application" "tftest" { resource "aws_elastic_beanstalk_environment" "tfenvtest" { name = "tf-test-name" application = "${aws_elastic_beanstalk_application.tftest.name}" - solution_stack_name = "64bit Amazon Linux 2015.03 v2.0.3 running Go 1.4" + solution_stack_name = "64bit Amazon Linux 2015.09 v2.0.4 running Go 1.4" #solution_stack_name = } ` From d06ce54c0879d03b715ae84df96bae9efcf588b6 Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 18 Nov 2015 19:51:58 -0700 Subject: [PATCH 08/26] Updated resourceAwsElasticBeanstalkEnviornmentCreate to treat version_label as optional. --- .../aws/resource_aws_elastic_beanstalk_environment.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go index 404437d1298f..4192e6245c37 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -108,7 +108,6 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i createOpts := elasticbeanstalk.CreateEnvironmentInput{ EnvironmentName: aws.String(name), ApplicationName: aws.String(app), - VersionLabel: aws.String(version), OptionSettings: extractOptionSettings(settings), Tags: tagsFromMapBeanstalk(d.Get("tags").(map[string]interface{})), } @@ -129,6 +128,10 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i createOpts.TemplateName = aws.String(templateName) } + if version != "" { + createOpts.VersionLabel = aws.String(version) + } + log.Printf("[DEBUG] Elastic Beanstalk Environment create opts: %s", createOpts) resp, err := conn.CreateEnvironment(&createOpts) if err != nil { From 8d9c7185abe8bc4e69a575dc260fc1e1ed62aadd Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 18 Nov 2015 20:31:48 -0700 Subject: [PATCH 09/26] Adding new documentation for elastic_beanstalk_application_version resource. Updated elastic_beanstalk_environment documentation to reflect this new resource. --- ...eanstalk_application_version.html.markdown | 63 +++++++++++++++++++ ...lastic_beanstalk_environment.html.markdown | 6 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown diff --git a/website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown b/website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown new file mode 100644 index 000000000000..0be5fcff4ea3 --- /dev/null +++ b/website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown @@ -0,0 +1,63 @@ +--- +layout: "aws" +page_title: "AWS: aws_elastic_beanstalk_application_version" +sidebar_current: "docs-aws-resource-elastic-beanstalk-application-version" +description: |- + Provides an Elastic Beanstalk Application Version Resource +--- + +# aws\_elastic\_beanstalk\_application\_version + +Provides an Elastic Beanstalk Application Version Resource. Elastic Beanstalk allows +you to deploy and manage applications in the AWS cloud without worrying about +the infrastructure that runs those applications. + +This resource creates a Beanstalk Application Version that can be deployed to a Beanstalk +Environment. + +## Example Usage + +``` +resource "aws_s3_bucket" "default" { + bucket = "tftest.applicationversion.bucket" +} + +resource "aws_s3_bucket_object" "default" { + bucket = "${aws_s3_bucket.default.id}" + key = "beanstalk/go-v1.zip" + source = "go-v1.zip" +} + +resource "aws_elastic_beanstalk_application" "default" { + name = "tf-test-name" + description = "tf-test-desc" +} + +resource "aws_elastic_beanstalk_application_version" "default" { + name = "tf-test-version-label" + application = "tf-test-name" + description = "application version created by terraform" + bucket = "${aws_s3_bucket.default.id}" + key = "${aws_s3_bucket_object.default.id}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) A unique name for the this Application Version. +* `application` – (Required) Name of the application that contains the version + to be deployed. +* `description` - (Optional) Short description of the Application Version. +* `bucket` - (Required) Name of S3 bucket where the Application Version is stored. +* `key` - (Required) Name of S3 object that contains the Application Version. + +## Attributes Reference + +The following attributes are exported: + +* `name` - The Application Version name. + + + diff --git a/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown b/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown index d9d28a63b951..3479ca98bc33 100644 --- a/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown +++ b/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown @@ -47,6 +47,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 +* `version_name` - (Optional) The name of the Elastic Beanstalk Application Version + to use * `tags` – (Optional) A set of tags to apply to the Environment. **Note:** at this time the Elastic Beanstalk API does not provide a programatic way of changing these tags after initial application @@ -68,7 +70,9 @@ The following attributes are exported: * `name` * `description` -* `application` – the application specified +* `application` – The application specified +* `version_label` - The Application Version specified +* `cname` - The Elastic Beanstalk CNAME poiting to this Environment * `setting` – Settings specifically set for this Environment * `all_settings` – List of all option settings configured in the Environment. These are a combination of default settings and their overrides from `settings` in From 01bebdd449a5043e655346ba61f1adb0bc3e0ab8 Mon Sep 17 00:00:00 2001 From: David Harris Date: Fri, 8 Jan 2016 10:47:13 -0700 Subject: [PATCH 10/26] Removed auto create application option. This option is unnecessary as there should always be a aws_elastic_beanstalk_application resource defined. --- .../resource_aws_elastic_beanstalk_application_version.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go index e784a6d9fc6e..bdefe1044681 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go @@ -24,11 +24,6 @@ func resourceAwsElasticBeanstalkApplicationVersion() *schema.Resource { Required: true, ForceNew: true, }, - "auto": &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - ForceNew: true, - }, "description": &schema.Schema{ Type: schema.TypeString, Optional: true, @@ -56,7 +51,6 @@ func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, conn := meta.(*AWSClient).elasticbeanstalkconn application := d.Get("application").(string) - auto := d.Get("auto").(bool) description := d.Get("description").(string) bucket := d.Get("bucket").(string) key := d.Get("key").(string) @@ -69,7 +63,6 @@ func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, createOpts := elasticbeanstalk.CreateApplicationVersionInput{ ApplicationName: aws.String(application), - AutoCreateApplication: aws.Bool(auto), Description: aws.String(description), SourceBundle: &s3Location, VersionLabel: aws.String(name), From 0c8843f2c2fd252311a876a4d5cf771950918d9b Mon Sep 17 00:00:00 2001 From: David Harris Date: Sun, 10 Jan 2016 16:59:14 -0700 Subject: [PATCH 11/26] ElasticBeanstalkEnvironmentUpdate with one beanstalk api call. --- ...ource_aws_elastic_beanstalk_environment.go | 107 +++++------------- 1 file changed, 30 insertions(+), 77 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go index 4192e6245c37..3ed4d59542bf 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -138,7 +138,6 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i return err } - // Assign the application name as the resource ID d.SetId(*resp.EnvironmentId) stateConf := &resource.StateChangeConf{ @@ -163,56 +162,18 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).elasticbeanstalkconn - if d.HasChange("description") { - if err := resourceAwsElasticBeanstalkEnvironmentDescriptionUpdate(conn, d); err != nil { - return err - } - } - - if d.HasChange("solution_stack_name") { - if err := resourceAwsElasticBeanstalkEnvironmentSolutionStackUpdate(conn, d); err != nil { - return err - } - } - - if d.HasChange("setting") { - if err := resourceAwsElasticBeanstalkEnvironmentOptionSettingsUpdate(conn, d); err != nil { - return err - } - } - - if d.HasChange("version_label") { - if err := resourceAwsElasticBeanstalkEnvironmentApplicationVersionUpdate(conn, d); err != nil { - return err - } - } - - return resourceAwsElasticBeanstalkEnvironmentRead(d, meta) -} - -func resourceAwsElasticBeanstalkEnvironmentDescriptionUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { - name := d.Get("name").(string) - desc := d.Get("description").(string) envId := d.Id() - log.Printf("[DEBUG] Elastic Beanstalk application: %s, update description: %s", name, desc) - - _, err := conn.UpdateEnvironment(&elasticbeanstalk.UpdateEnvironmentInput{ + updateOpts := elasticbeanstalk.UpdateEnvironmentInput{ EnvironmentId: aws.String(envId), - Description: aws.String(desc), - }) - - return err -} - -func resourceAwsElasticBeanstalkEnvironmentOptionSettingsUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { - name := d.Get("name").(string) - envId := d.Id() + } - log.Printf("[DEBUG] Elastic Beanstalk application: %s, update options", name) + if d.HasChange("description") { + updateOpts.Description = aws.String(d.Get("description").(string)) + } - req := &elasticbeanstalk.UpdateEnvironmentInput{ - EnvironmentId: aws.String(envId), + if d.HasChange("solution_stack_name") { + updateOpts.SolutionStackName = aws.String(d.Get("solution_stack_name").(string)) } if d.HasChange("setting") { @@ -227,44 +188,36 @@ func resourceAwsElasticBeanstalkEnvironmentOptionSettingsUpdate(conn *elasticbea os := o.(*schema.Set) ns := n.(*schema.Set) - req.OptionSettings = extractOptionSettings(ns.Difference(os)) + updateOpts.OptionSettings = extractOptionSettings(ns.Difference(os)) } - if _, err := conn.UpdateEnvironment(req); err != nil { - return err + if d.HasChange("version_label") { + updateOpts.VersionLabel = aws.String(d.Get("version_label").(string)) } - return nil -} - -func resourceAwsElasticBeanstalkEnvironmentSolutionStackUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { - name := d.Get("name").(string) - solutionStack := d.Get("solution_stack_name").(string) - envId := d.Id() - - log.Printf("[DEBUG] Elastic Beanstalk application: %s, update solution_stack_name: %s", name, solutionStack) - - _, err := conn.UpdateEnvironment(&elasticbeanstalk.UpdateEnvironmentInput{ - EnvironmentId: aws.String(envId), - SolutionStackName: aws.String(solutionStack), - }) - - return err -} - -func resourceAwsElasticBeanstalkEnvironmentApplicationVersionUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { - name := d.Get("name").(string) - version := d.Get("version_label").(string) - envId := d.Id() + log.Printf("[DEBUG] Elastic Beanstalk Environment update opts: %s", updateOpts) + _, err := conn.UpdateEnvironment(&updateOpts) + if err != nil { + return err + } - log.Printf("[Debug] Elastic Beanstalk application: %s, update version: %s", name, version) + stateConf := &resource.StateChangeConf{ + Pending: []string{"Launching", "Updating"}, + Target: "Ready", + Refresh: environmentStateRefreshFunc(conn, d.Id()), + Timeout: 10 * time.Minute, + Delay: 10 * time.Second, + MinTimeout: 3 * time.Second, + } - _, err := conn.UpdateEnvironment(&elasticbeanstalk.UpdateEnvironmentInput{ - EnvironmentId: aws.String(envId), - VersionLabel: aws.String(version), - }) + _, err = stateConf.WaitForState() + if err != nil { + return fmt.Errorf( + "Error waiting for Elastic Beanstalk Environment (%s) to become ready: %s", + d.Id(), err) + } - return err + return resourceAwsElasticBeanstalkEnvironmentRead(d, meta) } func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta interface{}) error { From 80f4194414e3f2d5f9ff8ffe46bc03cd42d90c25 Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 11 Nov 2015 18:23:35 -0700 Subject: [PATCH 12/26] Added new resource as_elastic_beanstalk_application_version. --- builtin/providers/aws/provider.go | 1 + ...s_elastic_beanstalk_application_version.go | 161 ++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go diff --git a/builtin/providers/aws/provider.go b/builtin/providers/aws/provider.go index 2a90cb893809..247494eb497a 100644 --- a/builtin/providers/aws/provider.go +++ b/builtin/providers/aws/provider.go @@ -141,6 +141,7 @@ func Provider() terraform.ResourceProvider { "aws_elasticache_security_group": resourceAwsElasticacheSecurityGroup(), "aws_elasticache_subnet_group": resourceAwsElasticacheSubnetGroup(), "aws_elastic_beanstalk_application": resourceAwsElasticBeanstalkApplication(), + "aws_elastic_beanstalk_application_version": resourceAwsElasticBeanstalkApplicationVersion(), "aws_elastic_beanstalk_configuration_template": resourceAwsElasticBeanstalkConfigurationTemplate(), "aws_elastic_beanstalk_environment": resourceAwsElasticBeanstalkEnvironment(), "aws_elasticsearch_domain": resourceAwsElasticSearchDomain(), diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go new file mode 100644 index 000000000000..ccc79962d90f --- /dev/null +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go @@ -0,0 +1,161 @@ +package aws + +import ( + "github.com/hashicorp/terraform/helper/schema" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/elasticbeanstalk" + "log" + "fmt" +) + +func resourceAwsElasticBeanstalkApplicationVersion() *schema.Resource { + return &schema.Resource{ + Create: resourceAwsElasticBeanstalkApplicationVersionCreate, + Read: resourceAwsElasticBeanstalkApplicationVersionRead, + Update: resourceAwsElasticBeanstalkApplicationVersionUpdate, + Delete: resourceAwsElasticBeanstalkApplicationVersionDelete, + + Schema: map[string]*schema.Schema{ + "application": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "auto": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + }, + "description": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + "bucket": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "key": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + }, + } +} + +func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, meta interface {}) error { + conn := meta.(*AWSClient).elasticbeanstalkconn + + application := d.Get("application").(string) + auto := d.Get("auto").(bool) + description := d.Get("description").(string) + bucket := d.Get("bucket").(string) + key := d.Get("key").(string) + name := d.Get("name").(string) + + s3Location := elasticbeanstalk.S3Location{ + S3Bucket: aws.String(bucket), + S3Key: aws.String(key), + } + + createOpts := elasticbeanstalk.CreateApplicationVersionInput{ + ApplicationName: aws.String(application), + AutoCreateApplication: aws.Bool(auto), + Description: aws.String(description), + SourceBundle: &s3Location, + VersionLabel: aws.String(name), + } + + log.Printf("[DEBUG] Elastic Beanstalk Application Version create opts: %s", createOpts) + _, err := conn.CreateApplicationVersion(&createOpts) + if err != nil { + return err + } + + d.SetId(name) + log.Printf("[INFO] Elastic Beanstalk Application Version Label: %s", name) + + return resourceAwsElasticBeanstalkApplicationVersionRead(d, meta) +} + +func resourceAwsElasticBeanstalkApplicationVersionRead(d *schema.ResourceData, meta interface{}) error { + beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + + name := d.Id() + + resp, err := beanstalkConn.DescribeApplicationVersions(&elasticbeanstalk.DescribeApplicationVersionsInput{ + VersionLabels: []*string{aws.String(name)}, + }) + + if err != nil { + return err + } + + if len(resp.ApplicationVersions) == 0 { + log.Printf("[DEBUG] Elastic Beanstalk application version read: application version not found") + + d.SetId("") + + 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)) + } + + if err := d.Set("description", resp.ApplicationVersions[0].Description); err != nil { + return err + } + + return nil +} + +func resourceAwsElasticBeanstalkApplicationVersionUpdate(d *schema.ResourceData, meta interface{}) error { + beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + + if d.HasChange("description") { + if err := resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(beanstalkConn, d); err != nil { + return err + } + } + + return resourceAwsElasticBeanstalkApplicationVersionRead(d, meta) + +} + +func resourceAwsElasticBeanstalkApplicationVersionDelete(d *schema.ResourceData, meta interface{}) error { + beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + + application := d.Get("application").(string) + name := d.Id() + + _, err := beanstalkConn.DeleteApplicationVersion(&elasticbeanstalk.DeleteApplicationVersionInput{ + ApplicationName: aws.String(application), + VersionLabel: aws.String(name), + }) + + d.SetId("") + + return err +} + +func resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(beanstalkConn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { + application := d.Get("application").(string) + description := d.Get("description").(string) + name := d.Get("name").(string) + + log.Printf("[DEBUG] Elastic Beanstalk application version: %s, update description: %s", name, description) + + _, err := beanstalkConn.UpdateApplicationVersion(&elasticbeanstalk.UpdateApplicationVersionInput{ + ApplicationName: aws.String(application), + Description: aws.String(description), + VersionLabel: aws.String(name), + }) + + return err +} \ No newline at end of file From e241a4cda29170431f3639386728632c3a212ee8 Mon Sep 17 00:00:00 2001 From: David Harris Date: Thu, 12 Nov 2015 23:43:39 -0700 Subject: [PATCH 13/26] Adding version_label option to beanstalk_environment resource. --- .../resource_aws_elastic_beanstalk_environment.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go index a22b9fa841f6..332a2d843ae0 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -56,6 +56,10 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "version_label": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, "cname": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -96,6 +100,7 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i cname := d.Get("cname").(string) app := d.Get("application").(string) desc := d.Get("description").(string) + version := d.Get("version_label").(string) settings := d.Get("setting").(*schema.Set) solutionStack := d.Get("solution_stack_name").(string) templateName := d.Get("template_name").(string) @@ -106,6 +111,7 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i createOpts := elasticbeanstalk.CreateEnvironmentInput{ EnvironmentName: aws.String(name), ApplicationName: aws.String(app), + VersionLabel: aws.String(version), OptionSettings: extractOptionSettings(settings), Tags: tagsFromMapBeanstalk(d.Get("tags").(map[string]interface{})), } @@ -181,12 +187,14 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i func resourceAwsElasticBeanstalkEnvironmentDescriptionUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { name := d.Get("name").(string) desc := d.Get("description").(string) + version := d.Get("version_label").(string) envId := d.Id() log.Printf("[DEBUG] Elastic Beanstalk application: %s, update description: %s", name, desc) _, err := conn.UpdateEnvironment(&elasticbeanstalk.UpdateEnvironmentInput{ EnvironmentId: aws.String(envId), + VersionLabel: aws.String(version), Description: aws.String(desc), }) @@ -283,6 +291,10 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int return err } + if err := d.Set("version_label", env.VersionLabel); err != nil { + return err + } + return resourceAwsElasticBeanstalkEnvironmentSettingsRead(d, meta) } From 26b830c7666faefc4279b9938a60402d42656435 Mon Sep 17 00:00:00 2001 From: David Harris Date: Sat, 14 Nov 2015 21:39:48 -0700 Subject: [PATCH 14/26] Handle InvalidParameterValue error when running terraform destroy on an application version. --- ...s_elastic_beanstalk_application_version.go | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go index ccc79962d90f..23f7185d5840 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go @@ -1,12 +1,15 @@ package aws import ( + "fmt" + "log" + "github.com/hashicorp/terraform/helper/schema" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elasticbeanstalk" - "log" - "fmt" + ) func resourceAwsElasticBeanstalkApplicationVersion() *schema.Resource { @@ -50,7 +53,7 @@ func resourceAwsElasticBeanstalkApplicationVersion() *schema.Resource { } } -func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, meta interface {}) error { +func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).elasticbeanstalkconn application := d.Get("application").(string) @@ -62,15 +65,15 @@ func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, s3Location := elasticbeanstalk.S3Location{ S3Bucket: aws.String(bucket), - S3Key: aws.String(key), + S3Key: aws.String(key), } createOpts := elasticbeanstalk.CreateApplicationVersionInput{ - ApplicationName: aws.String(application), + ApplicationName: aws.String(application), AutoCreateApplication: aws.Bool(auto), - Description: aws.String(description), - SourceBundle: &s3Location, - VersionLabel: aws.String(name), + Description: aws.String(description), + SourceBundle: &s3Location, + VersionLabel: aws.String(name), } log.Printf("[DEBUG] Elastic Beanstalk Application Version create opts: %s", createOpts) @@ -136,11 +139,18 @@ func resourceAwsElasticBeanstalkApplicationVersionDelete(d *schema.ResourceData, _, err := beanstalkConn.DeleteApplicationVersion(&elasticbeanstalk.DeleteApplicationVersionInput{ ApplicationName: aws.String(application), - VersionLabel: aws.String(name), + VersionLabel: aws.String(name), }) d.SetId("") + if awserr, ok := err.(awserr.Error); ok { + // application version is pending delete, or no longer exists. + if awserr.Code() == "InvalidParameterValue" { + return nil + } + + } return err } @@ -154,8 +164,8 @@ func resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(beanstalkCon _, err := beanstalkConn.UpdateApplicationVersion(&elasticbeanstalk.UpdateApplicationVersionInput{ ApplicationName: aws.String(application), Description: aws.String(description), - VersionLabel: aws.String(name), + VersionLabel: aws.String(name), }) return err -} \ No newline at end of file +} From b73af4e4150be7d162f45d4187f4b45a4eab2dd8 Mon Sep 17 00:00:00 2001 From: David Harris Date: Mon, 16 Nov 2015 13:55:02 -0700 Subject: [PATCH 15/26] Add an update check for version_label and create function to update environment when version_label changes. --- ...ource_aws_elastic_beanstalk_environment.go | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go index 332a2d843ae0..60d0206826e2 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -181,20 +181,24 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i } } + if d.HasChange("version_label") { + if err := resourceAwsElasticBeanstalkEnvironmentApplicationVersionUpdate(conn, d); err != nil { + return err + } + } + return resourceAwsElasticBeanstalkEnvironmentRead(d, meta) } func resourceAwsElasticBeanstalkEnvironmentDescriptionUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { name := d.Get("name").(string) desc := d.Get("description").(string) - version := d.Get("version_label").(string) envId := d.Id() log.Printf("[DEBUG] Elastic Beanstalk application: %s, update description: %s", name, desc) _, err := conn.UpdateEnvironment(&elasticbeanstalk.UpdateEnvironmentInput{ EnvironmentId: aws.String(envId), - VersionLabel: aws.String(version), Description: aws.String(desc), }) @@ -248,6 +252,21 @@ func resourceAwsElasticBeanstalkEnvironmentSolutionStackUpdate(conn *elasticbean return err } +func resourceAwsElasticBeanstalkEnvironmentApplicationVersionUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { + name := d.Get("name").(string) + version := d.Get("version_label").(string) + envId := d.Id() + + log.Printf("[Debug] Elastic Beanstalk application: %s, update version: %s", name, version) + + _, err := conn.UpdateEnvironment(&elasticbeanstalk.UpdateEnvironmentInput{ + EnvironmentId: aws.String(envId), + VersionLabel: aws.String(version), + }) + + return err +} + func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).elasticbeanstalkconn From dd999a90c03e2b5d65f99783c7dc30b95a9332be Mon Sep 17 00:00:00 2001 From: David Harris Date: Tue, 17 Nov 2015 09:34:57 -0700 Subject: [PATCH 16/26] Adding basic test for Elastic Beanstalk Application Version. --- ...stic_beanstalk_application_version_test.go | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go new file mode 100644 index 000000000000..84a43ba73f34 --- /dev/null +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go @@ -0,0 +1,130 @@ +package aws + +import ( + "testing" + + "fmt" + "io/ioutil" + "log" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" + "github.com/aws/aws-sdk-go/service/elasticbeanstalk" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +var s3File, s3Err = ioutil.TempFile("", "tf.zip") + +func TestAccAWSBeanstalkAppVersion_basic(t *testing.T) { + ioutil.WriteFile(s3File.Name(), []byte("{anything will do }"), 0644) + + var appVersion elasticbeanstalk.ApplicationVersionDescription + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + if s3Err != nil { + panic(s3Err) + } + testAccPreCheck(t) + }, + Providers: testAccProviders, + CheckDestroy: testAccCheckApplicationVersionDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccApplicationVersionConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckApplicationVersionExists("aws_elastic_beanstalk_application_version.default", &appVersion), + ), + }, + }, + }) +} + +func testAccCheckApplicationVersionDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_elastic_beanstalk_application_version" { + continue + } + + describeApplicationVersionOpts := &elasticbeanstalk.DescribeApplicationVersionsInput{ + VersionLabels: []*string{aws.String(rs.Primary.ID)}, + } + resp, err := conn.DescribeApplicationVersions(describeApplicationVersionOpts) + if err == nil { + if len(resp.ApplicationVersions) > 0 { + return fmt.Errorf("Elastic Beanstalk Application Verson still exists.") + } + + return nil + } + ec2err, ok := err.(awserr.Error) + if !ok { + return err + } + if ec2err.Code() != "InvalidParameterValue" { + return err + } + } + + return nil +} + +func testAccCheckApplicationVersionExists(n string, app *elasticbeanstalk.ApplicationVersionDescription) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("Elastic Beanstalk Application Version is not set") + } + + conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn + describeApplicationVersionOpts := &elasticbeanstalk.DescribeApplicationVersionsInput{ + VersionLabels: []*string{aws.String(rs.Primary.ID)}, + } + + log.Printf("[DEBUG] Elastic Beanstalk Application Version TEST describe opts: %s", describeApplicationVersionOpts) + + resp, err := conn.DescribeApplicationVersions(describeApplicationVersionOpts) + if err != nil { + return err + } + if len(resp.ApplicationVersions) == 0 { + return fmt.Errorf("Elastic Beanstalk Application Version not found.") + } + + *app = *resp.ApplicationVersions[0] + + return nil + } +} + +var randomBeanstalkBucket = randInt +var testAccApplicationVersionConfig = 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/go-v1.zip" + source = "%s" +} + +resource "aws_elastic_beanstalk_application" "default" { + name = "tf-test-name" + description = "tf-test-desc" +} + +resource "aws_elastic_beanstalk_application_version" "default" { + application = "tf-test-name" + name = "tf-test-version-label" + bucket = "${aws_s3_bucket.default.id}" + key = "${aws_s3_bucket_object.default.id}" +} +`, randomBeanstalkBucket, s3File.Name()) From 9cafc94f3545e334461675f24d2220da3642e29f Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 18 Nov 2015 19:15:39 -0700 Subject: [PATCH 17/26] Renaming AWSClient connections to conn for consistency. --- ...aws_elastic_beanstalk_application_version.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go index 23f7185d5840..e784a6d9fc6e 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go @@ -9,7 +9,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elasticbeanstalk" - ) func resourceAwsElasticBeanstalkApplicationVersion() *schema.Resource { @@ -89,11 +88,11 @@ func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, } func resourceAwsElasticBeanstalkApplicationVersionRead(d *schema.ResourceData, meta interface{}) error { - beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + conn := meta.(*AWSClient).elasticbeanstalkconn name := d.Id() - resp, err := beanstalkConn.DescribeApplicationVersions(&elasticbeanstalk.DescribeApplicationVersionsInput{ + resp, err := conn.DescribeApplicationVersions(&elasticbeanstalk.DescribeApplicationVersionsInput{ VersionLabels: []*string{aws.String(name)}, }) @@ -119,10 +118,10 @@ func resourceAwsElasticBeanstalkApplicationVersionRead(d *schema.ResourceData, m } func resourceAwsElasticBeanstalkApplicationVersionUpdate(d *schema.ResourceData, meta interface{}) error { - beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + conn := meta.(*AWSClient).elasticbeanstalkconn if d.HasChange("description") { - if err := resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(beanstalkConn, d); err != nil { + if err := resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(conn, d); err != nil { return err } } @@ -132,12 +131,12 @@ func resourceAwsElasticBeanstalkApplicationVersionUpdate(d *schema.ResourceData, } func resourceAwsElasticBeanstalkApplicationVersionDelete(d *schema.ResourceData, meta interface{}) error { - beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn + conn := meta.(*AWSClient).elasticbeanstalkconn application := d.Get("application").(string) name := d.Id() - _, err := beanstalkConn.DeleteApplicationVersion(&elasticbeanstalk.DeleteApplicationVersionInput{ + _, err := conn.DeleteApplicationVersion(&elasticbeanstalk.DeleteApplicationVersionInput{ ApplicationName: aws.String(application), VersionLabel: aws.String(name), }) @@ -154,14 +153,14 @@ func resourceAwsElasticBeanstalkApplicationVersionDelete(d *schema.ResourceData, return err } -func resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(beanstalkConn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { +func resourceAwsElasticBeanstalkApplicationVersionDescriptionUpdate(conn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { application := d.Get("application").(string) description := d.Get("description").(string) name := d.Get("name").(string) log.Printf("[DEBUG] Elastic Beanstalk application version: %s, update description: %s", name, description) - _, err := beanstalkConn.UpdateApplicationVersion(&elasticbeanstalk.UpdateApplicationVersionInput{ + _, err := conn.UpdateApplicationVersion(&elasticbeanstalk.UpdateApplicationVersionInput{ ApplicationName: aws.String(application), Description: aws.String(description), VersionLabel: aws.String(name), From c20e63886f85459d4671ece936dd6ebf2964e006 Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 18 Nov 2015 19:51:58 -0700 Subject: [PATCH 18/26] Updated resourceAwsElasticBeanstalkEnviornmentCreate to treat version_label as optional. --- .../aws/resource_aws_elastic_beanstalk_environment.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go index 60d0206826e2..8e8f280f293a 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -111,7 +111,6 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i createOpts := elasticbeanstalk.CreateEnvironmentInput{ EnvironmentName: aws.String(name), ApplicationName: aws.String(app), - VersionLabel: aws.String(version), OptionSettings: extractOptionSettings(settings), Tags: tagsFromMapBeanstalk(d.Get("tags").(map[string]interface{})), } @@ -132,6 +131,10 @@ func resourceAwsElasticBeanstalkEnvironmentCreate(d *schema.ResourceData, meta i createOpts.TemplateName = aws.String(templateName) } + if version != "" { + createOpts.VersionLabel = aws.String(version) + } + log.Printf("[DEBUG] Elastic Beanstalk Environment create opts: %s", createOpts) resp, err := conn.CreateEnvironment(&createOpts) if err != nil { From 3566c5436c3d1adf7a636707604cd0943ce9e0b8 Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 18 Nov 2015 20:31:48 -0700 Subject: [PATCH 19/26] Adding new documentation for elastic_beanstalk_application_version resource. Updated elastic_beanstalk_environment documentation to reflect this new resource. --- ...eanstalk_application_version.html.markdown | 63 +++++++++++++++++++ ...lastic_beanstalk_environment.html.markdown | 6 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown diff --git a/website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown b/website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown new file mode 100644 index 000000000000..0be5fcff4ea3 --- /dev/null +++ b/website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown @@ -0,0 +1,63 @@ +--- +layout: "aws" +page_title: "AWS: aws_elastic_beanstalk_application_version" +sidebar_current: "docs-aws-resource-elastic-beanstalk-application-version" +description: |- + Provides an Elastic Beanstalk Application Version Resource +--- + +# aws\_elastic\_beanstalk\_application\_version + +Provides an Elastic Beanstalk Application Version Resource. Elastic Beanstalk allows +you to deploy and manage applications in the AWS cloud without worrying about +the infrastructure that runs those applications. + +This resource creates a Beanstalk Application Version that can be deployed to a Beanstalk +Environment. + +## Example Usage + +``` +resource "aws_s3_bucket" "default" { + bucket = "tftest.applicationversion.bucket" +} + +resource "aws_s3_bucket_object" "default" { + bucket = "${aws_s3_bucket.default.id}" + key = "beanstalk/go-v1.zip" + source = "go-v1.zip" +} + +resource "aws_elastic_beanstalk_application" "default" { + name = "tf-test-name" + description = "tf-test-desc" +} + +resource "aws_elastic_beanstalk_application_version" "default" { + name = "tf-test-version-label" + application = "tf-test-name" + description = "application version created by terraform" + bucket = "${aws_s3_bucket.default.id}" + key = "${aws_s3_bucket_object.default.id}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) A unique name for the this Application Version. +* `application` – (Required) Name of the application that contains the version + to be deployed. +* `description` - (Optional) Short description of the Application Version. +* `bucket` - (Required) Name of S3 bucket where the Application Version is stored. +* `key` - (Required) Name of S3 object that contains the Application Version. + +## Attributes Reference + +The following attributes are exported: + +* `name` - The Application Version name. + + + diff --git a/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown b/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown index d9d28a63b951..3479ca98bc33 100644 --- a/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown +++ b/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown @@ -47,6 +47,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 +* `version_name` - (Optional) The name of the Elastic Beanstalk Application Version + to use * `tags` – (Optional) A set of tags to apply to the Environment. **Note:** at this time the Elastic Beanstalk API does not provide a programatic way of changing these tags after initial application @@ -68,7 +70,9 @@ The following attributes are exported: * `name` * `description` -* `application` – the application specified +* `application` – The application specified +* `version_label` - The Application Version specified +* `cname` - The Elastic Beanstalk CNAME poiting to this Environment * `setting` – Settings specifically set for this Environment * `all_settings` – List of all option settings configured in the Environment. These are a combination of default settings and their overrides from `settings` in From 4df23d3f327558e91602d05421ed80b43b6c46b8 Mon Sep 17 00:00:00 2001 From: David Harris Date: Fri, 8 Jan 2016 10:47:13 -0700 Subject: [PATCH 20/26] Removed auto create application option. This option is unnecessary as there should always be a aws_elastic_beanstalk_application resource defined. --- .../resource_aws_elastic_beanstalk_application_version.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go index e784a6d9fc6e..bdefe1044681 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go @@ -24,11 +24,6 @@ func resourceAwsElasticBeanstalkApplicationVersion() *schema.Resource { Required: true, ForceNew: true, }, - "auto": &schema.Schema{ - Type: schema.TypeBool, - Optional: true, - ForceNew: true, - }, "description": &schema.Schema{ Type: schema.TypeString, Optional: true, @@ -56,7 +51,6 @@ func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, conn := meta.(*AWSClient).elasticbeanstalkconn application := d.Get("application").(string) - auto := d.Get("auto").(bool) description := d.Get("description").(string) bucket := d.Get("bucket").(string) key := d.Get("key").(string) @@ -69,7 +63,6 @@ func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, createOpts := elasticbeanstalk.CreateApplicationVersionInput{ ApplicationName: aws.String(application), - AutoCreateApplication: aws.Bool(auto), Description: aws.String(description), SourceBundle: &s3Location, VersionLabel: aws.String(name), From 3cbf5b955af576555875eddf41d365edb41f8ace Mon Sep 17 00:00:00 2001 From: David Harris Date: Fri, 22 Jan 2016 10:29:49 -0700 Subject: [PATCH 21/26] gofmt --- .../resource_aws_elastic_beanstalk_application_version.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go index bdefe1044681..bffe18613c5e 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version.go @@ -62,10 +62,10 @@ func resourceAwsElasticBeanstalkApplicationVersionCreate(d *schema.ResourceData, } createOpts := elasticbeanstalk.CreateApplicationVersionInput{ - ApplicationName: aws.String(application), - Description: aws.String(description), - SourceBundle: &s3Location, - VersionLabel: aws.String(name), + ApplicationName: aws.String(application), + Description: aws.String(description), + SourceBundle: &s3Location, + VersionLabel: aws.String(name), } log.Printf("[DEBUG] Elastic Beanstalk Application Version create opts: %s", createOpts) From 28010c9a7ebdc72e03757df74c49de74ab16be88 Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 3 Feb 2016 10:28:14 -0700 Subject: [PATCH 22/26] Minor formating and wording changes to documentation. --- ...eanstalk_application_version.html.markdown | 16 ++---- ...lastic_beanstalk_environment.html.markdown | 56 +++++++++---------- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown b/website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown index 0be5fcff4ea3..22ca5f86bf0f 100644 --- a/website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown +++ b/website/source/docs/providers/aws/r/elastic_beanstalk_application_version.html.markdown @@ -8,11 +8,11 @@ description: |- # aws\_elastic\_beanstalk\_application\_version -Provides an Elastic Beanstalk Application Version Resource. Elastic Beanstalk allows -you to deploy and manage applications in the AWS cloud without worrying about +Provides an Elastic Beanstalk Application Version Resource. Elastic Beanstalk allows +you to deploy and manage applications in the AWS cloud without worrying about the infrastructure that runs those applications. -This resource creates a Beanstalk Application Version that can be deployed to a Beanstalk +This resource creates a Beanstalk Application Version that can be deployed to a Beanstalk Environment. ## Example Usage @@ -47,17 +47,13 @@ resource "aws_elastic_beanstalk_application_version" "default" { The following arguments are supported: * `name` - (Required) A unique name for the this Application Version. -* `application` – (Required) Name of the application that contains the version - to be deployed. +* `application` - (Required) Name of the Beanstalk Application the version is associated with. * `description` - (Optional) Short description of the Application Version. -* `bucket` - (Required) Name of S3 bucket where the Application Version is stored. -* `key` - (Required) Name of S3 object that contains the Application Version. +* `bucket` - (Required) S3 bucket that contains the Application Version source bundle. +* `key` - (Required) S3 object that is the Application Version source bundle. ## Attributes Reference The following attributes are exported: * `name` - The Application Version name. - - - diff --git a/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown b/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown index 3479ca98bc33..6b618f6166aa 100644 --- a/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown +++ b/website/source/docs/providers/aws/r/elastic_beanstalk_environment.html.markdown @@ -8,11 +8,11 @@ description: |- # aws\_elastic\_beanstalk\_environment -Provides an Elastic Beanstalk Environment Resource. Elastic Beanstalk allows -you to deploy and manage applications in the AWS cloud without worrying about +Provides an Elastic Beanstalk Environment Resource. Elastic Beanstalk allows +you to deploy and manage applications in the AWS cloud without worrying about the infrastructure that runs those applications. -Environments are often things such as `development`, `integration`, or +Environments are often things such as `development`, `integration`, or `production`. ## Example Usage @@ -35,23 +35,23 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" { The following arguments are supported: -* `name` - (Required) A unique name for the this Environment. This name is used - in the application URL -* `application` – (Required) Name of the application that contains the version - to be deployed -* `description` - (Optional) Short description of the Environment -* `setting` – (Optional) Option settings to configure the new Environment. These +* `name` - (Required) A unique name for the this Environment. This name is used + in the application URL. +* `application` - (Required) Name of the application that contains the version + to be deployed. +* `description` - (Optional) Short description of the Environment. +* `setting` - (Optional) Option settings to configure the new Environment. These override specific values that are set as defaults. The format is detailed - below in [Option Settings](#option-settings) -* `solution_stack_name` – (Optional) A solution stack to base your environment -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 -* `version_name` - (Optional) The name of the Elastic Beanstalk Application Version - to use -* `tags` – (Optional) A set of tags to apply to the Environment. **Note:** at + below in [Option Settings](#option-settings). +* `solution_stack_name` - (Optional) A solution stack to base your environment +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. +* `version_label` - (Optional) The name of the Elastic Beanstalk Application Version + to use in deployment. +* `tags` - (Optional) A set of tags to apply to the Environment. **Note:** at this time the Elastic Beanstalk API does not provide a programatic way of -changing these tags after initial application +changing these tags after initial application. @@ -59,7 +59,7 @@ changing these tags after initial application The `setting` and `all_settings` mappings support the following format: -* `namespace` - (Optional) unique namespace identifying the option's +* `namespace` - (Optional) unique namespace identifying the option's associated AWS resource * `name` - (Optional) name of the configuration option * `value` - (Optional) value for the configuration option @@ -68,17 +68,15 @@ The `setting` and `all_settings` mappings support the following format: The following attributes are exported: -* `name` -* `description` -* `application` – The application specified -* `version_label` - The Application Version specified -* `cname` - The Elastic Beanstalk CNAME poiting to this Environment -* `setting` – Settings specifically set for this Environment -* `all_settings` – List of all option settings configured in the Environment. These +* `name` - The Elastic Beanstalk environment name. +* `description` - The Elastic Beanstalk environment description. +* `application` - The application specified. +* `version_label` - The Elastic Beanstalk Application Version specified. +* `cname` - The Elastic Beanstalk CNAME poiting to this Environment. +* `setting` - Settings specifically set for this Environment. +* `all_settings` - List of all option settings configured in the Environment. These are a combination of default settings and their overrides from `settings` in - the configuration + the configuration. [1]: http://docs.aws.amazon.com/fr_fr/elasticbeanstalk/latest/dg/concepts.platforms.html - - From e132ac95d5d86988115a236f1fc879c46264460d Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 10 Feb 2016 17:12:26 -0700 Subject: [PATCH 23/26] Cleaned up BeanstalkAppVersion_basic test. Added text fixture for sample beanstalk application used in tests. --- ...elastic_beanstalk_application_version_test.go | 15 +++------------ .../aws/test-fixtures/beanstalk-go-v1.zip | Bin 0 -> 2214 bytes 2 files changed, 3 insertions(+), 12 deletions(-) create mode 100644 builtin/providers/aws/test-fixtures/beanstalk-go-v1.zip diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go index 72c8828007a5..6f21f167e539 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go @@ -4,7 +4,6 @@ import ( "testing" "fmt" - "io/ioutil" "log" "github.com/hashicorp/terraform/helper/acctest" @@ -16,20 +15,12 @@ import ( "github.com/aws/aws-sdk-go/service/elasticbeanstalk" ) -var s3File, s3Err = ioutil.TempFile("", "tf.zip") - func TestAccAWSBeanstalkAppVersion_basic(t *testing.T) { - ioutil.WriteFile(s3File.Name(), []byte("{anything will do }"), 0644) var appVersion elasticbeanstalk.ApplicationVersionDescription resource.Test(t, resource.TestCase{ - PreCheck: func() { - if s3Err != nil { - panic(s3Err) - } - testAccPreCheck(t) - }, + PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckApplicationVersionDestroy, Steps: []resource.TestStep{ @@ -115,7 +106,7 @@ resource "aws_s3_bucket" "default" { resource "aws_s3_bucket_object" "default" { bucket = "${aws_s3_bucket.default.id}" key = "beanstalk/go-v1.zip" - source = "%s" + source = "test-fixtures/beanstalk-go-v1.zip" } resource "aws_elastic_beanstalk_application" "default" { @@ -129,4 +120,4 @@ resource "aws_elastic_beanstalk_application_version" "default" { bucket = "${aws_s3_bucket.default.id}" key = "${aws_s3_bucket_object.default.id}" } -`, randomBeanstalkBucket, s3File.Name()) +`, randomBeanstalkBucket) diff --git a/builtin/providers/aws/test-fixtures/beanstalk-go-v1.zip b/builtin/providers/aws/test-fixtures/beanstalk-go-v1.zip new file mode 100644 index 0000000000000000000000000000000000000000..c8a5e9939e7fa37a29f2543c6b7ed690ba345e8d GIT binary patch literal 2214 zcmZ`*c{mhW8y_@6F^eoE5tT4WK5I?c#V~e8VeH0?v1Q0mmdTQ9%f8EU$Iz+Z{z=7(1_J*O}@@TSpPc?O}xO?MIypa>8XTgdhTh|`HZ0?*)z>Lu$-hY0oj?zvf`e0QdXavcAnt?gfM58O3)zuG+nuF#88Q=As-b>JXF z>D}YR_e1{vla$>C@KV%s@^4&>X>JeIO>q2W#H{n_a6pO;tRulSPZ92bLOsxFsgm#5SYvzl3k7rW$} zNl>_aPjL{}7*^8Goj+)_o09l&=0R*+<4LHW$oB#{oP*N`_)+JX<$|&9z9I!=Z10Qh~9WB zEwOfmz8HSD${LyChQ1ZLq_O)po=(FBznG@FtvpRRU2*8FPJnK@fF89Xt+#dU1)Hd6 z&{N>1H~7Tqo0wt*_Ze!6=X_$$n7pb%1XS`$9N4c!me3uGAv?vAt$$p^m@2nW+tsO| z)!Gxc$=Zx&?N93=Ouc$8hPY(_o;9(3Gn1G#rNyO{qw5J@+hB7^B<-rBm5rnlMx4c! zTu8?r2WDoASpERf*IAlHMt!>n2Z=E*Aym_1$}Ik-qm7l{H7xCXV(1dt&M#P8as*_e zW*jB`=G(Z-uf=p}5&V|MsgT7(0087?F=72Zy~31y2!42my;Z=3IyiFm$@3cVXIwd+ zmwK;1Pd)g~1m!`t8CxM;86NIEqnCcnq$en0XG7AYH%R!&*}4w1=yT~WTenwQWz$~F zi@nR7eE`a>tFMd(Nim&}a^N0pc(97eNYX5@&9S4CH1hkzol5WF!2WDc8RU5k#6ZHg zR=2>vdBQUy<7~Tm?$@{Z7m;z+yqS}8^o8*uWQ$nCtv?UDZo*R+fy!14^RIu=^g1Ul z-3jWwqL}Yl^OSM;I2!6F!1I zg~o)DC=J4CMJwMA4c|HiW(}>53_V)ec@iZ$JjHfT!<9}%{H4%;9m`HO%c?dVk1+@& z`u^>AC?CZ_MY-3b`jVa$6I zEG>Ks8Q;GCN#Cr#`Qs;`tBazKCU+aIG=S)@!4pOtjaG4D4z~PIzAGeg2{Qb8#$y@cj9ms?;XUMFjmHZ!;(3!bKN%@hU&(=fnA#8mKJP z-<)^yIw#`xcgj$|myqu{f{1T#SXI`i|($=uj@8{B4 zxWm|%vNYx5R^{RJxBny6dnX*N1kA+jt^O Date: Wed, 10 Feb 2016 17:31:44 -0700 Subject: [PATCH 24/26] Cleaned up test config name. Moved random bucket name creation to _basic test --- ...urce_aws_elastic_beanstalk_application_version_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go index 6f21f167e539..2560cd92427e 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go @@ -18,6 +18,7 @@ import ( func TestAccAWSBeanstalkAppVersion_basic(t *testing.T) { var appVersion elasticbeanstalk.ApplicationVersionDescription + var randomBeanstalkBucket = acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -25,7 +26,7 @@ func TestAccAWSBeanstalkAppVersion_basic(t *testing.T) { CheckDestroy: testAccCheckApplicationVersionDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccApplicationVersionConfig, + Config: fmt.Sprintf(testAccBeanstalkApplicationVersionConfig, randomBeanstalkBucket), Check: resource.ComposeTestCheckFunc( testAccCheckApplicationVersionExists("aws_elastic_beanstalk_application_version.default", &appVersion), ), @@ -97,8 +98,7 @@ func testAccCheckApplicationVersionExists(n string, app *elasticbeanstalk.Applic } } -var randomBeanstalkBucket = acctest.RandInt() -var testAccApplicationVersionConfig = fmt.Sprintf(` +const testAccBeanstalkApplicationVersionConfig = ` resource "aws_s3_bucket" "default" { bucket = "tftest.applicationversion.bucket-%d" } @@ -120,4 +120,4 @@ resource "aws_elastic_beanstalk_application_version" "default" { bucket = "${aws_s3_bucket.default.id}" key = "${aws_s3_bucket_object.default.id}" } -`, randomBeanstalkBucket) +` From 6de38ca94900772f7d58bb4253b383fedc75f64c Mon Sep 17 00:00:00 2001 From: David Harris Date: Thu, 11 Feb 2016 20:57:32 -0700 Subject: [PATCH 25/26] clean up test terraform document. --- ...aws_elastic_beanstalk_application_version_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go index 2560cd92427e..e1419fb0c835 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_application_version_test.go @@ -1,10 +1,9 @@ package aws import ( - "testing" - "fmt" "log" + "testing" "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" @@ -18,7 +17,6 @@ import ( func TestAccAWSBeanstalkAppVersion_basic(t *testing.T) { var appVersion elasticbeanstalk.ApplicationVersionDescription - var randomBeanstalkBucket = acctest.RandInt() resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -26,7 +24,7 @@ func TestAccAWSBeanstalkAppVersion_basic(t *testing.T) { CheckDestroy: testAccCheckApplicationVersionDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: fmt.Sprintf(testAccBeanstalkApplicationVersionConfig, randomBeanstalkBucket), + Config: testAccBeanstalkApplicationVersionConfig(acctest.RandInt()), Check: resource.ComposeTestCheckFunc( testAccCheckApplicationVersionExists("aws_elastic_beanstalk_application_version.default", &appVersion), ), @@ -98,7 +96,8 @@ func testAccCheckApplicationVersionExists(n string, app *elasticbeanstalk.Applic } } -const testAccBeanstalkApplicationVersionConfig = ` +func testAccBeanstalkApplicationVersionConfig(randInt int) string { + return fmt.Sprintf(` resource "aws_s3_bucket" "default" { bucket = "tftest.applicationversion.bucket-%d" } @@ -119,5 +118,6 @@ resource "aws_elastic_beanstalk_application_version" "default" { name = "tf-test-version-label" bucket = "${aws_s3_bucket.default.id}" key = "${aws_s3_bucket_object.default.id}" + } + `, randInt) } -` From b495df7d8408d68209fb636c379a8c62d6d7eb38 Mon Sep 17 00:00:00 2001 From: David Harris Date: Thu, 11 Feb 2016 21:00:08 -0700 Subject: [PATCH 26/26] Adding TestAccAWSBeanstalkEnv_version_label test. --- ..._aws_elastic_beanstalk_environment_test.go | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go index 5e4b8e3e11db..9fee5eb28dbc 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elasticbeanstalk" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -30,6 +31,24 @@ func TestAccAWSBeanstalkEnv_basic(t *testing.T) { }) } +func TestAccAWSBeanstalkEnv_version_label(t *testing.T) { + var app elasticbeanstalk.EnvironmentDescription + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBeanstalkEnvDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccBeanstalkEnvApplicationVersionConfig(acctest.RandInt()), + Check: resource.ComposeTestCheckFunc( + testAccCheckBeanstalkApplicationVersionDeployed("aws_elastic_beanstalk_environment.default", &app), + ), + }, + }, + }) +} + func testAccCheckBeanstalkEnvDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn @@ -102,6 +121,42 @@ func testAccCheckBeanstalkEnvExists(n string, app *elasticbeanstalk.EnvironmentD } } +func testAccCheckBeanstalkApplicationVersionDeployed(n string, env *elasticbeanstalk.EnvironmentDescription) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("Elastic Beanstalk ENV is not set") + } + + conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn + describeBeanstalkEnvOpts := &elasticbeanstalk.DescribeEnvironmentsInput{ + EnvironmentIds: []*string{aws.String(rs.Primary.ID)}, + } + + log.Printf("[DEBUG] Elastic Beanstalk Environment TEST describe opts: %s", describeBeanstalkEnvOpts) + + resp, err := conn.DescribeEnvironments(describeBeanstalkEnvOpts) + if err != nil { + return err + } + if len(resp.Environments) == 0 { + return fmt.Errorf("Elastic Beanstalk ENV not found.") + } + + if *resp.Environments[0].VersionLabel != rs.Primary.Attributes["version_label"] { + return fmt.Errorf("Elastic Beanstalk version deployed %s. Expected %s", resp.Environments[0].VersionLabel, rs.Primary.Attributes["version_label"]) + } + + *env = *resp.Environments[0] + + return nil + } +} + const testAccBeanstalkEnvConfig = ` resource "aws_elastic_beanstalk_application" "tftest" { name = "tf-test-name" @@ -115,3 +170,36 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" { #solution_stack_name = } ` + +func testAccBeanstalkEnvApplicationVersionConfig(randInt int) string { + return fmt.Sprintf(` +resource "aws_s3_bucket" "default" { + bucket = "tftest.applicationversion.buckets-%d" +} + +resource "aws_s3_bucket_object" "default" { + bucket = "${aws_s3_bucket.default.id}" + key = "beanstalk/go-v1.zip" + source = "test-fixtures/beanstalk-go-v1.zip" +} + +resource "aws_elastic_beanstalk_application" "default" { + name = "tf-test-name" + description = "tf-test-desc" +} + +resource "aws_elastic_beanstalk_application_version" "default" { + application = "tf-test-name" + name = "tf-test-version-label" + bucket = "${aws_s3_bucket.default.id}" + key = "${aws_s3_bucket_object.default.id}" +} + +resource "aws_elastic_beanstalk_environment" "default" { + name = "tf-test-name" + application = "${aws_elastic_beanstalk_application.default.name}" + version_label = "${aws_elastic_beanstalk_application_version.default.name}" + solution_stack_name = "64bit Amazon Linux 2015.09 v2.0.4 running Go 1.4" +} +`, randInt) +}