diff --git a/sysdig/resource_sysdig_ip_filter_test.go b/sysdig/resource_sysdig_ip_filter_test.go index 2acec57db..86146e72e 100644 --- a/sysdig/resource_sysdig_ip_filter_test.go +++ b/sysdig/resource_sysdig_ip_filter_test.go @@ -4,14 +4,19 @@ package sysdig_test import ( "fmt" - "github.com/draios/terraform-provider-sysdig/sysdig" "testing" + "github.com/draios/terraform-provider-sysdig/sysdig" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) { + ipRange1 := generateRandomIPRange() + ipRange2 := generateRandomIPRange() + resource.Test(t, resource.TestCase{ PreCheck: preCheckAnyEnv(t, SysdigMonitorApiTokenEnv), ProviderFactories: map[string]func() (*schema.Provider, error){ @@ -21,19 +26,19 @@ func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) { }, Steps: []resource.TestStep{ { - // Create resource - Config: createIPFilter("192.168.1.0/24", "Initial note", true), + // Create resource with the first random IP range + Config: createIPFilter(ipRange1, "Initial note", true), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", "192.168.1.0/24"), + resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", ipRange1), resource.TestCheckResourceAttr("sysdig_ip_filter.test", "note", "Initial note"), resource.TestCheckResourceAttr("sysdig_ip_filter.test", "enabled", "true"), ), }, { - // Update resource - Config: createIPFilter("192.168.2.0/24", "Updated note", false), + // Update resource with the second random IP range + Config: createIPFilter(ipRange2, "Updated note", false), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", "192.168.2.0/24"), + resource.TestCheckResourceAttr("sysdig_ip_filter.test", "ip_range", ipRange2), resource.TestCheckResourceAttr("sysdig_ip_filter.test", "note", "Updated note"), resource.TestCheckResourceAttr("sysdig_ip_filter.test", "enabled", "false"), ), @@ -42,6 +47,10 @@ func TestAccSysdigIpFilter_fullLifecycle(t *testing.T) { }) } +func generateRandomIPRange() string { + return fmt.Sprintf("%d.%d.%d.0/24", acctest.RandIntRange(0, 255), acctest.RandIntRange(0, 255), acctest.RandIntRange(0, 255)) +} + func createIPFilter(ipRange, note string, enabled bool) string { return fmt.Sprintf(` resource "sysdig_ip_filter" "test" {