Skip to content

Commit bfd7848

Browse files
authored
Merge pull request #25511 from silvaalbert/f-aws-route53-resolver-firewall-rule-group
add data source for aws_route53_resolver_firewall_rule_group
2 parents 44fd94d + f05ebea commit bfd7848

File tree

5 files changed

+186
-0
lines changed

5 files changed

+186
-0
lines changed

.changelog/25511.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-data-source
2+
aws_route53_resolver_firewall_rule_group
3+
```

internal/provider/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ func New(_ context.Context) (*schema.Provider, error) {
849849
"aws_route53_resolver_endpoint": route53resolver.DataSourceEndpoint(),
850850
"aws_route53_resolver_firewall_config": route53resolver.DataSourceFirewallConfig(),
851851
"aws_route53_resolver_firewall_domain_list": route53resolver.DataSourceFirewallDomainList(),
852+
"aws_route53_resolver_firewall_rule_group": route53resolver.DataSourceFirewallRuleGroup(),
852853
"aws_route53_resolver_rule": route53resolver.DataSourceRule(),
853854
"aws_route53_resolver_rules": route53resolver.DataSourceRules(),
854855

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package route53resolver
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go/aws"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/hashicorp/terraform-provider-aws/internal/conns"
10+
)
11+
12+
func DataSourceFirewallRuleGroup() *schema.Resource {
13+
return &schema.Resource{
14+
ReadWithoutTimeout: dataSourceFirewallRuleGroupRead,
15+
16+
Schema: map[string]*schema.Schema{
17+
"arn": {
18+
Type: schema.TypeString,
19+
Computed: true,
20+
},
21+
"creation_time": {
22+
Type: schema.TypeString,
23+
Computed: true,
24+
},
25+
"creator_request_id": {
26+
Type: schema.TypeString,
27+
Computed: true,
28+
},
29+
"firewall_rule_group_id": {
30+
Type: schema.TypeString,
31+
Required: true,
32+
},
33+
"modification_time": {
34+
Type: schema.TypeString,
35+
Computed: true,
36+
},
37+
"name": {
38+
Type: schema.TypeString,
39+
Computed: true,
40+
},
41+
"owner_id": {
42+
Type: schema.TypeString,
43+
Computed: true,
44+
},
45+
"rule_count": {
46+
Type: schema.TypeInt,
47+
Computed: true,
48+
},
49+
"share_status": {
50+
Type: schema.TypeString,
51+
Computed: true,
52+
},
53+
"status": {
54+
Type: schema.TypeString,
55+
Computed: true,
56+
},
57+
"status_message": {
58+
Type: schema.TypeString,
59+
Computed: true,
60+
},
61+
},
62+
}
63+
}
64+
65+
func dataSourceFirewallRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
66+
conn := meta.(*conns.AWSClient).Route53ResolverConn
67+
68+
id := d.Get("firewall_rule_group_id").(string)
69+
ruleGroup, err := FindFirewallRuleGroupByID(ctx, conn, id)
70+
71+
if err != nil {
72+
return diag.Errorf("reading Route53 Resolver Firewall Rule Group (%s): %s", id, err)
73+
}
74+
75+
d.SetId(aws.StringValue(ruleGroup.Id))
76+
d.Set("arn", ruleGroup.Arn)
77+
d.Set("creation_time", ruleGroup.CreationTime)
78+
d.Set("creator_request_id", ruleGroup.CreatorRequestId)
79+
d.Set("firewall_rule_group_id", ruleGroup.Id)
80+
d.Set("modification_time", ruleGroup.ModificationTime)
81+
d.Set("name", ruleGroup.Name)
82+
d.Set("owner_id", ruleGroup.OwnerId)
83+
d.Set("rule_count", ruleGroup.RuleCount)
84+
d.Set("share_status", ruleGroup.ShareStatus)
85+
d.Set("status", ruleGroup.Status)
86+
d.Set("status_message", ruleGroup.StatusMessage)
87+
88+
return nil
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package route53resolver_test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/aws/aws-sdk-go/service/route53resolver"
8+
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
11+
)
12+
13+
func TestAccRoute53ResolverFirewallRuleGroupDataSource_basic(t *testing.T) {
14+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
15+
dataSourceName := "data.aws_route53_resolver_firewall_rule_group.test"
16+
resourceName := "aws_route53_resolver_firewall_rule_group.test"
17+
18+
resource.Test(t, resource.TestCase{
19+
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(t) },
20+
ErrorCheck: acctest.ErrorCheck(t, route53resolver.EndpointsID),
21+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
22+
Steps: []resource.TestStep{
23+
{
24+
Config: testAccFirewallRuleGroupDataSourceConfig_basic(rName),
25+
Check: resource.ComposeAggregateTestCheckFunc(
26+
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
27+
resource.TestCheckResourceAttrPair(dataSourceName, "firewall_rule_group_id", resourceName, "id"),
28+
resource.TestCheckResourceAttrSet(dataSourceName, "creation_time"),
29+
resource.TestCheckResourceAttrSet(dataSourceName, "creator_request_id"),
30+
resource.TestCheckResourceAttrSet(dataSourceName, "modification_time"),
31+
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
32+
resource.TestCheckResourceAttrPair(dataSourceName, "owner_id", resourceName, "owner_id"),
33+
resource.TestCheckResourceAttr(dataSourceName, "rule_count", "0"),
34+
resource.TestCheckResourceAttrPair(dataSourceName, "share_status", resourceName, "share_status"),
35+
resource.TestCheckResourceAttrSet(dataSourceName, "status"),
36+
resource.TestCheckResourceAttrSet(dataSourceName, "status_message"),
37+
),
38+
},
39+
},
40+
})
41+
}
42+
43+
func testAccFirewallRuleGroupDataSourceConfig_basic(rName string) string {
44+
return fmt.Sprintf(`
45+
resource "aws_route53_resolver_firewall_rule_group" "test" {
46+
name = %[1]q
47+
}
48+
49+
data "aws_route53_resolver_firewall_rule_group" "test" {
50+
firewall_rule_group_id = aws_route53_resolver_firewall_rule_group.test.id
51+
}
52+
`, rName)
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
subcategory: "Route 53 Resolver"
3+
layout: "aws"
4+
page_title: "AWS: aws_route53_resolver_firewall_rule_group"
5+
description: |-
6+
Retrieves the specified firewall rule group.
7+
---
8+
9+
# Data Source: aws_route53_resolver_firewall_rule_group
10+
11+
`aws_route53_resolver_firewall_rule_group` Retrieves the specified firewall rule group.
12+
13+
This data source allows to retrieve details about a specific a Route 53 Resolver DNS Firewall rule group.
14+
15+
## Example Usage
16+
17+
The following example shows how to get a firewall rule group from its ID.
18+
19+
```terraform
20+
data "aws_route53_resolver_firewall_rule_group" "example" {
21+
firewall_rule_group_id = "rslvr-frg-example"
22+
}
23+
```
24+
25+
## Argument Reference
26+
27+
* `firewall_rule_group_id` - (Required) The ID of the rule group.
28+
29+
The following attribute is additionally exported:
30+
31+
* `arn` - The ARN (Amazon Resource Name) of the rule group.
32+
* `creation_time` - The date and time that the rule group was created, in Unix time format and Coordinated Universal Time (UTC).
33+
* `creator_request_id` - A unique string defined by you to identify the request.
34+
* `name` - The name of the rule group.
35+
* `modification_time` - The date and time that the rule group was last modified, in Unix time format and Coordinated Universal Time (UTC).
36+
* `owner_id` - The Amazon Web Services account ID for the account that created the rule group. When a rule group is shared with your account, this is the account that has shared the rule group with you.
37+
* `rule_count` - The number of rules in the rule group.
38+
* `share_status` - Whether the rule group is shared with other Amazon Web Services accounts, or was shared with the current account by another Amazon Web Services account.
39+
* `status` - The status of the rule group.
40+
* `status_message` - Additional information about the status of the rule group, if available.

0 commit comments

Comments
 (0)