forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/stable-website'
- Loading branch information
Showing
22 changed files
with
4,751 additions
and
74 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
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 |
---|---|---|
|
@@ -100,6 +100,7 @@ awsproviderlint: | |
-S015 \ | ||
-S016 \ | ||
-S017 \ | ||
-S018 \ | ||
-S019 \ | ||
-S020 \ | ||
-S021 \ | ||
|
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
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,83 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/wafv2" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
) | ||
|
||
func dataSourceAwsWafv2RuleGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsWafv2RuleGroupRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"scope": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
wafv2.ScopeCloudfront, | ||
wafv2.ScopeRegional, | ||
}, false), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsWafv2RuleGroupRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).wafv2conn | ||
name := d.Get("name").(string) | ||
|
||
var foundRuleGroup *wafv2.RuleGroupSummary | ||
input := &wafv2.ListRuleGroupsInput{ | ||
Scope: aws.String(d.Get("scope").(string)), | ||
Limit: aws.Int64(100), | ||
} | ||
|
||
for { | ||
resp, err := conn.ListRuleGroups(input) | ||
if err != nil { | ||
return fmt.Errorf("Error reading WAFv2 RuleGroups: %s", err) | ||
} | ||
|
||
if resp == nil || resp.RuleGroups == nil { | ||
return fmt.Errorf("Error reading WAFv2 RuleGroups") | ||
} | ||
|
||
for _, ruleGroup := range resp.RuleGroups { | ||
if aws.StringValue(ruleGroup.Name) == name { | ||
foundRuleGroup = ruleGroup | ||
break | ||
} | ||
} | ||
|
||
if resp.NextMarker == nil || foundRuleGroup != nil { | ||
break | ||
} | ||
input.NextMarker = resp.NextMarker | ||
} | ||
|
||
if foundRuleGroup == nil { | ||
return fmt.Errorf("WAFv2 RuleGroup not found for name: %s", name) | ||
} | ||
|
||
d.SetId(aws.StringValue(foundRuleGroup.Id)) | ||
d.Set("arn", aws.StringValue(foundRuleGroup.ARN)) | ||
d.Set("description", aws.StringValue(foundRuleGroup.Description)) | ||
|
||
return nil | ||
} |
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,80 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsWafv2RuleGroup_Basic(t *testing.T) { | ||
name := acctest.RandomWithPrefix("tf-acc-test") | ||
resourceName := "aws_wafv2_rule_group.test" | ||
datasourceName := "data.aws_wafv2_rule_group.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsWafv2RuleGroup_NonExistent(name), | ||
ExpectError: regexp.MustCompile(`WAFv2 RuleGroup not found`), | ||
}, | ||
{ | ||
Config: testAccDataSourceAwsWafv2RuleGroup_Name(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"), | ||
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "wafv2", regexp.MustCompile(fmt.Sprintf("regional/rulegroup/%v/.+$", name))), | ||
resource.TestCheckResourceAttrPair(datasourceName, "description", resourceName, "description"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "id", resourceName, "id"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "scope", resourceName, "scope"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsWafv2RuleGroup_Name(name string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_wafv2_rule_group" "test" { | ||
name = "%s" | ||
scope = "REGIONAL" | ||
capacity = 10 | ||
visibility_config { | ||
cloudwatch_metrics_enabled = false | ||
metric_name = "friendly-rule-metric-name" | ||
sampled_requests_enabled = false | ||
} | ||
} | ||
data "aws_wafv2_rule_group" "test" { | ||
name = aws_wafv2_rule_group.test.name | ||
scope = "REGIONAL" | ||
} | ||
`, name) | ||
} | ||
|
||
func testAccDataSourceAwsWafv2RuleGroup_NonExistent(name string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_wafv2_rule_group" "test" { | ||
name = "%s" | ||
scope = "REGIONAL" | ||
capacity = 10 | ||
visibility_config { | ||
cloudwatch_metrics_enabled = false | ||
metric_name = "friendly-rule-metric-name" | ||
sampled_requests_enabled = false | ||
} | ||
} | ||
data "aws_wafv2_rule_group" "test" { | ||
name = "tf-acc-test-does-not-exist" | ||
scope = "REGIONAL" | ||
} | ||
`, name) | ||
} |
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
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
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
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
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
Oops, something went wrong.