From c3a6cf06208d7dceb855980ae13d7daabc1d5fae Mon Sep 17 00:00:00 2001 From: David Harris Date: Mon, 28 Mar 2016 13:11:25 -0600 Subject: [PATCH] provider/aws: Adding outputs for elastic_beanstalk_environment resource. refs #5798 --- ...c_beanstalk_configuration_template_test.go | 10 +-- ...ource_aws_elastic_beanstalk_environment.go | 58 ++++++++++++++++++ ..._aws_elastic_beanstalk_environment_test.go | 40 ++++++++++-- builtin/providers/aws/structure.go | 61 +++++++++++++++++++ ...lastic_beanstalk_environment.html.markdown | 19 ++++-- 5 files changed, 170 insertions(+), 18 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template_test.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template_test.go index 4aedf82b1..17f1a6ca7 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template_test.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template_test.go @@ -126,16 +126,10 @@ resource "aws_elastic_beanstalk_application" "tftest" { 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" { name = "tf-test-template-config" 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" 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 { namespace = "aws:ec2:vpc" diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go index fd5426ce7..204790eef 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -124,6 +124,36 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource { 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(), }, @@ -342,6 +372,14 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int 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 { 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) } 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 15e496a1e..5a9d14379 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go @@ -34,6 +34,7 @@ func TestAccAWSBeanstalkEnv_basic(t *testing.T) { func TestAccAWSBeanstalkEnv_tier(t *testing.T) { var app elasticbeanstalk.EnvironmentDescription + beanstalkQueuesNameRegexp := regexp.MustCompile("https://sqs.+?awseb[^,]+") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -44,6 +45,38 @@ func TestAccAWSBeanstalkEnv_tier(t *testing.T) { Config: testAccBeanstalkWorkerEnvConfig, Check: resource.ComposeTestCheckFunc( 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" { name = "tf-test-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 = + solution_stack_name = "64bit Amazon Linux running Python" } ` @@ -204,7 +236,7 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" { name = "tf-test-name" application = "${aws_elastic_beanstalk_application.tftest.name}" 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" application = "${aws_elastic_beanstalk_application.tftest.name}" 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) } diff --git a/builtin/providers/aws/structure.go b/builtin/providers/aws/structure.go index 72766c026..a23b1ef6c 100644 --- a/builtin/providers/aws/structure.go +++ b/builtin/providers/aws/structure.go @@ -17,6 +17,7 @@ import ( "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ecs" "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" "github.com/aws/aws-sdk-go/service/elb" "github.com/aws/aws-sdk-go/service/lambda" @@ -1016,3 +1017,63 @@ func flattenCloudWachLogMetricTransformations(ts []*cloudwatchlogs.MetricTransfo 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 +} 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 83ac79aeb..afe8f510c 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 @@ -74,15 +74,22 @@ The `setting` and `all_settings` mappings support the following format: The following attributes are exported: -* `name` -* `description` -* `tier` - the environment tier specified. -* `application` – the application specified -* `setting` – Settings specifically set for this Environment +* `name` - Name of the Elastic Beanstalk Environment. +* `description` - Description of the Elastic Beanstalk Environment. +* `tier` - The environment tier specified. +* `application` – The Elastic Beanstalk Application specified for 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. * `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