Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new modsec_rule_ids filter argument in fastly_waf_rules data resource #521

Merged
merged 4 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/data-sources/waf_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ The `rules` block supports:

- **exclude_modsec_rule_ids** (List of Number) A list of modsecurity rules IDs to be excluded from the data set.
- **id** (String) The ID of this resource.
- **modsec_rule_ids** (List of Number) A list of modsecurity rules IDs to be used as filters for the data set.
- **publishers** (List of String) A list of publishers to be used as filters for the data set.
- **tags** (List of String) A list of tags to be used as filters for the data set.

Expand Down
13 changes: 13 additions & 0 deletions fastly/data_source_waf_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ func dataSourceFastlyWAFRules() *schema.Resource {
Description: "A list of tags to be used as filters for the data set.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"modsec_rule_ids": {
Type: schema.TypeList,
Optional: true,
Description: "A list of modsecurity rules IDs to be used as filters for the data set.",
Elem: &schema.Schema{Type: schema.TypeInt},
},
"exclude_modsec_rule_ids": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -85,6 +91,13 @@ func dataSourceFastlyWAFRulesRead(_ context.Context, d *schema.ResourceData, met
}
}

if v, ok := d.GetOk("modsec_rule_ids"); ok {
l := v.([]interface{})
for i := range l {
input.FilterModSecIDs = append(input.FilterModSecIDs, l[i].(int))
}
}

if v, ok := d.GetOk("exclude_modsec_rule_ids"); ok {
l := v.([]interface{})
for i := range l {
Expand Down
19 changes: 19 additions & 0 deletions fastly/data_source_waf_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ func TestAccFastlyWAFRulesPublisherFilter(t *testing.T) {
})
}

func TestAccFastlyWAFRulesModSecIDsFilter(t *testing.T) {

wafrulesHCL := `
modsec_rule_ids = [1010060, 1010070]
`

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckServiceV1Destroy,
Steps: []resource.TestStep{
{
Config: testAccFastlyWAFRules(wafrulesHCL),
Check: resource.TestCheckResourceAttr("data.fastly_waf_rules.r1", "rules.#", "2"),
},
},
})
}

func TestAccFastlyWAFRulesExcludeFilter(t *testing.T) {

wafrulesHCL := `
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
github.com/bflad/tfproviderlint v0.27.1
github.com/fastly/go-fastly/v5 v5.1.3
github.com/fastly/go-fastly/v5 v5.2.0
github.com/google/go-cmp v0.5.6
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-docs v0.5.0
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fastly/go-fastly/v5 v5.1.3 h1:idgaGxLqPn9m+pZu7Fo8uNB7UJXqwtEoKHmhr3VtqlI=
github.com/fastly/go-fastly/v5 v5.1.3/go.mod h1:4WKmXkCyvjq6+XlE9zrCBsFyoQngQGQjVkpr0LjAXoY=
github.com/fastly/go-fastly/v5 v5.2.0 h1:jWULYVCcER3x4a2gX4KTyg/+ejBlBcmVOXg4mTyn/Y4=
github.com/fastly/go-fastly/v5 v5.2.0/go.mod h1:zlDZcVcOigWpNixpCvV0LdatzXtgpg5ISOETF5CoKWo=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
Expand Down Expand Up @@ -341,6 +341,8 @@ github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/peterhellberg/link v1.1.0 h1:s2+RH8EGuI/mI4QwrWGSYQCRz7uNgip9BaM04HKu5kc=
github.com/peterhellberg/link v1.1.0/go.mod h1:gtSlOT4jmkY8P47hbTc8PTgiDDWpdPbFYl75keYyBB8=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -694,7 +696,6 @@ gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qS
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
115 changes: 115 additions & 0 deletions vendor/github.com/fastly/go-fastly/v5/fastly/acl_entry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/fastly/go-fastly/v5/fastly/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

115 changes: 113 additions & 2 deletions vendor/github.com/fastly/go-fastly/v5/fastly/dictionary_item.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading