Skip to content

Commit

Permalink
Adding outputs for elastic_beanstalk_environment resource.
Browse files Browse the repository at this point in the history
  • Loading branch information
dharrisio committed Mar 29, 2016
1 parent 7d1cfde commit 4075404
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -14,6 +15,10 @@ import (

func TestAccAWSBeanstalkEnv_basic(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) },
Expand All @@ -24,6 +29,14 @@ func TestAccAWSBeanstalkEnv_basic(t *testing.T) {
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),
),
},
},
Expand All @@ -32,6 +45,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) },
Expand All @@ -42,6 +56,8 @@ 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),
),
},
},
Expand Down
61 changes: 61 additions & 0 deletions builtin/providers/aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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"
Expand Down Expand Up @@ -945,3 +946,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
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ description: |-

# aws\_elastic\_beanstalk\_<wbr>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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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


0 comments on commit 4075404

Please sign in to comment.