-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathdata_source_sysdig_secure_posture_zone_test.go
More file actions
77 lines (67 loc) · 2.35 KB
/
data_source_sysdig_secure_posture_zone_test.go
File metadata and controls
77 lines (67 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//go:build tf_acc_sysdig_secure || tf_acc_ibm_secure || tf_acc_onprem_secure
package sysdig_test
import (
"fmt"
"github.com/draios/terraform-provider-sysdig/sysdig"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func TestAccDataSourceSysdigSecurePostureZones(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: preCheckAnyEnv(t, SysdigSecureApiTokenEnv, SysdigIBMSecureAPIKeyEnv),
ProviderFactories: map[string]func() (*schema.Provider, error){
"sysdig": func() (*schema.Provider, error) {
return sysdig.Provider(), nil
},
},
Steps: []resource.TestStep{
{
Config: testAccDataSourceSysdigSecurePostureZonesWithMultipleResourcesConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckDataSourceSysdigSecurePostureZonesExists("data.sysdig_secure_posture_zone.test_posture_zone"),
resource.TestCheckResourceAttr("data.sysdig_secure_posture_zone.test_posture_zone", "name", "test-zone-1"),
resource.TestCheckResourceAttr("data.sysdig_secure_posture_zone.test_posture_zone", "description", "Test description 1"),
resource.TestCheckTypeSetElemNestedAttrs(
"data.sysdig_secure_posture_zone.test_posture_zone",
"scopes.*",
map[string]string{
"target_type": "aws",
"rules": "organization in (\"o1\", \"o2\") and account in (\"a1\", \"a2\")",
},
),
),
},
},
})
}
func testAccDataSourceSysdigSecurePostureZonesWithMultipleResourcesConfig() string {
return `
resource "sysdig_secure_posture_zone" "test_posture_zone" {
name = "test-zone-1"
description = "Test description 1"
scopes {
scope {
target_type = "aws"
rules = "organization in (\"o1\", \"o2\") and account in (\"a1\", \"a2\")"
}
}
}
data "sysdig_secure_posture_zone" "test_posture_zone" {
id = sysdig_secure_posture_zone.test_posture_zone.id
}
`
}
func testAccCheckDataSourceSysdigSecurePostureZonesExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("not found: %s", resourceName)
}
if rs.Primary.ID == "" {
return fmt.Errorf("no ID is set")
}
return nil
}
}