Skip to content

Commit

Permalink
Merge pull request #29 from signalsciences/FixSiteShortNamesReorder
Browse files Browse the repository at this point in the history
remove all deepEquals checks, they are not necessary. Add in tests pr…
  • Loading branch information
jhanrahan-sigsci authored Mar 9, 2021
2 parents b570584 + 24b9d7f commit b44b963
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 29 deletions.
3 changes: 1 addition & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ resource "sigsci_site" "my-site" {
agent_level = "block"
}


resource "sigsci_corp_list" "test" {
name = "My corp list"
type = "ip"
Expand Down Expand Up @@ -180,7 +179,7 @@ resource "sigsci_site_rule" "test" {
}

actions {
type = "block"
type = "excludeSignal"
}
}

Expand Down
6 changes: 0 additions & 6 deletions provider/resource_corp_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/signalsciences/go-sigsci"
"reflect"
)

func resourceCorpList() *schema.Resource {
Expand Down Expand Up @@ -132,10 +131,5 @@ func resourceCorpListUpdate(d *schema.ResourceData, m interface{}) error {
if err != nil {
return fmt.Errorf("%s. Could not update list with ID %s in corp %s. Please re-run", err.Error(), d.Id(), corp)
}
after, err := sc.GetCorpListByID(corp, d.Id())
if err == nil && reflect.DeepEqual(after.CreateListBody, before.CreateListBody) {
return fmt.Errorf("Update failed for list ID %s in corp %s\ngot:\n%#v\nexpected:\n%#v.Please re-run",
d.Id(), corp, after.CreateListBody, updateCorpListBody)
}
return resourceCorpListRead(d, m)
}
10 changes: 0 additions & 10 deletions provider/resource_corp_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/signalsciences/go-sigsci"
"reflect"
)

func resourceCorpRule() *schema.Resource {
Expand Down Expand Up @@ -211,10 +210,6 @@ func resourceCorpRuleCreate(d *schema.ResourceData, m interface{}) error {
if err != nil {
return err
}
_, err = sc.GetCorpRuleByID(corp, rule.ID)
if err != nil {
return fmt.Errorf("%s. Could not create rule with ID %s in corp %s. Please re-run", err.Error(), rule.ID, corp)
}
d.SetId(rule.ID)
return resourceCorpRuleRead(d, m)
}
Expand Down Expand Up @@ -242,11 +237,6 @@ func resourceCorpRuleUpdate(d *schema.ResourceData, m interface{}) error {
if err != nil {
return fmt.Errorf("%s. Could not update rule with ID %s in corp %s ", err.Error(), corp, d.Id())
}
rule, err := sc.GetCorpRuleByID(corp, d.Id())
if err == nil && !reflect.DeepEqual(updateCorpRuleBody, rule.CreateCorpRuleBody) {
return fmt.Errorf("Update failed for rule ID %s in corp %s\ngot:\n%#v\nexpected:\n%#v\nPlease re-run",
d.Id(), corp, rule.CreateCorpRuleBody, updateCorpRuleBody)
}
return resourceCorpRuleRead(d, m)
}
func resourceCorpRuleRead(d *schema.ResourceData, m interface{}) error {
Expand Down
133 changes: 133 additions & 0 deletions provider/resource_corp_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,139 @@ func TestResourceCorpRule_basic(t *testing.T) {
})
}

// The api appears to sort site_short_names
func TestResourceCorpRule_SortedSiteNames(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: fmt.Sprintf(`
resource "sigsci_site" "test_site" {
short_name = "aaa_corp_rule_test_site"
display_name = "z corp rule test site"
agent_anon_mode = "EU"
block_duration_seconds = 86400
}
resource "sigsci_site" "test_site2" {
short_name = "zzz_corp_rule_test_site"
display_name = "a corp rule test site 2"
agent_anon_mode = "EU"
block_duration_seconds = 86400
}
resource "sigsci_corp_rule" "test"{
site_short_names=["%s", sigsci_site.test_site.short_name]
type= "signal"
corp_scope="specificSites"
enabled=true
group_operator="any"
signal="SQLI"
reason="Example corp rule"
expiration= ""
conditions {
type="single"
field="ip"
operator="equals"
value="1.2.3.4"
}
actions {
type="excludeSignal"
}
}`, testSite),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "site_short_names.#", "2"),
),
},
{
Config: fmt.Sprintf(`
resource "sigsci_site" "test_site"{
short_name = "aaa_corp_rule_test_site"
display_name = "z corp rule test site"
agent_anon_mode = "EU"
block_duration_seconds = 86400
}
resource "sigsci_site" "test_site2"{
short_name = "zzz_corp_rule_test_site"
display_name = "a corp rule test site 2"
agent_anon_mode = "EU"
block_duration_seconds = 86400
}
resource "sigsci_corp_rule" "test"{
site_short_names=["%s", sigsci_site.test_site.short_name, sigsci_site.test_site2.short_name]
type= "signal"
corp_scope="specificSites"
enabled=false
group_operator="any"
signal="SQLI"
reason="Example corp rule"
expiration= ""
conditions {
type="single"
field="ip"
operator="equals"
value="1.2.3.4"
}
actions {
type="excludeSignal"
}
}`, testSite),
Check: resource.ComposeAggregateTestCheckFunc(
testInspect(),
resource.TestCheckResourceAttr(resourceName, "site_short_names.#", "3"),
),
},
{
Config: fmt.Sprintf(`
resource "sigsci_site" "test_site"{
short_name = "aaa_corp_rule_test_site"
display_name = "z corp rule test site"
agent_anon_mode = "EU"
block_duration_seconds = 86400
}
resource "sigsci_site" "test_site2"{
short_name = "zzz_corp_rule_test_site"
display_name = "a corp rule test site 2"
agent_anon_mode = "EU"
block_duration_seconds = 86400
}
resource "sigsci_corp_rule" "test"{
site_short_names=[sigsci_site.test_site2.short_name, sigsci_site.test_site.short_name, "%s"]
type= "signal"
corp_scope="specificSites"
enabled=false
group_operator="any"
signal="SQLI"
reason="Example corp rule"
expiration= ""
conditions {
type="single"
field="ip"
operator="equals"
value="1.2.3.4"
}
actions {
type="excludeSignal"
}
}`, testSite),
Check: resource.ComposeAggregateTestCheckFunc(
testInspect(),
resource.TestCheckResourceAttr(resourceName, "site_short_names.#", "3"),
//resource.TestCheckResourceAttr(resourceName, "site_short_names.1785148924", testSite),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateCheck: testAccImportStateCheckFunction(1),
},
},
})
}

func testACCCheckCorpRuleDestroy(s *terraform.State) error {
pm := testAccProvider.Meta().(providerMetadata)
sc := pm.Client
Expand Down
5 changes: 0 additions & 5 deletions provider/resource_corp_signal_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ func resourceCorpSignalTagUpdate(d *schema.ResourceData, m interface{}) error {
if err != nil {
return fmt.Errorf("%s. Could not update signaltag with ID %s in corp %s", err.Error(), d.Id(), corp)
}
after, err := sc.GetCorpSignalTagByID(corp, d.Id())
if err == nil && reflect.DeepEqual(before, after) {
return fmt.Errorf("Update failed for signaltag ID %s in corp %s\ngot:\n%#v\nexpected:\n%#v\nPlease re-run",
d.Id(), corp, after, updateSignalTagBody)
}
return resourceCorpSignalTagRead(d, m)
}

Expand Down
6 changes: 0 additions & 6 deletions provider/resource_site_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/signalsciences/go-sigsci"
"reflect"
)

func resourceSiteRule() *schema.Resource {
Expand Down Expand Up @@ -314,11 +313,6 @@ func resourceSiteRuleUpdate(d *schema.ResourceData, m interface{}) error {
if err != nil {
return err
}
rule, err := sc.GetSiteRuleByID(corp, site, d.Id())
if err == nil && !reflect.DeepEqual(updateSiteRuleBody, rule.CreateSiteRuleBody) {
return fmt.Errorf("Update failed for rule ID %s in corp %s in site %s\ngot:\n%#v\nexpected:\n%#v\nPlease re-run",
d.Id(), corp, site, rule.CreateSiteRuleBody, updateSiteRuleBody)
}
return resourceSiteRuleRead(d, m)
}

Expand Down

0 comments on commit b44b963

Please sign in to comment.