Skip to content

Commit

Permalink
r/vpc_endpoint: fix private_dns_only_for_inbound_resolver_endpoint
Browse files Browse the repository at this point in the history
This field was always set to True or nil, and could not be set to False.
  • Loading branch information
FabianPonce committed Jun 15, 2023
1 parent 9de5f94 commit 2c21001
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/service/ec2/vpc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func expandDNSOptionsSpecification(tfMap map[string]interface{}) *ec2.DnsOptions
apiObject.DnsRecordIpType = aws.String(v)
}

if v, ok := tfMap["private_dns_only_for_inbound_resolver_endpoint"].(bool); ok && v {
if v, ok := tfMap["private_dns_only_for_inbound_resolver_endpoint"].(bool); ok {
apiObject.PrivateDnsOnlyForInboundResolverEndpoint = aws.Bool(v)
}

Expand Down
48 changes: 40 additions & 8 deletions internal/service/ec2/vpc_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ func TestAccVPCEndpoint_interfacePrivateDNS(t *testing.T) {
CheckDestroy: testAccCheckVPCEndpointDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccVPCEndpointConfig_interfacePrivateDNS(rName, true),
Config: testAccVPCEndpointConfig_interfacePrivateDNS(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckVPCEndpointExists(ctx, resourceName, &endpoint),
acctest.CheckResourceAttrGreaterThanValue(resourceName, "cidr_blocks.#", 0),
resource.TestCheckResourceAttr(resourceName, "dns_entry.#", "0"),
resource.TestCheckResourceAttr(resourceName, "dns_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "dns_options.0.dns_record_ip_type", "ipv4"),
resource.TestCheckResourceAttr(resourceName, "dns_options.0.private_dns_only_for_inbound_resolver_endpoint", "true"),
resource.TestCheckResourceAttr(resourceName, "dns_options.0.private_dns_only_for_inbound_resolver_endpoint", "false"),
resource.TestCheckResourceAttr(resourceName, "private_dns_enabled", "true"),
),
},
Expand All @@ -134,14 +134,14 @@ func TestAccVPCEndpoint_interfacePrivateDNS(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccVPCEndpointConfig_interfacePrivateDNS(rName, false),
Config: testAccVPCEndpointConfig_interfacePrivateDNSWithGateway(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckVPCEndpointExists(ctx, resourceName, &endpoint),
acctest.CheckResourceAttrGreaterThanValue(resourceName, "cidr_blocks.#", 0),
resource.TestCheckResourceAttr(resourceName, "dns_entry.#", "0"),
resource.TestCheckResourceAttr(resourceName, "dns_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "dns_options.0.dns_record_ip_type", "ipv4"),
resource.TestCheckResourceAttr(resourceName, "dns_options.0.private_dns_only_for_inbound_resolver_endpoint", "false"),
resource.TestCheckResourceAttr(resourceName, "dns_options.0.private_dns_only_for_inbound_resolver_endpoint", "true"),
resource.TestCheckResourceAttr(resourceName, "private_dns_enabled", "true"),
),
},
Expand Down Expand Up @@ -742,7 +742,40 @@ resource "aws_vpc_endpoint" "test" {
`, rName)
}

func testAccVPCEndpointConfig_interfacePrivateDNS(rName string, privateDNSOnlyForInboundResolverEndpoint bool) string {
func testAccVPCEndpointConfig_interfacePrivateDNS(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = %[1]q
}
}
data "aws_region" "current" {}
resource "aws_vpc_endpoint" "test" {
vpc_id = aws_vpc.test.id
service_name = "com.amazonaws.${data.aws_region.current.name}.s3"
private_dns_enabled = true
vpc_endpoint_type = "Interface"
ip_address_type = "ipv4"
dns_options {
dns_record_ip_type = "ipv4"
private_dns_only_for_inbound_resolver_endpoint = false
}
tags = {
Name = %[1]q
}
}
`, rName)
}

func testAccVPCEndpointConfig_interfacePrivateDNSWithGateway(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
Expand All @@ -759,7 +792,6 @@ data "aws_region" "current" {}
resource "aws_vpc_endpoint" "gateway" {
vpc_id = aws_vpc.test.id
service_name = "com.amazonaws.${data.aws_region.current.name}.s3"
tags = {
Name = %[1]q
}
Expand All @@ -774,7 +806,7 @@ resource "aws_vpc_endpoint" "test" {
dns_options {
dns_record_ip_type = "ipv4"
private_dns_only_for_inbound_resolver_endpoint = %[2]t
private_dns_only_for_inbound_resolver_endpoint = true
}
tags = {
Expand All @@ -784,7 +816,7 @@ resource "aws_vpc_endpoint" "test" {
# To set PrivateDnsOnlyForInboundResolverEndpoint to true, the VPC vpc-abcd1234 must have a Gateway endpoint for the service.
depends_on = [aws_vpc_endpoint.gateway]
}
`, rName, privateDNSOnlyForInboundResolverEndpoint)
`, rName)
}

func testAccVPCEndpointConfig_ipAddressType(rName, addressType string) string {
Expand Down

0 comments on commit 2c21001

Please sign in to comment.