provider/aws: Adding outputs for elastic_beanstalk_environment resource.

refs #5798
This commit is contained in:
David Harris 2016-03-28 13:11:25 -06:00
parent 14942640dd
commit c3a6cf0620
5 changed files with 170 additions and 18 deletions

View File

@ -126,16 +126,10 @@ resource "aws_elastic_beanstalk_application" "tftest" {
description = "tf-test-desc" description = "tf-test-desc"
} }
#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"
#}
resource "aws_elastic_beanstalk_configuration_template" "tf_template" { resource "aws_elastic_beanstalk_configuration_template" "tf_template" {
name = "tf-test-template-config" name = "tf-test-template-config"
application = "${aws_elastic_beanstalk_application.tftest.name}" application = "${aws_elastic_beanstalk_application.tftest.name}"
solution_stack_name = "64bit Amazon Linux 2015.09 v2.0.8 running Go 1.4" solution_stack_name = "64bit Amazon Linux running Python"
} }
` `
@ -167,7 +161,7 @@ resource "aws_elastic_beanstalk_configuration_template" "tf_template" {
name = "tf-test-%s" name = "tf-test-%s"
application = "${aws_elastic_beanstalk_application.tftest.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 running Python"
setting { setting {
namespace = "aws:ec2:vpc" namespace = "aws:ec2:vpc"

View File

@ -124,6 +124,36 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource {
return return
}, },
}, },
"autoscaling_groups": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"instances": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"launch_configurations": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"load_balancers": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"queues": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"triggers": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"tags": tagsSchema(), "tags": tagsSchema(),
}, },
@ -342,6 +372,14 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int
return nil return nil
} }
resources, err := conn.DescribeEnvironmentResources(&elasticbeanstalk.DescribeEnvironmentResourcesInput{
EnvironmentId: aws.String(envId),
})
if err != nil {
return err
}
if err := d.Set("description", env.Description); err != nil { if err := d.Set("description", env.Description); err != nil {
return err return err
} }
@ -366,6 +404,26 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int
} }
} }
if err := d.Set("autoscaling_groups", flattenBeanstalkAsg(resources.EnvironmentResources.AutoScalingGroups)); err != nil {
return err
}
if err := d.Set("instances", flattenBeanstalkInstances(resources.EnvironmentResources.Instances)); err != nil {
return err
}
if err := d.Set("launch_configurations", flattenBeanstalkLc(resources.EnvironmentResources.LaunchConfigurations)); err != nil {
return err
}
if err := d.Set("load_balancers", flattenBeanstalkElb(resources.EnvironmentResources.LoadBalancers)); err != nil {
return err
}
if err := d.Set("queues", flattenBeanstalkSqs(resources.EnvironmentResources.Queues)); err != nil {
return err
}
if err := d.Set("triggers", flattenBeanstalkTrigger(resources.EnvironmentResources.Triggers)); err != nil {
return err
}
return resourceAwsElasticBeanstalkEnvironmentSettingsRead(d, meta) return resourceAwsElasticBeanstalkEnvironmentSettingsRead(d, meta)
} }

View File

@ -34,6 +34,7 @@ func TestAccAWSBeanstalkEnv_basic(t *testing.T) {
func TestAccAWSBeanstalkEnv_tier(t *testing.T) { func TestAccAWSBeanstalkEnv_tier(t *testing.T) {
var app elasticbeanstalk.EnvironmentDescription var app elasticbeanstalk.EnvironmentDescription
beanstalkQueuesNameRegexp := regexp.MustCompile("https://sqs.+?awseb[^,]+")
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -44,6 +45,38 @@ func TestAccAWSBeanstalkEnv_tier(t *testing.T) {
Config: testAccBeanstalkWorkerEnvConfig, Config: testAccBeanstalkWorkerEnvConfig,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvTier("aws_elastic_beanstalk_environment.tfenvtest", &app), testAccCheckBeanstalkEnvTier("aws_elastic_beanstalk_environment.tfenvtest", &app),
resource.TestMatchResourceAttr(
"aws_elastic_beanstalk_environment.tfenvtest", "queues.0", beanstalkQueuesNameRegexp),
),
},
},
})
}
func TestAccAWSBeanstalkEnv_outputs(t *testing.T) {
var app elasticbeanstalk.EnvironmentDescription
beanstalkAsgNameRegexp := regexp.MustCompile("awseb.+?AutoScalingGroup[^,]+")
beanstalkElbNameRegexp := regexp.MustCompile("awseb.+?EBLoa[^,]+")
beanstalkInstancesNameRegexp := regexp.MustCompile("i-([0-9a-fA-F]{8}|[0-9a-fA-F]{17})")
beanstalkLcNameRegexp := regexp.MustCompile("awseb.+?AutoScalingLaunch[^,]+")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBeanstalkEnvDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccBeanstalkEnvConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckBeanstalkEnvExists("aws_elastic_beanstalk_environment.tfenvtest", &app),
resource.TestMatchResourceAttr(
"aws_elastic_beanstalk_environment.tfenvtest", "autoscaling_groups.0", beanstalkAsgNameRegexp),
resource.TestMatchResourceAttr(
"aws_elastic_beanstalk_environment.tfenvtest", "load_balancers.0", beanstalkElbNameRegexp),
resource.TestMatchResourceAttr(
"aws_elastic_beanstalk_environment.tfenvtest", "instances.0", beanstalkInstancesNameRegexp),
resource.TestMatchResourceAttr(
"aws_elastic_beanstalk_environment.tfenvtest", "launch_configurations.0", beanstalkLcNameRegexp),
), ),
}, },
}, },
@ -189,8 +222,7 @@ resource "aws_elastic_beanstalk_application" "tftest" {
resource "aws_elastic_beanstalk_environment" "tfenvtest" { resource "aws_elastic_beanstalk_environment" "tfenvtest" {
name = "tf-test-name" name = "tf-test-name"
application = "${aws_elastic_beanstalk_application.tftest.name}" application = "${aws_elastic_beanstalk_application.tftest.name}"
solution_stack_name = "64bit Amazon Linux 2015.09 v2.0.8 running Go 1.4" solution_stack_name = "64bit Amazon Linux running Python"
#solution_stack_name =
} }
` `
@ -204,7 +236,7 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" {
name = "tf-test-name" name = "tf-test-name"
application = "${aws_elastic_beanstalk_application.tftest.name}" application = "${aws_elastic_beanstalk_application.tftest.name}"
tier = "Worker" tier = "Worker"
solution_stack_name = "64bit Amazon Linux 2015.09 v2.0.4 running Go 1.4" solution_stack_name = "64bit Amazon Linux running Python"
} }
` `
@ -219,7 +251,7 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" {
name = "tf-test-name" name = "tf-test-name"
application = "${aws_elastic_beanstalk_application.tftest.name}" application = "${aws_elastic_beanstalk_application.tftest.name}"
cname_prefix = "%s" cname_prefix = "%s"
solution_stack_name = "64bit Amazon Linux 2015.09 v2.0.4 running Go 1.4" solution_stack_name = "64bit Amazon Linux running Python"
} }
`, randString) `, randString)
} }

View File

@ -17,6 +17,7 @@ import (
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ecs" "github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/service/elasticache" "github.com/aws/aws-sdk-go/service/elasticache"
"github.com/aws/aws-sdk-go/service/elasticbeanstalk"
elasticsearch "github.com/aws/aws-sdk-go/service/elasticsearchservice" elasticsearch "github.com/aws/aws-sdk-go/service/elasticsearchservice"
"github.com/aws/aws-sdk-go/service/elb" "github.com/aws/aws-sdk-go/service/elb"
"github.com/aws/aws-sdk-go/service/lambda" "github.com/aws/aws-sdk-go/service/lambda"
@ -1016,3 +1017,63 @@ func flattenCloudWachLogMetricTransformations(ts []*cloudwatchlogs.MetricTransfo
return m return m
} }
func flattenBeanstalkAsg(list []*elasticbeanstalk.AutoScalingGroup) []string {
strs := make([]string, 0, len(list))
for _, r := range list {
if r.Name != nil {
strs = append(strs, *r.Name)
}
}
return strs
}
func flattenBeanstalkInstances(list []*elasticbeanstalk.Instance) []string {
strs := make([]string, 0, len(list))
for _, r := range list {
if r.Id != nil {
strs = append(strs, *r.Id)
}
}
return strs
}
func flattenBeanstalkLc(list []*elasticbeanstalk.LaunchConfiguration) []string {
strs := make([]string, 0, len(list))
for _, r := range list {
if r.Name != nil {
strs = append(strs, *r.Name)
}
}
return strs
}
func flattenBeanstalkElb(list []*elasticbeanstalk.LoadBalancer) []string {
strs := make([]string, 0, len(list))
for _, r := range list {
if r.Name != nil {
strs = append(strs, *r.Name)
}
}
return strs
}
func flattenBeanstalkSqs(list []*elasticbeanstalk.Queue) []string {
strs := make([]string, 0, len(list))
for _, r := range list {
if r.URL != nil {
strs = append(strs, *r.URL)
}
}
return strs
}
func flattenBeanstalkTrigger(list []*elasticbeanstalk.Trigger) []string {
strs := make([]string, 0, len(list))
for _, r := range list {
if r.Name != nil {
strs = append(strs, *r.Name)
}
}
return strs
}

View File

@ -74,15 +74,22 @@ The `setting` and `all_settings` mappings support the following format:
The following attributes are exported: The following attributes are exported:
* `name` * `name` - Name of the Elastic Beanstalk Environment.
* `description` * `description` - Description of the Elastic Beanstalk Environment.
* `tier` - the environment tier specified. * `tier` - The environment tier specified.
* `application` the application specified * `application` The Elastic Beanstalk Application specified for this environment.
* `setting`  Settings specifically set for this Environment * `setting`  Settings specifically set for this Environment.
* `all_settings`  List of all option settings configured in the Environment. These * `all_settings`  List of all option settings configured in the Environment. These
are a combination of default settings and their overrides from `settings` in are a combination of default settings and their overrides from `settings` in
the configuration the configuration.
* `cname` - Fully qualified DNS name for the Environment. * `cname` - Fully qualified DNS name for the Environment.
* `autoscaling_groups` - The autoscaling groups used by this environment.
* `instances` - Instances used by this environment.
* `launch_configurations` - Launch configurations in use by this environment.
* `load_balancers` - Elastic load balancers in use by this environment.
* `queues` - SQS queues in use by this environment.
* `triggers` - Autoscaling triggers in use by this environment.
[1]: http://docs.aws.amazon.com/fr_fr/elasticbeanstalk/latest/dg/concepts.platforms.html [1]: http://docs.aws.amazon.com/fr_fr/elasticbeanstalk/latest/dg/concepts.platforms.html