-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/aws: Elastic Beanstalk Application and Environment #3157
Closed
Closed
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
f81984c
provider/aws: Elastic Beanstalk WIP
catsby 58bfa55
document elastic beanstalk env
catsby 8da6634
tolerate Beanstalk App not found in read method
catsby 3d177cc
update beanstalk configuration template a bit
catsby 138cc13
Merge branch 'master' into f-aws-elastic-beanstalk
catsby cbc010d
fixes for Elastic Beanstalk after feedback
catsby c257708
Merge branch 'master' into f-aws-elastic-beanstalk
catsby 781c22b
Merge branch 'master' into f-aws-elastic-beanstalk
catsby 0cbf79d
Merge branch 'master' into f-aws-elastic-beanstalk
catsby 0083c8d
Fix issue with recurring plans. For some option setting values the El…
dharrisio 675f6b7
Updating solution_stack_name for new accounts that don't have "64bit…
dharrisio 148aea0
Update optionSettingKeyHash function to hash setting key, not setting…
dharrisio 5df8dfa
Merge pull request #4596 from dharrisio/aws-elastic-beanstalk-recurri…
catsby 2dde588
Merge branch 'master' into f-aws-elastic-beanstalk
catsby 458d7de
Fix security group problem
Bowbaq 6a836e8
Properly detect terminated environments
Bowbaq e1d4d67
Delete configuration template instead of application.
dharrisio 4ddf94f
Fixing resource_aws_elastic_beanstalk_application.go to pass TestAccA…
dharrisio 6a0fba4
Fixing testAccCheckBeanstalkConfigurationTemplateDestroy to handle In…
dharrisio b751f39
Rewrite if/else as switch.
dharrisio e3c5b2e
Updating testAccCheckBeanstalkEnvDestroy to consider an environment i…
dharrisio 1220efd
Merge pull request #4764 from dharrisio/aws-elastic-beanstalk-failing…
catsby e775ae0
Merge pull request #4691 from Originate/mb-fix-generated-security-group
catsby 77c36fe
Merge pull request #4692 from Originate/mb-fix-terminated-env-detection
catsby 38c4bbe
Fixing panic in TestAccAWSBeanstalkEnv_basic. When splitting the valu…
dharrisio 528303e
Merge pull request #4791 from dharrisio/mb-fix-generated-security-gro…
catsby abf10d3
Update to accomodate 47ac10d6
Bowbaq 533d579
Merge pull request #4832 from Originate/mb-aws-elasticbeanstalk-multi…
jen20 d449ef4
Merge branch 'master' into f-aws-elastic-beanstalk
catsby 2b8410c
update godeps
catsby d73e41c
add vendored elasticbeanstalk code
catsby ee5f4d1
Adding tier attribute and associated test to aws_elastic_beanstalk_en…
dharrisio afee005
Sort subnets to avoid spurious diffs
Bowbaq ddc2ca2
Merge branch 'master' into f-aws-elastic-beanstalk
catsby 199c3a4
update beanstalk env for test
catsby 226bc2a
Merge pull request #5208 from Originate/mb-fix-subnet-ordering
catsby 3713f0a
Merge branch 'f-aws-elastic-beanstalk' of github.com:hashicorp/terraf…
catsby 832a190
Merge pull request #5209 from dharrisio/f-aws-elastic-beanstalk-tier
catsby c736fff
Merge branch 'f-aws-elastic-beanstalk' of github.com:hashicorp/terraf…
catsby 6a4b50e
update config template test stack name
catsby 6aa848b
update beanstalk documentation
catsby 592da4e
Merge branch 'master' into f-aws-elastic-beanstalk
catsby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
147 changes: 147 additions & 0 deletions
147
builtin/providers/aws/resource_aws_elastic_beanstalk_application.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"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" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func resourceAwsElasticBeanstalkApplication() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsElasticBeanstalkApplicationCreate, | ||
Read: resourceAwsElasticBeanstalkApplicationRead, | ||
Update: resourceAwsElasticBeanstalkApplicationUpdate, | ||
Delete: resourceAwsElasticBeanstalkApplicationDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"description": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsElasticBeanstalkApplicationCreate(d *schema.ResourceData, meta interface{}) error { | ||
beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn | ||
|
||
// Get the name and description | ||
name := d.Get("name").(string) | ||
description := d.Get("description").(string) | ||
|
||
log.Printf("[DEBUG] Elastic Beanstalk application create: %s, description: %s", name, description) | ||
|
||
req := &elasticbeanstalk.CreateApplicationInput{ | ||
ApplicationName: aws.String(name), | ||
Description: aws.String(description), | ||
} | ||
|
||
_, err := beanstalkConn.CreateApplication(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(name) | ||
|
||
return resourceAwsElasticBeanstalkApplicationRead(d, meta) | ||
} | ||
|
||
func resourceAwsElasticBeanstalkApplicationUpdate(d *schema.ResourceData, meta interface{}) error { | ||
beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn | ||
|
||
if d.HasChange("description") { | ||
if err := resourceAwsElasticBeanstalkApplicationDescriptionUpdate(beanstalkConn, d); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return resourceAwsElasticBeanstalkApplicationRead(d, meta) | ||
} | ||
|
||
func resourceAwsElasticBeanstalkApplicationDescriptionUpdate(beanstalkConn *elasticbeanstalk.ElasticBeanstalk, d *schema.ResourceData) error { | ||
name := d.Get("name").(string) | ||
description := d.Get("description").(string) | ||
|
||
log.Printf("[DEBUG] Elastic Beanstalk application: %s, update description: %s", name, description) | ||
|
||
_, err := beanstalkConn.UpdateApplication(&elasticbeanstalk.UpdateApplicationInput{ | ||
ApplicationName: aws.String(name), | ||
Description: aws.String(description), | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func resourceAwsElasticBeanstalkApplicationRead(d *schema.ResourceData, meta interface{}) error { | ||
a, err := getBeanstalkApplication(d, meta) | ||
if err != nil { | ||
return err | ||
} | ||
if a == nil { | ||
return err | ||
} | ||
|
||
d.Set("description", a.Description) | ||
return nil | ||
} | ||
|
||
func resourceAwsElasticBeanstalkApplicationDelete(d *schema.ResourceData, meta interface{}) error { | ||
beanstalkConn := meta.(*AWSClient).elasticbeanstalkconn | ||
|
||
a, err := getBeanstalkApplication(d, meta) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = beanstalkConn.DeleteApplication(&elasticbeanstalk.DeleteApplicationInput{ | ||
ApplicationName: aws.String(d.Id()), | ||
}) | ||
|
||
return resource.Retry(10*time.Second, func() error { | ||
if a, _ = getBeanstalkApplication(d, meta); a != nil { | ||
return fmt.Errorf("Beanstalk Application still exists") | ||
} | ||
return nil | ||
}) | ||
} | ||
|
||
func getBeanstalkApplication( | ||
d *schema.ResourceData, | ||
meta interface{}) (*elasticbeanstalk.ApplicationDescription, error) { | ||
conn := meta.(*AWSClient).elasticbeanstalkconn | ||
|
||
resp, err := conn.DescribeApplications(&elasticbeanstalk.DescribeApplicationsInput{ | ||
ApplicationNames: []*string{aws.String(d.Id())}, | ||
}) | ||
|
||
if err != nil { | ||
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() != "InvalidBeanstalkAppID.NotFound" { | ||
log.Printf("[Err] Error reading Elastic Beanstalk Application (%s): Application not found", d.Id()) | ||
d.SetId("") | ||
return nil, nil | ||
} | ||
return nil, err | ||
} | ||
|
||
switch { | ||
case len(resp.Applications) > 1: | ||
return nil, fmt.Errorf("Error %d Applications matched, expected 1", len(resp.Applications)) | ||
case len(resp.Applications) == 0: | ||
d.SetId("") | ||
return nil, nil | ||
default: | ||
return resp.Applications[0], nil | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
builtin/providers/aws/resource_aws_elastic_beanstalk_application_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"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" | ||
) | ||
|
||
func TestAccAWSBeanstalkApp_basic(t *testing.T) { | ||
var app elasticbeanstalk.ApplicationDescription | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckBeanstalkAppDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccBeanstalkAppConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckBeanstalkAppExists("aws_elastic_beanstalk_application.tftest", &app), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckBeanstalkAppDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "aws_elastic_beanstalk_application" { | ||
continue | ||
} | ||
|
||
// Try to find the application | ||
DescribeBeanstalkAppOpts := &elasticbeanstalk.DescribeApplicationsInput{ | ||
ApplicationNames: []*string{aws.String(rs.Primary.ID)}, | ||
} | ||
resp, err := conn.DescribeApplications(DescribeBeanstalkAppOpts) | ||
if err == nil { | ||
if len(resp.Applications) > 0 { | ||
return fmt.Errorf("Elastic Beanstalk Application still exists.") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Verify the error is what we want | ||
ec2err, ok := err.(awserr.Error) | ||
if !ok { | ||
return err | ||
} | ||
if ec2err.Code() != "InvalidBeanstalkAppID.NotFound" { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccCheckBeanstalkAppExists(n string, app *elasticbeanstalk.ApplicationDescription) 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 app ID is not set") | ||
} | ||
|
||
conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn | ||
DescribeBeanstalkAppOpts := &elasticbeanstalk.DescribeApplicationsInput{ | ||
ApplicationNames: []*string{aws.String(rs.Primary.ID)}, | ||
} | ||
resp, err := conn.DescribeApplications(DescribeBeanstalkAppOpts) | ||
if err != nil { | ||
return err | ||
} | ||
if len(resp.Applications) == 0 { | ||
return fmt.Errorf("Elastic Beanstalk Application not found.") | ||
} | ||
|
||
*app = *resp.Applications[0] | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccBeanstalkAppConfig = ` | ||
resource "aws_elastic_beanstalk_application" "tftest" { | ||
name = "tf-test-name" | ||
description = "tf-test-desc" | ||
} | ||
` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that this error is expected here makes me feel like we should also be catching it up in
Read
too - instead of just a response wherelen(Applications) == 0
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 8da6634