Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d/lb - add private_ipv4_address attribute to subnet mapping #14545

Merged
merged 8 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions aws/data_source_aws_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ func dataSourceAwsLb() *schema.Resource {
Read: dataSourceAwsLbRead,
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateArn,
},

"arn_suffix": {
Expand Down Expand Up @@ -44,14 +45,12 @@ func dataSourceAwsLb() *schema.Resource {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Set: schema.HashString,
},

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

"subnet_mapping": {
Expand All @@ -61,11 +60,15 @@ func dataSourceAwsLb() *schema.Resource {
Schema: map[string]*schema.Schema{
"subnet_id": {
Type: schema.TypeString,
Required: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing these. 😄

Computed: true,
},
"allocation_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"private_ipv4_address": {
Type: schema.TypeString,
Computed: true,
},
},
},
Expand Down Expand Up @@ -138,7 +141,7 @@ func dataSourceAwsLb() *schema.Resource {
}

func dataSourceAwsLbRead(d *schema.ResourceData, meta interface{}) error {
elbconn := meta.(*AWSClient).elbv2conn
conn := meta.(*AWSClient).elbv2conn
lbArn := d.Get("arn").(string)
lbName := d.Get("name").(string)

Expand All @@ -151,7 +154,7 @@ func dataSourceAwsLbRead(d *schema.ResourceData, meta interface{}) error {
}

log.Printf("[DEBUG] Reading Load Balancer: %s", describeLbOpts)
describeResp, err := elbconn.DescribeLoadBalancers(describeLbOpts)
describeResp, err := conn.DescribeLoadBalancers(describeLbOpts)
if err != nil {
return fmt.Errorf("Error retrieving LB: %s", err)
}
Expand Down
115 changes: 65 additions & 50 deletions aws/data_source_aws_lb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestAccDataSourceAWSLB_basic(t *testing.T) {
lbName := fmt.Sprintf("testaccawslb-basic-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
dataSourceName := "data.aws_lb.alb_test_with_arn"
dataSourceName2 := "data.aws_lb.alb_test_with_name"
resourceName := "aws_lb.alb_test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -20,32 +21,34 @@ func TestAccDataSourceAWSLB_basic(t *testing.T) {
{
Config: testAccDataSourceAWSLBConfigBasic(lbName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "name", lbName),
resource.TestCheckResourceAttr(dataSourceName, "internal", "true"),
resource.TestCheckResourceAttr(dataSourceName, "subnets.#", "2"),
resource.TestCheckResourceAttr(dataSourceName, "security_groups.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(dataSourceName, "tags.TestName", "TestAccAWSALB_basic"),
resource.TestCheckResourceAttr(dataSourceName, "enable_deletion_protection", "false"),
resource.TestCheckResourceAttr(dataSourceName, "idle_timeout", "30"),
resource.TestCheckResourceAttrSet(dataSourceName, "vpc_id"),
resource.TestCheckResourceAttrSet(dataSourceName, "zone_id"),
resource.TestCheckResourceAttrSet(dataSourceName, "dns_name"),
resource.TestCheckResourceAttrSet(dataSourceName, "arn"),
resource.TestCheckResourceAttrSet(dataSourceName, "ip_address_type"),
resource.TestCheckResourceAttr(dataSourceName2, "name", lbName),
resource.TestCheckResourceAttr(dataSourceName2, "internal", "true"),
resource.TestCheckResourceAttr(dataSourceName2, "subnets.#", "2"),
resource.TestCheckResourceAttr(dataSourceName2, "security_groups.#", "1"),
resource.TestCheckResourceAttr(dataSourceName2, "tags.%", "1"),
resource.TestCheckResourceAttr(dataSourceName2, "tags.TestName", "TestAccAWSALB_basic"),
resource.TestCheckResourceAttr(dataSourceName2, "enable_deletion_protection", "false"),
resource.TestCheckResourceAttr(dataSourceName2, "idle_timeout", "30"),
resource.TestCheckResourceAttrSet(dataSourceName2, "vpc_id"),
resource.TestCheckResourceAttrSet(dataSourceName2, "zone_id"),
resource.TestCheckResourceAttrSet(dataSourceName2, "dns_name"),
resource.TestCheckResourceAttrSet(dataSourceName2, "arn"),
resource.TestCheckResourceAttrSet(dataSourceName2, "ip_address_type"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "internal", resourceName, "internal"),
resource.TestCheckResourceAttrPair(dataSourceName, "subnets.#", resourceName, "subnets.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "security_groups.#", resourceName, "security_groups.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.TestName", resourceName, "tags.TestName"),
resource.TestCheckResourceAttrPair(dataSourceName, "enable_deletion_protection", resourceName, "enable_deletion_protection"),
resource.TestCheckResourceAttrPair(dataSourceName, "idle_timeout", resourceName, "idle_timeout"),
resource.TestCheckResourceAttrPair(dataSourceName, "vpc_id", resourceName, "vpc_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "zone_id", resourceName, "zone_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "dns_name", resourceName, "dns_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "ip_address_type", resourceName, "ip_address_type"),
resource.TestCheckResourceAttrPair(dataSourceName, "subnet_mapping.#", resourceName, "subnet_mapping.#"),
resource.TestCheckResourceAttrPair(dataSourceName2, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName2, "internal", resourceName, "internal"),
resource.TestCheckResourceAttrPair(dataSourceName2, "subnets.#", resourceName, "subnets.#"),
resource.TestCheckResourceAttrPair(dataSourceName2, "security_groups.#", resourceName, "security_groups.#"),
resource.TestCheckResourceAttrPair(dataSourceName2, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(dataSourceName2, "tags.TestName", resourceName, "tags.TestName"),
resource.TestCheckResourceAttrPair(dataSourceName2, "enable_deletion_protection", resourceName, "enable_deletion_protection"),
resource.TestCheckResourceAttrPair(dataSourceName2, "idle_timeout", resourceName, "idle_timeout"),
resource.TestCheckResourceAttrPair(dataSourceName2, "vpc_id", resourceName, "vpc_id"),
resource.TestCheckResourceAttrPair(dataSourceName2, "zone_id", resourceName, "zone_id"),
resource.TestCheckResourceAttrPair(dataSourceName2, "dns_name", resourceName, "dns_name"),
resource.TestCheckResourceAttrPair(dataSourceName2, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName2, "ip_address_type", resourceName, "ip_address_type"),
resource.TestCheckResourceAttrPair(dataSourceName2, "subnet_mapping.#", resourceName, "subnet_mapping.#"),
),
},
},
Expand All @@ -56,37 +59,49 @@ func TestAccDataSourceAWSLB_BackwardsCompatibility(t *testing.T) {
lbName := fmt.Sprintf("testaccawsalb-basic-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
dataSourceName1 := "data.aws_alb.alb_test_with_arn"
dataSourceName2 := "data.aws_alb.alb_test_with_name"
resourceName := "aws_alb.alb_test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAWSLBConfigBackardsCompatibility(lbName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName1, "name", lbName),
resource.TestCheckResourceAttr(dataSourceName1, "internal", "true"),
resource.TestCheckResourceAttr(dataSourceName1, "subnets.#", "2"),
resource.TestCheckResourceAttr(dataSourceName1, "security_groups.#", "1"),
resource.TestCheckResourceAttr(dataSourceName1, "tags.%", "1"),
resource.TestCheckResourceAttr(dataSourceName1, "tags.TestName", "TestAccAWSALB_basic"),
resource.TestCheckResourceAttr(dataSourceName1, "enable_deletion_protection", "false"),
resource.TestCheckResourceAttr(dataSourceName1, "idle_timeout", "30"),
resource.TestCheckResourceAttrSet(dataSourceName1, "vpc_id"),
resource.TestCheckResourceAttrSet(dataSourceName1, "zone_id"),
resource.TestCheckResourceAttrSet(dataSourceName1, "dns_name"),
resource.TestCheckResourceAttrSet(dataSourceName1, "arn"),
resource.TestCheckResourceAttr(dataSourceName2, "name", lbName),
resource.TestCheckResourceAttr(dataSourceName2, "internal", "true"),
resource.TestCheckResourceAttr(dataSourceName2, "subnets.#", "2"),
resource.TestCheckResourceAttr(dataSourceName2, "security_groups.#", "1"),
resource.TestCheckResourceAttr(dataSourceName2, "tags.%", "1"),
resource.TestCheckResourceAttr(dataSourceName2, "tags.TestName", "TestAccAWSALB_basic"),
resource.TestCheckResourceAttr(dataSourceName2, "enable_deletion_protection", "false"),
resource.TestCheckResourceAttr(dataSourceName2, "idle_timeout", "30"),
resource.TestCheckResourceAttrSet(dataSourceName2, "vpc_id"),
resource.TestCheckResourceAttrSet(dataSourceName2, "zone_id"),
resource.TestCheckResourceAttrSet(dataSourceName2, "dns_name"),
resource.TestCheckResourceAttrSet(dataSourceName2, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName1, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName1, "internal", resourceName, "internal"),
resource.TestCheckResourceAttrPair(dataSourceName1, "subnets.#", resourceName, "subnets.#"),
resource.TestCheckResourceAttrPair(dataSourceName1, "security_groups.#", resourceName, "security_groups.#"),
resource.TestCheckResourceAttrPair(dataSourceName1, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(dataSourceName1, "tags.TestName", resourceName, "tags.TestName"),
resource.TestCheckResourceAttrPair(dataSourceName1, "enable_deletion_protection", resourceName, "enable_deletion_protection"),
resource.TestCheckResourceAttrPair(dataSourceName1, "idle_timeout", resourceName, "idle_timeout"),
resource.TestCheckResourceAttrPair(dataSourceName1, "vpc_id", resourceName, "vpc_id"),
resource.TestCheckResourceAttrPair(dataSourceName1, "zone_id", resourceName, "zone_id"),
resource.TestCheckResourceAttrPair(dataSourceName1, "dns_name", resourceName, "dns_name"),
resource.TestCheckResourceAttrPair(dataSourceName1, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName1, "ip_address_type", resourceName, "ip_address_type"),
resource.TestCheckResourceAttrPair(dataSourceName1, "subnet_mapping.#", resourceName, "subnet_mapping.#"),
resource.TestCheckResourceAttrPair(dataSourceName1, "drop_invalid_header_fields", resourceName, "drop_invalid_header_fields"),
resource.TestCheckResourceAttrPair(dataSourceName1, "enable_http2", resourceName, "enable_http2"),
resource.TestCheckResourceAttrPair(dataSourceName1, "access_logs.#", resourceName, "access_logs.#"),
resource.TestCheckResourceAttrPair(dataSourceName2, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName2, "internal", resourceName, "internal"),
resource.TestCheckResourceAttrPair(dataSourceName2, "subnets.#", resourceName, "subnets.#"),
resource.TestCheckResourceAttrPair(dataSourceName2, "security_groups.#", resourceName, "security_groups.#"),
resource.TestCheckResourceAttrPair(dataSourceName2, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(dataSourceName2, "tags.TestName", resourceName, "tags.TestName"),
resource.TestCheckResourceAttrPair(dataSourceName2, "enable_deletion_protection", resourceName, "enable_deletion_protection"),
resource.TestCheckResourceAttrPair(dataSourceName2, "idle_timeout", resourceName, "idle_timeout"),
resource.TestCheckResourceAttrPair(dataSourceName2, "vpc_id", resourceName, "vpc_id"),
resource.TestCheckResourceAttrPair(dataSourceName2, "zone_id", resourceName, "zone_id"),
resource.TestCheckResourceAttrPair(dataSourceName2, "dns_name", resourceName, "dns_name"),
resource.TestCheckResourceAttrPair(dataSourceName2, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName2, "ip_address_type", resourceName, "ip_address_type"),
resource.TestCheckResourceAttrPair(dataSourceName2, "subnet_mapping.#", resourceName, "subnet_mapping.#"),
resource.TestCheckResourceAttrPair(dataSourceName1, "drop_invalid_header_fields", resourceName, "drop_invalid_header_fields"),
resource.TestCheckResourceAttrPair(dataSourceName1, "enable_http2", resourceName, "enable_http2"),
resource.TestCheckResourceAttrPair(dataSourceName1, "access_logs.#", resourceName, "access_logs.#"),
),
},
},
Expand Down