Skip to content

Commit

Permalink
Merge pull request #25511 from silvaalbert/f-aws-route53-resolver-fir…
Browse files Browse the repository at this point in the history
…ewall-rule-group

add data source for aws_route53_resolver_firewall_rule_group
  • Loading branch information
ewbankkit authored Nov 9, 2022
2 parents 44fd94d + f05ebea commit bfd7848
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/25511.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_route53_resolver_firewall_rule_group
```
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ func New(_ context.Context) (*schema.Provider, error) {
"aws_route53_resolver_endpoint": route53resolver.DataSourceEndpoint(),
"aws_route53_resolver_firewall_config": route53resolver.DataSourceFirewallConfig(),
"aws_route53_resolver_firewall_domain_list": route53resolver.DataSourceFirewallDomainList(),
"aws_route53_resolver_firewall_rule_group": route53resolver.DataSourceFirewallRuleGroup(),
"aws_route53_resolver_rule": route53resolver.DataSourceRule(),
"aws_route53_resolver_rules": route53resolver.DataSourceRules(),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package route53resolver

import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
)

func DataSourceFirewallRuleGroup() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceFirewallRuleGroupRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"creation_time": {
Type: schema.TypeString,
Computed: true,
},
"creator_request_id": {
Type: schema.TypeString,
Computed: true,
},
"firewall_rule_group_id": {
Type: schema.TypeString,
Required: true,
},
"modification_time": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"owner_id": {
Type: schema.TypeString,
Computed: true,
},
"rule_count": {
Type: schema.TypeInt,
Computed: true,
},
"share_status": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"status_message": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceFirewallRuleGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).Route53ResolverConn

id := d.Get("firewall_rule_group_id").(string)
ruleGroup, err := FindFirewallRuleGroupByID(ctx, conn, id)

if err != nil {
return diag.Errorf("reading Route53 Resolver Firewall Rule Group (%s): %s", id, err)
}

d.SetId(aws.StringValue(ruleGroup.Id))
d.Set("arn", ruleGroup.Arn)
d.Set("creation_time", ruleGroup.CreationTime)
d.Set("creator_request_id", ruleGroup.CreatorRequestId)
d.Set("firewall_rule_group_id", ruleGroup.Id)
d.Set("modification_time", ruleGroup.ModificationTime)
d.Set("name", ruleGroup.Name)
d.Set("owner_id", ruleGroup.OwnerId)
d.Set("rule_count", ruleGroup.RuleCount)
d.Set("share_status", ruleGroup.ShareStatus)
d.Set("status", ruleGroup.Status)
d.Set("status_message", ruleGroup.StatusMessage)

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package route53resolver_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/route53resolver"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func TestAccRoute53ResolverFirewallRuleGroupDataSource_basic(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
dataSourceName := "data.aws_route53_resolver_firewall_rule_group.test"
resourceName := "aws_route53_resolver_firewall_rule_group.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, route53resolver.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccFirewallRuleGroupDataSourceConfig_basic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "firewall_rule_group_id", resourceName, "id"),
resource.TestCheckResourceAttrSet(dataSourceName, "creation_time"),
resource.TestCheckResourceAttrSet(dataSourceName, "creator_request_id"),
resource.TestCheckResourceAttrSet(dataSourceName, "modification_time"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "owner_id", resourceName, "owner_id"),
resource.TestCheckResourceAttr(dataSourceName, "rule_count", "0"),
resource.TestCheckResourceAttrPair(dataSourceName, "share_status", resourceName, "share_status"),
resource.TestCheckResourceAttrSet(dataSourceName, "status"),
resource.TestCheckResourceAttrSet(dataSourceName, "status_message"),
),
},
},
})
}

func testAccFirewallRuleGroupDataSourceConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_route53_resolver_firewall_rule_group" "test" {
name = %[1]q
}
data "aws_route53_resolver_firewall_rule_group" "test" {
firewall_rule_group_id = aws_route53_resolver_firewall_rule_group.test.id
}
`, rName)
}
40 changes: 40 additions & 0 deletions website/docs/d/route53_resolver_firewall_rule_group.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
subcategory: "Route 53 Resolver"
layout: "aws"
page_title: "AWS: aws_route53_resolver_firewall_rule_group"
description: |-
Retrieves the specified firewall rule group.
---

# Data Source: aws_route53_resolver_firewall_rule_group

`aws_route53_resolver_firewall_rule_group` Retrieves the specified firewall rule group.

This data source allows to retrieve details about a specific a Route 53 Resolver DNS Firewall rule group.

## Example Usage

The following example shows how to get a firewall rule group from its ID.

```terraform
data "aws_route53_resolver_firewall_rule_group" "example" {
firewall_rule_group_id = "rslvr-frg-example"
}
```

## Argument Reference

* `firewall_rule_group_id` - (Required) The ID of the rule group.

The following attribute is additionally exported:

* `arn` - The ARN (Amazon Resource Name) of the rule group.
* `creation_time` - The date and time that the rule group was created, in Unix time format and Coordinated Universal Time (UTC).
* `creator_request_id` - A unique string defined by you to identify the request.
* `name` - The name of the rule group.
* `modification_time` - The date and time that the rule group was last modified, in Unix time format and Coordinated Universal Time (UTC).
* `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.
* `rule_count` - The number of rules in the rule group.
* `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.
* `status` - The status of the rule group.
* `status_message` - Additional information about the status of the rule group, if available.

0 comments on commit bfd7848

Please sign in to comment.