Skip to content

Commit

Permalink
Merge branch 'master' into f-r-2217
Browse files Browse the repository at this point in the history
  • Loading branch information
trung committed Dec 12, 2017
2 parents f03a0a1 + f4800f6 commit 3a3c6da
Show file tree
Hide file tree
Showing 423 changed files with 22,292 additions and 13,802 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

FEATURES:

* **New Datasource:** `aws_network_interface` [GH-2316]
* **New Data Source:** `aws_network_interface` [GH-2316]
* **New Data Source:** `aws_elb` [GH-2004]
* **New Resource:** `aws_dx_connection_association` [GH-2360]
* **New Resource:** `aws_appautoscaling_scheduled_action` [GH-2231]
* **New Resource:** `aws_cloudwatch_log_resource_policy` [GH-2243]
* **New Resource:** `aws_media_store_container` [GH-2448]

IMPROVEMENTS:

Expand All @@ -13,11 +16,18 @@ IMPROVEMENTS:
* resource/aws_lambda_function: Add `reserved_concurrent_executions` [GH-2504]
* resource/aws_ecs_service: Add `launch_type` (Fargate support) [GH-2483]
* resource/aws_ecs_task_definition: Add `cpu`, `memory`, `execution_role_arn` & `requires_compatibilities` (Fargate support) [GH-2483]
* resource/aws_ecs_cluster: Add arn attribute [GH-2552]
* resource/aws_elasticache_security_group: Add import support [GH-2277]
* resource/aws_sqs_queue_policy: Support import by queue URL [GH-2544]
* resource/aws_elasticsearch_domain: Add `log_publishing_options` [GH-2285]
* resource/aws_athena_database: Add `force_destroy` field [GH-2363]

BUG FIXES:

* data-source/aws_instance: Set `placement_group` if available [GH-2400]
* resource/aws_elasticache_parameter_group: Add StateFunc to make name lowercase [GH-2426]
* resource/aws_elasticache_replication_group: Modify validation, make replication_group_id lowercase [GH-2432]
* resource/aws_db_instance: Treat `storage-optimization` as valid state [GH-2409]

## 1.5.0 (November 29, 2017)

Expand Down
3 changes: 3 additions & 0 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
"github.com/aws/aws-sdk-go/service/kms"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/aws/aws-sdk-go/service/lightsail"
"github.com/aws/aws-sdk-go/service/mediastore"
"github.com/aws/aws-sdk-go/service/mq"
"github.com/aws/aws-sdk-go/service/opsworks"
"github.com/aws/aws-sdk-go/service/rds"
Expand Down Expand Up @@ -188,6 +189,7 @@ type AWSClient struct {
batchconn *batch.Batch
athenaconn *athena.Athena
dxconn *directconnect.DirectConnect
mediastoreconn *mediastore.MediaStore
}

func (c *AWSClient) S3() *s3.S3 {
Expand Down Expand Up @@ -426,6 +428,7 @@ func (c *Config) Client() (interface{}, error) {
client.batchconn = batch.New(sess)
client.athenaconn = athena.New(sess)
client.dxconn = directconnect.New(sess)
client.mediastoreconn = mediastore.New(sess)

// Workaround for https://github.com/aws/aws-sdk-go/issues/1376
client.kinesisconn.Handlers.Retry.PushBack(func(r *request.Request) {
Expand Down
212 changes: 212 additions & 0 deletions aws/data_source_aws_elb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
package aws

import (
"fmt"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceAwsElb() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsElbRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},

"access_logs": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"interval": {
Type: schema.TypeInt,
Computed: true,
},
"bucket": {
Type: schema.TypeString,
Computed: true,
},
"bucket_prefix": {
Type: schema.TypeString,
Computed: true,
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},

"availability_zones": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Set: schema.HashString,
},

"connection_draining": {
Type: schema.TypeBool,
Computed: true,
},

"connection_draining_timeout": {
Type: schema.TypeInt,
Computed: true,
},

"cross_zone_load_balancing": {
Type: schema.TypeBool,
Computed: true,
},

"dns_name": {
Type: schema.TypeString,
Computed: true,
},

"health_check": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"healthy_threshold": {
Type: schema.TypeInt,
Computed: true,
},

"unhealthy_threshold": {
Type: schema.TypeInt,
Computed: true,
},

"target": {
Type: schema.TypeString,
Computed: true,
},

"interval": {
Type: schema.TypeInt,
Computed: true,
},

"timeout": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},

"idle_timeout": {
Type: schema.TypeInt,
Computed: true,
},

"instances": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Set: schema.HashString,
},

"internal": {
Type: schema.TypeBool,
Computed: true,
},

"listener": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"instance_port": {
Type: schema.TypeInt,
Computed: true,
},

"instance_protocol": {
Type: schema.TypeString,
Computed: true,
},

"lb_port": {
Type: schema.TypeInt,
Computed: true,
},

"lb_protocol": {
Type: schema.TypeString,
Computed: true,
},

"ssl_certificate_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
Set: resourceAwsElbListenerHash,
},

"security_groups": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Set: schema.HashString,
},

"source_security_group": {
Type: schema.TypeString,
Computed: true,
},

"source_security_group_id": {
Type: schema.TypeString,
Computed: true,
},

"subnets": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Set: schema.HashString,
},

"tags": tagsSchemaComputed(),

"zone_id": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceAwsElbRead(d *schema.ResourceData, meta interface{}) error {
elbconn := meta.(*AWSClient).elbconn
lbName := d.Get("name").(string)

input := &elb.DescribeLoadBalancersInput{
LoadBalancerNames: []*string{aws.String(lbName)},
}

log.Printf("[DEBUG] Reading ELBs: %#v", input)
resp, err := elbconn.DescribeLoadBalancers(input)
if err != nil {
return fmt.Errorf("Error retrieving LB: %s", err)
}
if len(resp.LoadBalancerDescriptions) != 1 {
return fmt.Errorf("Search returned %d results, please revise so only one is returned", len(resp.LoadBalancerDescriptions))
}
d.SetId(*resp.LoadBalancerDescriptions[0].LoadBalancerName)

return flattenAwsELbResource(d, meta.(*AWSClient).ec2conn, elbconn, resp.LoadBalancerDescriptions[0])
}
114 changes: 114 additions & 0 deletions aws/data_source_aws_elb_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package aws

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceAWSELB_basic(t *testing.T) {
// Must be less than 32 characters for ELB name
rName := fmt.Sprintf("TestAccDataSourceAWSELB-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAWSELBConfigBasic(rName, t.Name()),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.aws_elb.elb_test", "name", rName),
resource.TestCheckResourceAttr("data.aws_elb.elb_test", "cross_zone_load_balancing", "true"),
resource.TestCheckResourceAttr("data.aws_elb.elb_test", "idle_timeout", "30"),
resource.TestCheckResourceAttr("data.aws_elb.elb_test", "internal", "true"),
resource.TestCheckResourceAttr("data.aws_elb.elb_test", "subnets.#", "2"),
resource.TestCheckResourceAttr("data.aws_elb.elb_test", "security_groups.#", "1"),
resource.TestCheckResourceAttr("data.aws_elb.elb_test", "tags.%", "1"),
resource.TestCheckResourceAttr("data.aws_elb.elb_test", "tags.TestName", t.Name()),
resource.TestCheckResourceAttrSet("data.aws_elb.elb_test", "dns_name"),
resource.TestCheckResourceAttrSet("data.aws_elb.elb_test", "zone_id"),
),
},
},
})
}

func testAccDataSourceAWSELBConfigBasic(rName, testName string) string {
return fmt.Sprintf(`
resource "aws_elb" "elb_test" {
name = "%[1]s"
internal = true
security_groups = ["${aws_security_group.elb_test.id}"]
subnets = ["${aws_subnet.elb_test.*.id}"]
idle_timeout = 30
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
tags {
TestName = "%[2]s"
}
}
variable "subnets" {
default = ["10.0.1.0/24", "10.0.2.0/24"]
type = "list"
}
data "aws_availability_zones" "available" {}
resource "aws_vpc" "elb_test" {
cidr_block = "10.0.0.0/16"
tags {
TestName = "%[2]s"
}
}
resource "aws_subnet" "elb_test" {
count = 2
vpc_id = "${aws_vpc.elb_test.id}"
cidr_block = "${element(var.subnets, count.index)}"
map_public_ip_on_launch = true
availability_zone = "${element(data.aws_availability_zones.available.names, count.index)}"
tags {
TestName = "%[2]s"
}
}
resource "aws_security_group" "elb_test" {
name = "%[1]s"
description = "%[2]s"
vpc_id = "${aws_vpc.elb_test.id}"
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags {
TestName = "%[2]s"
}
}
data "aws_elb" "elb_test" {
name = "${aws_elb.elb_test.name}"
}`, rName, testName)
}
Loading

0 comments on commit 3a3c6da

Please sign in to comment.