diff --git a/go.mod b/go.mod index f69f7c5..1ab300b 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/hashicorp/terraform-plugin-docs v0.14.1 github.com/hashicorp/terraform-plugin-sdk v1.14.0 - github.com/signalsciences/go-sigsci v0.1.15 + github.com/signalsciences/go-sigsci v0.1.16 golang.org/x/lint v0.0.0-20190409202823-959b441ac422 honnef.co/go/tools v0.4.2 ) diff --git a/go.sum b/go.sum index b94851b..0316586 100644 --- a/go.sum +++ b/go.sum @@ -257,8 +257,8 @@ github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/signalsciences/go-sigsci v0.1.15 h1:Z1Wkli5NtN8OsvBBWBgXRS0LpAsmVrl1dgCPqFrKglo= -github.com/signalsciences/go-sigsci v0.1.15/go.mod h1:CXwoXk81ZwFdne6o8cnAYwxvke5kcLg7zE6Bl/e1KUo= +github.com/signalsciences/go-sigsci v0.1.16 h1:4Z6kwgSyo0gPLRLv+/gsaeq+CeGuE/AhENOR2aANnm4= +github.com/signalsciences/go-sigsci v0.1.16/go.mod h1:CXwoXk81ZwFdne6o8cnAYwxvke5kcLg7zE6Bl/e1KUo= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= diff --git a/provider/resource_corp_rule.go b/provider/resource_corp_rule.go index d9463b4..480def2 100644 --- a/provider/resource_corp_rule.go +++ b/provider/resource_corp_rule.go @@ -209,13 +209,14 @@ func resourceCorpRuleCreate(d *schema.ResourceData, m interface{}) error { sc := pm.Client corp := pm.Corp corpRuleBody := sigsci.CreateCorpRuleBody{ - Type: d.Get("type").(string), - CorpScope: d.Get("corp_scope").(string), - Enabled: d.Get("enabled").(bool), - GroupOperator: d.Get("group_operator").(string), - Reason: d.Get("reason").(string), - Signal: d.Get("signal").(string), - Expiration: d.Get("expiration").(string), + Type: d.Get("type").(string), + CorpScope: d.Get("corp_scope").(string), + Enabled: d.Get("enabled").(bool), + GroupOperator: d.Get("group_operator").(string), + Reason: d.Get("reason").(string), + Signal: d.Get("signal").(string), + Expiration: d.Get("expiration").(string), + RequestLogging: d.Get("requestlogging").(string), } corpRuleBody.SiteNames = expandStringArray(d.Get("site_short_names").(*schema.Set)) @@ -236,13 +237,14 @@ func resourceCorpRuleUpdate(d *schema.ResourceData, m interface{}) error { corp := pm.Corp updateCorpRuleBody := sigsci.CreateCorpRuleBody{ - Type: d.Get("type").(string), - CorpScope: d.Get("corp_scope").(string), - Enabled: d.Get("enabled").(bool), - GroupOperator: d.Get("group_operator").(string), - Reason: d.Get("reason").(string), - Signal: d.Get("signal").(string), - Expiration: d.Get("expiration").(string), + Type: d.Get("type").(string), + CorpScope: d.Get("corp_scope").(string), + Enabled: d.Get("enabled").(bool), + GroupOperator: d.Get("group_operator").(string), + Reason: d.Get("reason").(string), + Signal: d.Get("signal").(string), + Expiration: d.Get("expiration").(string), + RequestLogging: d.Get("requestlogging").(string), } updateCorpRuleBody.SiteNames = expandStringArray(d.Get("site_short_names").(*schema.Set)) @@ -295,6 +297,10 @@ func resourceCorpRuleRead(d *schema.ResourceData, m interface{}) error { if err != nil { return err } + err = d.Set("requestlogging", rule.RequestLogging) + if err != nil { + return err + } err = d.Set("site_short_names", flattenStringArray(rule.SiteNames)) if err != nil { return err diff --git a/provider/resource_corp_rule_test.go b/provider/resource_corp_rule_test.go index f9fa57b..7f8b0e7 100644 --- a/provider/resource_corp_rule_test.go +++ b/provider/resource_corp_rule_test.go @@ -225,3 +225,61 @@ func testACCCheckCorpRuleDestroy(s *terraform.State) error { } return nil } + +func TestResourceCorpRequestRule(t *testing.T) { + t.Parallel() + resourceName := "sigsci_corp_rule.test" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testACCCheckCorpRuleDestroy, + Steps: []resource.TestStep{ + { + Config: ` + resource "sigsci_corp_rule" "test"{ + type= "request" + corp_scope="global" + enabled=true + group_operator="any" + reason="Example corp rule" + requestlogging="none" + expiration= "" + + conditions { + type="single" + field="ip" + operator="equals" + value="1.2.3.4" + } + actions { + type="block" + } + }`, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "actions.#", "1"), + resource.TestCheckResourceAttr(resourceName, "actions.1990726244.type", "block"), + resource.TestCheckResourceAttr(resourceName, "conditions.#", "1"), + resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.conditions.#", "0"), + resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.field", "ip"), + resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.group_operator", ""), + resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.operator", "equals"), + resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.type", "single"), + resource.TestCheckResourceAttr(resourceName, "conditions.2534374319.value", "1.2.3.4"), + resource.TestCheckResourceAttr(resourceName, "corp_scope", "global"), + resource.TestCheckResourceAttr(resourceName, "enabled", "true"), + resource.TestCheckResourceAttr(resourceName, "expiration", ""), + resource.TestCheckResourceAttr(resourceName, "group_operator", "any"), + resource.TestCheckResourceAttr(resourceName, "reason", "Example corp rule"), + resource.TestCheckResourceAttr(resourceName, "type", "request"), + resource.TestCheckResourceAttr(resourceName, "requestlogging", "none"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateCheck: testAccImportStateCheckFunction(1), + }, + }, + }) +}