Skip to content

Commit 4a8434a

Browse files
committed
fix ip_filter acc test - delete resource after creation to avoid conflict during next run
1 parent de61a83 commit 4a8434a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

sysdig/resource_sysdig_ip_filter_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ package sysdig_test
44

55
import (
66
"fmt"
7-
"github.com/draios/terraform-provider-sysdig/sysdig"
87
"testing"
98

9+
"github.com/draios/terraform-provider-sysdig/sysdig"
10+
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
1012
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1113
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1214
)
1315

1416
func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
17+
ipRange1 := generateRandomIPRange()
18+
ipRange2 := generateRandomIPRange()
19+
1520
resource.Test(t, resource.TestCase{
1621
PreCheck: preCheckAnyEnv(t, SysdigMonitorApiTokenEnv),
1722
ProviderFactories: map[string]func() (*schema.Provider, error){
@@ -21,19 +26,19 @@ func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
2126
},
2227
Steps: []resource.TestStep{
2328
{
24-
// Create resource
25-
Config: createIPFilter("192.168.1.0/24", "Initial note", true),
29+
// Create resource with the first random IP range
30+
Config: createIPFilter(ipRange1, "Initial note", true),
2631
Check: resource.ComposeTestCheckFunc(
27-
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", "192.168.1.0/24"),
32+
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", ipRange1),
2833
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "note", "Initial note"),
2934
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "enabled", "true"),
3035
),
3136
},
3237
{
33-
// Update resource
34-
Config: createIPFilter("192.168.2.0/24", "Updated note", false),
38+
// Update resource with the second random IP range
39+
Config: createIPFilter(ipRange2, "Updated note", false),
3540
Check: resource.ComposeTestCheckFunc(
36-
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", "192.168.2.0/24"),
41+
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", ipRange2),
3742
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "note", "Updated note"),
3843
resource.TestCheckResourceAttr("sysdig_ip_filter.test", "enabled", "false"),
3944
),
@@ -42,6 +47,10 @@ func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) {
4247
})
4348
}
4449

50+
func generateRandomIPRange() string {
51+
return fmt.Sprintf("%d.%d.%d.0/24", acctest.RandIntRange(0, 255), acctest.RandIntRange(0, 255), acctest.RandIntRange(0, 255))
52+
}
53+
4554
func createIPFilter(ipRange, note string, enabled bool) string {
4655
return fmt.Sprintf(`
4756
resource "sysdig_ip_filter" "test" {

0 commit comments

Comments
 (0)