Skip to content

Commit a86fe80

Browse files
committed
data.aws_route53_resolver_rule: Add target_ips attribute
Adds the `target_ips` attribute to the `aws_route53_resolver_rule` data source to expose the list of target IP addresses configured for FORWARD rules. This includes IPv4 (`ip`), IPv6 (`ipv6`), port, and protocol information for each target.
1 parent 5265262 commit a86fe80

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

.changelog/45492.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
data-source/aws_route53_resolver_rule: Add `target_ips` attribute
3+
```

internal/service/route53resolver/rule_data_source.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ func dataSourceRule() *schema.Resource {
7070
Type: schema.TypeString,
7171
Computed: true,
7272
},
73+
"target_ips": {
74+
Type: schema.TypeSet,
75+
Computed: true,
76+
Elem: &schema.Resource{
77+
Schema: map[string]*schema.Schema{
78+
"ip": {
79+
Type: schema.TypeString,
80+
Computed: true,
81+
},
82+
"ipv6": {
83+
Type: schema.TypeString,
84+
Computed: true,
85+
},
86+
names.AttrPort: {
87+
Type: schema.TypeInt,
88+
Computed: true,
89+
},
90+
names.AttrProtocol: {
91+
Type: schema.TypeString,
92+
Computed: true,
93+
},
94+
},
95+
},
96+
},
7397
names.AttrTags: tftags.TagsSchemaComputed(),
7498
},
7599
}
@@ -134,6 +158,9 @@ func dataSourceRuleRead(ctx context.Context, d *schema.ResourceData, meta any) d
134158
d.Set("rule_type", rule.RuleType)
135159
shareStatus := rule.ShareStatus
136160
d.Set("share_status", shareStatus)
161+
if err := d.Set("target_ips", flattenRuleTargetIPs(rule.TargetIps)); err != nil {
162+
return sdkdiag.AppendErrorf(diags, "setting target_ips: %s", err)
163+
}
137164
// https://github.com/hashicorp/terraform-provider-aws/issues/10211
138165
if shareStatus != awstypes.ShareStatusSharedWithMe {
139166
tags, err := listTags(ctx, conn, arn)

internal/service/route53resolver/rule_data_source_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,39 @@ func TestAccRoute53ResolverRuleDataSource_resolverEndpointIdWithTags(t *testing.
106106
})
107107
}
108108

109+
func TestAccRoute53ResolverRuleDataSource_targetIPs(t *testing.T) {
110+
ctx := acctest.Context(t)
111+
domainName := acctest.RandomDomainName()
112+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
113+
resourceName := "aws_route53_resolver_rule.test"
114+
dsResourceName := "data.aws_route53_resolver_rule.test"
115+
116+
resource.ParallelTest(t, resource.TestCase{
117+
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
118+
ErrorCheck: acctest.ErrorCheck(t, names.Route53ResolverServiceID),
119+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
120+
Steps: []resource.TestStep{
121+
{
122+
Config: testAccRuleDataSourceConfig_targetIPs(rName, domainName),
123+
Check: resource.ComposeAggregateTestCheckFunc(
124+
resource.TestCheckResourceAttrPair(dsResourceName, names.AttrID, resourceName, names.AttrID),
125+
resource.TestCheckResourceAttr(dsResourceName, "target_ips.#", "2"),
126+
resource.TestCheckTypeSetElemNestedAttrs(dsResourceName, "target_ips.*", map[string]string{
127+
"ip": "192.0.2.7",
128+
names.AttrPort: "53",
129+
names.AttrProtocol: "Do53",
130+
}),
131+
resource.TestCheckTypeSetElemNestedAttrs(dsResourceName, "target_ips.*", map[string]string{
132+
"ip": "192.0.2.8",
133+
names.AttrPort: "53",
134+
names.AttrProtocol: "Do53",
135+
}),
136+
),
137+
},
138+
},
139+
})
140+
}
141+
109142
func TestAccRoute53ResolverRuleDataSource_sharedByMe(t *testing.T) {
110143
ctx := acctest.Context(t)
111144
domainName := acctest.RandomDomainName()
@@ -318,6 +351,30 @@ data "aws_route53_resolver_rule" "by_resolver_endpoint_id" {
318351
`, rName, domainName))
319352
}
320353

354+
func testAccRuleDataSourceConfig_targetIPs(rName, domainName string) string {
355+
return acctest.ConfigCompose(testAccRuleConfig_resolverEndpointBase(rName), fmt.Sprintf(`
356+
resource "aws_route53_resolver_rule" "test" {
357+
domain_name = %[2]q
358+
rule_type = "FORWARD"
359+
name = %[1]q
360+
361+
resolver_endpoint_id = aws_route53_resolver_endpoint.test[1].id
362+
363+
target_ip {
364+
ip = "192.0.2.7"
365+
}
366+
367+
target_ip {
368+
ip = "192.0.2.8"
369+
}
370+
}
371+
372+
data "aws_route53_resolver_rule" "test" {
373+
resolver_rule_id = aws_route53_resolver_rule.test.id
374+
}
375+
`, rName, domainName))
376+
}
377+
321378
// testAccErrorCheckSkipRoute53 skips Route53 tests that have error messages indicating unsupported features
322379
func testAccErrorCheckSkipRoute53(t *testing.T) resource.ErrorCheckFunc {
323380
return acctest.ErrorCheckSkipMessagesContaining(t,

website/docs/d/route53_resolver_rule.html.markdown

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ This data source exports the following attributes in addition to the arguments a
4242
* `share_status` - Whether the rules is shared and, if so, whether the current account is sharing the rule with another account, or another account is sharing the rule with the current account.
4343
Values are `NOT_SHARED`, `SHARED_BY_ME` or `SHARED_WITH_ME`
4444
* `tags` - Map of tags assigned to the resolver rule.
45+
* `target_ips` - List of configurations for target IP addresses. Only applicable for `FORWARD` rules. See [`target_ips`](#target_ips) below for details.
46+
47+
### target_ips
48+
49+
* `ip` - IPv4 address that you want to forward DNS queries to.
50+
* `ipv6` - IPv6 address that you want to forward DNS queries to.
51+
* `port` - Port at the IP address that you want to forward DNS queries to.
52+
* `protocol` - Protocol for the target IP address. Valid values are `Do53` (DNS over port 53), `DoH` (DNS over HTTPS), and `DoH-FIPS` (DNS over HTTPS with FIPS).

0 commit comments

Comments
 (0)