Skip to content

Commit 88ae3e7

Browse files
committed
feat: add delegation_record to route53 resolver rule
1 parent 229b588 commit 88ae3e7

File tree

5 files changed

+87
-7
lines changed

5 files changed

+87
-7
lines changed

internal/service/route53resolver/rule.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ func resourceRule() *schema.Resource {
5151
Type: schema.TypeString,
5252
Computed: true,
5353
},
54+
"delegation_record": {
55+
Type: schema.TypeString,
56+
Optional: true,
57+
ValidateFunc: validation.StringLenBetween(1, 256),
58+
},
5459
names.AttrDomainName: {
5560
Type: schema.TypeString,
56-
Required: true,
61+
Optional: true,
5762
ForceNew: true,
5863
ValidateFunc: validation.StringLenBetween(1, 256),
5964
StateFunc: trimTrailingPeriod,
@@ -125,11 +130,18 @@ func resourceRuleCreate(ctx context.Context, d *schema.ResourceData, meta any) d
125130

126131
input := &route53resolver.CreateResolverRuleInput{
127132
CreatorRequestId: aws.String(id.PrefixedUniqueId("tf-r53-resolver-rule-")),
128-
DomainName: aws.String(d.Get(names.AttrDomainName).(string)),
129133
RuleType: awstypes.RuleTypeOption(d.Get("rule_type").(string)),
130134
Tags: getTagsIn(ctx),
131135
}
132136

137+
if v, ok := d.GetOk("delegation_record"); ok {
138+
input.DelegationRecord = aws.String(v.(string))
139+
}
140+
141+
if v, ok := d.GetOk(names.AttrDomainName); ok {
142+
input.DomainName = aws.String(v.(string))
143+
}
144+
133145
if v, ok := d.GetOk(names.AttrName); ok {
134146
input.Name = aws.String(v.(string))
135147
}
@@ -174,9 +186,14 @@ func resourceRuleRead(ctx context.Context, d *schema.ResourceData, meta any) dia
174186
}
175187

176188
d.Set(names.AttrARN, rule.Arn)
189+
if rule.DelegationRecord != nil {
190+
d.Set("delegation_record", trimTrailingPeriod(aws.ToString(rule.DelegationRecord)))
191+
}
177192
// To be consistent with other AWS services that do not accept a trailing period,
178193
// we remove the suffix from the Domain Name returned from the API
179-
d.Set(names.AttrDomainName, trimTrailingPeriod(aws.ToString(rule.DomainName)))
194+
if rule.DomainName != nil {
195+
d.Set(names.AttrDomainName, trimTrailingPeriod(aws.ToString(rule.DomainName)))
196+
}
180197
d.Set(names.AttrName, rule.Name)
181198
d.Set(names.AttrOwnerID, rule.OwnerId)
182199
d.Set("resolver_endpoint_id", rule.ResolverEndpointId)
@@ -415,7 +432,7 @@ func flattenRuleTargetIPs(targetAddresses []awstypes.TargetAddress) []any {
415432
}
416433

417434
// trimTrailingPeriod is used to remove the trailing period
418-
// of "name" or "domain name" attributes often returned from
435+
// of "name", "domain name" or "delegation_record" attributes often returned from
419436
// the Route53 API or provided as user input.
420437
// The single dot (".") domain name is returned as-is.
421438
func trimTrailingPeriod(v any) string {

internal/service/route53resolver/rule_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ func dataSourceRule() *schema.Resource {
2929
Type: schema.TypeString,
3030
Computed: true,
3131
},
32+
"delegation_record": {
33+
Type: schema.TypeString,
34+
Optional: true,
35+
Computed: true,
36+
ValidateFunc: validation.StringLenBetween(1, 256),
37+
},
3238
names.AttrDomainName: {
3339
Type: schema.TypeString,
3440
Optional: true,

internal/service/route53resolver/rule_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,50 @@ func TestAccRoute53ResolverRule_updateName(t *testing.T) {
227227
})
228228
}
229229

230+
func TestAccRoute53ResolverRule_delegate(t *testing.T) {
231+
ctx := acctest.Context(t)
232+
var rule1 awstypes.ResolverRule
233+
resourceName := "aws_route53_resolver_rule.test"
234+
delegationRecord := acctest.RandomDomainName()
235+
ep1ResourceName := "aws_route53_resolver_endpoint.test.0"
236+
ep2ResourceName := "aws_route53_resolver_endpoint.test.1"
237+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
238+
239+
resource.ParallelTest(t, resource.TestCase{
240+
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
241+
ErrorCheck: acctest.ErrorCheck(t, names.Route53ResolverServiceID),
242+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
243+
CheckDestroy: testAccCheckRuleDestroy(ctx),
244+
Steps: []resource.TestStep{
245+
{
246+
Config: testAccRuleConfig_delegate(rName, delegationRecord, 0),
247+
Check: resource.ComposeTestCheckFunc(
248+
testAccCheckRuleExists(ctx, resourceName, &rule1),
249+
resource.TestCheckResourceAttr(resourceName, "delegation_record", delegationRecord),
250+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
251+
resource.TestCheckResourceAttr(resourceName, "rule_type", "DELEGATE"),
252+
resource.TestCheckResourceAttrPair(resourceName, "resolver_endpoint_id", ep1ResourceName, names.AttrID),
253+
),
254+
},
255+
{
256+
ResourceName: resourceName,
257+
ImportState: true,
258+
ImportStateVerify: true,
259+
},
260+
{
261+
Config: testAccRuleConfig_delegate(rName, delegationRecord, 1),
262+
Check: resource.ComposeTestCheckFunc(
263+
testAccCheckRuleExists(ctx, resourceName, &rule1),
264+
resource.TestCheckResourceAttr(resourceName, "delegation_record", delegationRecord),
265+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
266+
resource.TestCheckResourceAttr(resourceName, "rule_type", "DELEGATE"),
267+
resource.TestCheckResourceAttrPair(resourceName, "resolver_endpoint_id", ep2ResourceName, names.AttrID),
268+
),
269+
},
270+
},
271+
})
272+
}
273+
230274
func TestAccRoute53ResolverRule_forward(t *testing.T) {
231275
ctx := acctest.Context(t)
232276
var rule1, rule2, rule3 awstypes.ResolverRule
@@ -670,6 +714,17 @@ resource "aws_route53_resolver_rule" "test" {
670714
`, rName, domainName)
671715
}
672716

717+
func testAccRuleConfig_delegate(rName, delegationRecord string, resolverEndpointId int) string {
718+
return acctest.ConfigCompose(testAccRuleConfig_resolverEndpointBase(rName), fmt.Sprintf(`
719+
resource "aws_route53_resolver_rule" "test" {
720+
delegation_record = %[2]q
721+
rule_type = "DELEGATE"
722+
name = %[1]q
723+
724+
resolver_endpoint_id = aws_route53_resolver_endpoint.test[%[3]d].id
725+
}
726+
`, rName, delegationRecord, resolverEndpointId))
727+
}
673728
func testAccRuleConfig_forward(rName, domainName string) string {
674729
return acctest.ConfigCompose(testAccRuleConfig_resolverEndpointBase(rName), fmt.Sprintf(`
675730
resource "aws_route53_resolver_rule" "test" {

website/docs/d/route53_resolver_rule.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ data "aws_route53_resolver_rule" "example" {
2626
This data source supports the following arguments:
2727

2828
* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
29+
* `delegation_record` - (Optional) DNS queries with the delegation records that match this domain name are forwarded to the resolvers on your network.
2930
* `domain_name` - (Optional) Domain name the desired resolver rule forwards DNS queries for. Conflicts with `resolver_rule_id`.
3031
* `name` - (Optional) Friendly name of the desired resolver rule. Conflicts with `resolver_rule_id`.
3132
* `resolver_endpoint_id` (Optional) ID of the outbound resolver endpoint of the desired resolver rule. Conflicts with `resolver_rule_id`.
3233
* `resolver_rule_id` (Optional) ID of the desired resolver rule. Conflicts with `domain_name`, `name`, `resolver_endpoint_id` and `rule_type`.
33-
* `rule_type` - (Optional) Rule type of the desired resolver rule. Valid values are `FORWARD`, `SYSTEM` and `RECURSIVE`. Conflicts with `resolver_rule_id`.
34+
* `rule_type` - (Optional) Rule type of the desired resolver rule. Valid values are `DELEGATE`, `FORWARD`, `SYSTEM` and `RECURSIVE`. Conflicts with `resolver_rule_id`.
3435

3536
## Attribute Reference
3637

website/docs/r/route53_resolver_rule.html.markdown

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ resource "aws_route53_resolver_rule" "fwd" {
6464
This resource supports the following arguments:
6565

6666
* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
67-
* `domain_name` - (Required) DNS queries for this domain name are forwarded to the IP addresses that are specified using `target_ip`.
68-
* `rule_type` - (Required) Rule type. Valid values are `FORWARD`, `SYSTEM` and `RECURSIVE`.
67+
* `delegation_record` - (Optional) DNS queries with the delegation records that match this domain name are forwarded to the resolvers on your network.
68+
* `domain_name` - (Optional) DNS queries for this domain name are forwarded to the IP addresses that are specified using `target_ip`.
69+
* `rule_type` - (Required) Rule type. Valid values are `DELEGATE`, `FORWARD`, `SYSTEM` and `RECURSIVE`.
6970
* `name` - (Optional) Friendly name that lets you easily find a rule in the Resolver dashboard in the Route 53 console.
7071
* `resolver_endpoint_id` (Optional) ID of the outbound resolver endpoint that you want to use to route DNS queries to the IP addresses that you specify using `target_ip`.
7172
This argument should only be specified for `FORWARD` type rules.

0 commit comments

Comments
 (0)