forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
423 changed files
with
22,292 additions
and
13,802 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.