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 4aedf82b15d4..17f1a6ca7a05 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 d7cfaed303f7..db335afd8105 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment.go @@ -98,6 +98,36 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource { Optional: true, ConflictsWith: []string{"solution_stack_name"}, }, + "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(), }, @@ -308,6 +338,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 } @@ -316,6 +354,26 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int return err } + 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 6c2caa20b8ba..0629408fecb7 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_environment_test.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "regexp" "testing" "github.com/aws/aws-sdk-go/aws" @@ -32,6 +33,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) }, @@ -42,6 +44,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), ), }, }, @@ -165,8 +199,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" } ` @@ -180,6 +213,6 @@ 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" } ` diff --git a/builtin/providers/aws/structure.go b/builtin/providers/aws/structure.go index 72766c0269d6..a23b1ef6ca85 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 8b842f954d89..78f608dd2301 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 @@ -8,11 +8,11 @@ description: |- # aws\_elastic\_beanstalk\_environment -Provides an Elastic Beanstalk Environment Resource. Elastic Beanstalk allows -you to deploy and manage applications in the AWS cloud without worrying about +Provides an Elastic Beanstalk Environment Resource. Elastic Beanstalk allows +you to deploy and manage applications in the AWS cloud without worrying about the infrastructure that runs those applications. -Environments are often things such as `development`, `integration`, or +Environments are often things such as `development`, `integration`, or `production`. ## Example Usage @@ -35,19 +35,19 @@ resource "aws_elastic_beanstalk_environment" "tfenvtest" { The following arguments are supported: -* `name` - (Required) A unique name for this Environment. This name is used +* `name` - (Required) A unique name for this Environment. This name is used in the application URL -* `application` – (Required) Name of the application that contains the version +* `application` – (Required) Name of the application that contains the version to be deployed -* `description` - (Optional) Short description of the Environment -* `tier` - (Optional) Elastic Beanstalk Environment tier. Valid values are `Worker` +* `description` - (Optional) Short description of the Environment +* `tier` - (Optional) Elastic Beanstalk Environment tier. Valid values are `Worker` or `WebServer`. If tier is left blank `WebServer` will be used. * `setting` – (Optional) Option settings to configure the new Environment. These override specific values that are set as defaults. The format is detailed below in [Option Settings](#option-settings) * `solution_stack_name` – (Optional) A solution stack to base your environment off of. Example stacks can be found in the [Amazon API documentation][1] -* `template_name` – (Optional) The name of the Elastic Beanstalk Configuration +* `template_name` – (Optional) The name of the Elastic Beanstalk Configuration template to use in deployment * `tags` – (Optional) A set of tags to apply to the Environment. **Note:** at this time the Elastic Beanstalk API does not provide a programatic way of @@ -59,7 +59,7 @@ changing these tags after initial application The `setting` and `all_settings` mappings support the following format: -* `namespace` - (Optional) unique namespace identifying the option's +* `namespace` - (Optional) unique namespace identifying the option's associated AWS resource * `name` - (Optional) name of the configuration option * `value` - (Optional) value for the configuration option @@ -68,16 +68,20 @@ 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. +* `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 - -