-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7144 from kterada0509/feature/add-elastic_beansta…
…lk_application-data-source Add aws_elastic_beanstalk_application Data Source
- Loading branch information
Showing
4 changed files
with
177 additions
and
0 deletions.
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. |