-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25511 from silvaalbert/f-aws-route53-resolver-fir…
…ewall-rule-group add data source for aws_route53_resolver_firewall_rule_group
- Loading branch information
Showing
5 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
internal/service/route53resolver/firewall_rule_group_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
53 changes: 53 additions & 0 deletions
53
internal/service/route53resolver/firewall_rule_group_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
website/docs/d/route53_resolver_firewall_rule_group.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |