-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Add aws_elastic_beanstalk_application Data Source #7144
Merged
bflad
merged 1 commit into
hashicorp:master
from
teraken0509:feature/add-elastic_beanstalk_application-data-source
Jan 15, 2019
Merged
Changes from all commits
Commits
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
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,87 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/elasticbeanstalk" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceAwsElasticBeanstalkApplication() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsElasticBeanstalkApplicationRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"appversion_lifecycle": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"service_role": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"max_age_in_days": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"max_count": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"delete_source_from_s3": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsElasticBeanstalkApplicationRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).elasticbeanstalkconn | ||
|
||
// Get the name and description | ||
name := d.Get("name").(string) | ||
|
||
resp, err := conn.DescribeApplications(&elasticbeanstalk.DescribeApplicationsInput{ | ||
ApplicationNames: []*string{aws.String(name)}, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error describing Applications (%s): %s", name, err) | ||
} | ||
|
||
if len(resp.Applications) > 1 || len(resp.Applications) < 1 { | ||
return fmt.Errorf("Error %d Applications matched, expected 1", len(resp.Applications)) | ||
} | ||
|
||
app := resp.Applications[0] | ||
|
||
d.SetId(name) | ||
d.Set("arn", app.ApplicationArn) | ||
d.Set("name", app.ApplicationName) | ||
d.Set("description", app.Description) | ||
|
||
if app.ResourceLifecycleConfig != nil { | ||
d.Set("appversion_lifecycle", flattenResourceLifecycleConfig(app.ResourceLifecycleConfig)) | ||
} | ||
|
||
return nil | ||
} |
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,45 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAwsElasticBeanstalkApplicationDataSource_basic(t *testing.T) { | ||
rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) | ||
dataSourceResourceName := "data.aws_elastic_beanstalk_application.test" | ||
resourceName := "aws_elastic_beanstalk_application.tftest" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSEksClusterDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAwsElasticBeanstalkApplicationDataSourceConfig_Basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceResourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceResourceName, "name"), | ||
resource.TestCheckResourceAttrPair(resourceName, "description", dataSourceResourceName, "description"), | ||
resource.TestCheckResourceAttr(dataSourceResourceName, "appversion_lifecycle.#", "1"), | ||
resource.TestCheckResourceAttrPair(resourceName, "appversion_lifecycle.0.service_role", dataSourceResourceName, "appversion_lifecycle.0.service_role"), | ||
resource.TestCheckResourceAttrPair(resourceName, "appversion_lifecycle.0.max_age_in_days", dataSourceResourceName, "appversion_lifecycle.0.max_age_in_days"), | ||
resource.TestCheckResourceAttrPair(resourceName, "appversion_lifecycle.0.delete_source_from_s3", dataSourceResourceName, "appversion_lifecycle.0.delete_source_from_s3"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAwsElasticBeanstalkApplicationDataSourceConfig_Basic(rName string) string { | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
data "aws_elastic_beanstalk_application" "test" { | ||
name = "${aws_elastic_beanstalk_application.tftest.name}" | ||
} | ||
`, testAccBeanstalkAppConfigWithMaxAge(rName)) | ||
} |
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
44 changes: 44 additions & 0 deletions
44
website/docs/d/elastic_beanstalk_application.html.markdown
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,44 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_elastic_beanstalk_application" | ||
sidebar_current: "docs-aws-datasource-elastic-beanstalk-application" | ||
description: |- | ||
Retrieve information about an Elastic Beanstalk Application | ||
--- | ||
|
||
# Data Source: aws_elastic_beanstalk_application | ||
|
||
Retrieve information about an Elastic Beanstalk Application. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_elastic_beanstalk_application" "example" { | ||
name = "example" | ||
} | ||
|
||
output "arn" { | ||
value = "${data.aws_elastic_beanstalk_application.example.arn}" | ||
} | ||
|
||
output "description" { | ||
value = "${data.aws_elastic_beanstalk_application.example.description}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) The name of the application | ||
|
||
## Attributes Reference | ||
|
||
* `id` - The name of the application | ||
* `arn` - The Amazon Resource Name (ARN) of the application. | ||
* `description` - Short description of the application | ||
|
||
Application version lifecycle (`appversion_lifecycle`) supports the nested attribute containing. | ||
|
||
* `service_role` - The ARN of an IAM service role under which the application version is deleted. Elastic Beanstalk must have permission to assume this role. | ||
* `max_count` - The maximum number of application versions to retain. | ||
* `max_age_in_days` - The number of days to retain an application version. | ||
* `delete_source_from_s3` - Specifies whether delete a version's source bundle from S3 when the application version is deleted. |
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.
Nit:
ForceNew: true
is extraneous for data sources