|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package wafv2_test |
| 5 | + |
| 6 | +import ( |
| 7 | + "fmt" |
| 8 | + "testing" |
| 9 | + |
| 10 | + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" |
| 11 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 12 | + "github.com/hashicorp/terraform-provider-aws/internal/acctest" |
| 13 | + |
| 14 | + "github.com/hashicorp/terraform-provider-aws/names" |
| 15 | +) |
| 16 | + |
| 17 | +func TestAccWAFV2WebACLsDataSource_basic(t *testing.T) { |
| 18 | + ctx := acctest.Context(t) |
| 19 | + |
| 20 | + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) |
| 21 | + dataSourceName := "data.aws_wafv2_web_acls.test" |
| 22 | + |
| 23 | + resource.ParallelTest(t, resource.TestCase{ |
| 24 | + PreCheck: func() { |
| 25 | + acctest.PreCheck(ctx, t) |
| 26 | + }, |
| 27 | + ErrorCheck: acctest.ErrorCheck(t, names.WAFV2ServiceID), |
| 28 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, |
| 29 | + CheckDestroy: testAccCheckWebACLDestroy(ctx), |
| 30 | + Steps: []resource.TestStep{ |
| 31 | + { |
| 32 | + Config: testAccWebAclsDataSourceConfig_basic(rName), |
| 33 | + Check: resource.ComposeAggregateTestCheckFunc( |
| 34 | + acctest.CheckResourceAttrGreaterThanValue(dataSourceName, "names.#", 1), |
| 35 | + resource.TestCheckTypeSetElemAttrPair(dataSourceName, "names.*", "aws_wafv2_web_acl.test1", names.AttrName), |
| 36 | + resource.TestCheckTypeSetElemAttrPair(dataSourceName, "names.*", "aws_wafv2_web_acl.test2", names.AttrName), |
| 37 | + ), |
| 38 | + }, |
| 39 | + }, |
| 40 | + }) |
| 41 | +} |
| 42 | + |
| 43 | +func testAccWebAclsDataSourceConfig_basic(rName string) string { |
| 44 | + return fmt.Sprintf(` |
| 45 | +resource "aws_wafv2_web_acl" "test1" { |
| 46 | + name = "%[1]s-test1" |
| 47 | + scope = "REGIONAL" |
| 48 | +
|
| 49 | + default_action { |
| 50 | + block {} |
| 51 | + } |
| 52 | +
|
| 53 | + visibility_config { |
| 54 | + cloudwatch_metrics_enabled = false |
| 55 | + metric_name = "friendly-rule-metric-name" |
| 56 | + sampled_requests_enabled = false |
| 57 | + } |
| 58 | +} |
| 59 | +resource "aws_wafv2_web_acl" "test2" { |
| 60 | + name = "%[1]s-test2" |
| 61 | + scope = "REGIONAL" |
| 62 | +
|
| 63 | + default_action { |
| 64 | + block {} |
| 65 | + } |
| 66 | +
|
| 67 | + visibility_config { |
| 68 | + cloudwatch_metrics_enabled = false |
| 69 | + metric_name = "friendly-rule-metric-name" |
| 70 | + sampled_requests_enabled = false |
| 71 | + } |
| 72 | +} |
| 73 | +
|
| 74 | +data "aws_wafv2_web_acls" "test" { |
| 75 | + scope = "REGIONAL" |
| 76 | + depends_on = [aws_wafv2_web_acl.test1, aws_wafv2_web_acl.test2] |
| 77 | +} |
| 78 | +`, rName) |
| 79 | +} |
0 commit comments