Skip to content

Commit 4d9d8b5

Browse files
authored
fix(tests): Skip onprem unsupported policy types (#510)
* Do not run cloud policy types tests with `tf_acc_onprem_secure` tag * Use TypeSet instead of TypeList for rules
1 parent c3ad264 commit 4d9d8b5

6 files changed

+95
-96
lines changed

sysdig/data_source_sysdig_secure_aws_ml_policy_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws || tf_acc_onprem_secure
1+
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws
22

33
package sysdig_test
44

sysdig/data_source_sysdig_secure_trusted_cloud_identity_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build tf_acc_sysdig_secure || tf_acc_onprem_secure
1+
//go:build tf_acc_sysdig_secure
22

33
package sysdig_test
44

sysdig/resource_sysdig_secure_aws_ml_policy_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws || tf_acc_onprem_secure
1+
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws
22

33
package sysdig_test
44

sysdig/resource_sysdig_secure_custom_policy.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package sysdig
33
import (
44
"context"
55
"errors"
6-
"fmt"
76
"net/http"
87
"strconv"
98
"time"
@@ -51,7 +50,7 @@ func resourceSysdigSecureCustomPolicy() *schema.Resource {
5150
ValidateDiagFunc: validateDiagFunc(validation.IntBetween(0, 7)),
5251
},
5352
"rules": {
54-
Type: schema.TypeList,
53+
Type: schema.TypeSet,
5554
Optional: true,
5655
Elem: &schema.Resource{
5756
Schema: map[string]*schema.Schema{
@@ -100,11 +99,11 @@ func customPolicyFromResourceData(d *schema.ResourceData) v2.Policy {
10099

101100
policy.Rules = []*v2.PolicyRule{}
102101

103-
rules := d.Get("rules").([]interface{})
104-
for index := range rules {
102+
for _, ruleItr := range d.Get("rules").(*schema.Set).List() {
103+
ruleInfo := ruleItr.(map[string]interface{})
105104
rule := &v2.PolicyRule{
106-
Name: d.Get(fmt.Sprintf("rules.%d.name", index)).(string),
107-
Enabled: d.Get(fmt.Sprintf("rules.%d.enabled", index)).(bool),
105+
Name: ruleInfo["name"].(string),
106+
Enabled: ruleInfo["enabled"].(bool),
108107
}
109108
policy.Rules = append(policy.Rules, rule)
110109
}
@@ -147,13 +146,14 @@ func customPolicyToResourceData(policy *v2.Policy, d *schema.ResourceData) {
147146
}
148147

149148
func getPolicyRulesFromResourceData(d *schema.ResourceData) []*v2.PolicyRule {
150-
rules := d.Get("rules").([]interface{})
149+
rules := d.Get("rules").(*schema.Set).List()
151150
policyRules := make([]*v2.PolicyRule, len(rules))
152151

153-
for i, rule := range rules {
152+
for i, ruleItr := range rules {
153+
ruleInfo := ruleItr.(map[string]interface{})
154154
policyRules[i] = &v2.PolicyRule{
155-
Name: rule.(map[string]interface{})["name"].(string),
156-
Enabled: rule.(map[string]interface{})["enabled"].(bool),
155+
Name: ruleInfo["name"].(string),
156+
Enabled: ruleInfo["enabled"].(bool),
157157
}
158158
}
159159

sysdig/resource_sysdig_secure_custom_policy_test.go

+43-40
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,62 @@ import (
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1212

13+
"github.com/draios/terraform-provider-sysdig/buildinfo"
1314
"github.com/draios/terraform-provider-sysdig/sysdig"
1415
)
1516

1617
func TestAccCustomPolicy(t *testing.T) {
1718
rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) }
1819
policy1 := rText()
20+
21+
steps := []resource.TestStep{
22+
{
23+
Config: customPolicyWithName(policy1),
24+
},
25+
{
26+
ResourceName: "sysdig_secure_custom_policy.sample",
27+
ImportState: true,
28+
ImportStateVerify: true,
29+
},
30+
{
31+
Config: customPolicyWithRulesOrderChange(policy1),
32+
},
33+
{
34+
Config: customPolicyWithoutActions(rText()),
35+
},
36+
{
37+
Config: customPolicyWithoutNotificationChannels(rText()),
38+
},
39+
{
40+
Config: customPolicyWithMinimumConfiguration(rText()),
41+
},
42+
{
43+
Config: customPoliciesWithDifferentSeverities(rText()),
44+
},
45+
{
46+
Config: customPoliciesWithKillAction(rText()),
47+
},
48+
{
49+
Config: customPoliciesWithDisabledRules(rText()),
50+
},
51+
}
52+
53+
if !buildinfo.OnpremSecure {
54+
steps = append(steps,
55+
resource.TestStep{Config: customPoliciesForAWSCloudtrail(rText())},
56+
resource.TestStep{Config: customPoliciesForGCPAuditLog(rText())},
57+
resource.TestStep{Config: customPoliciesForAzurePlatformlogs(rText())},
58+
)
59+
}
60+
1961
resource.ParallelTest(t, resource.TestCase{
2062
PreCheck: preCheckAnyEnv(t, SysdigSecureApiTokenEnv),
2163
ProviderFactories: map[string]func() (*schema.Provider, error){
2264
"sysdig": func() (*schema.Provider, error) {
2365
return sysdig.Provider(), nil
2466
},
2567
},
26-
Steps: []resource.TestStep{
27-
{
28-
Config: customPolicyWithName(policy1),
29-
},
30-
{
31-
ResourceName: "sysdig_secure_custom_policy.sample",
32-
ImportState: true,
33-
ImportStateVerify: true,
34-
},
35-
{
36-
Config: customPolicyWithRulesOrderChange(policy1),
37-
},
38-
{
39-
Config: customPolicyWithoutActions(rText()),
40-
},
41-
{
42-
Config: customPolicyWithoutNotificationChannels(rText()),
43-
},
44-
{
45-
Config: customPolicyWithMinimumConfiguration(rText()),
46-
},
47-
{
48-
Config: customPoliciesWithDifferentSeverities(rText()),
49-
},
50-
{
51-
Config: customPoliciesWithKillAction(rText()),
52-
},
53-
{
54-
Config: customPoliciesForAWSCloudtrail(rText()),
55-
},
56-
{
57-
Config: customPoliciesForGCPAuditLog(rText()),
58-
},
59-
{
60-
Config: customPoliciesForAzurePlatformlogs(rText()),
61-
},
62-
{
63-
Config: customPoliciesWithDisabledRules(rText()),
64-
},
65-
},
68+
Steps: steps,
6669
})
6770
}
6871

sysdig/resource_sysdig_secure_policy_test.go

+39-43
Original file line numberDiff line numberDiff line change
@@ -10,62 +10,58 @@ import (
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1212

13+
"github.com/draios/terraform-provider-sysdig/buildinfo"
1314
"github.com/draios/terraform-provider-sysdig/sysdig"
1415
)
1516

1617
func TestAccPolicy(t *testing.T) {
1718
rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) }
1819

20+
steps := []resource.TestStep{
21+
{
22+
Config: policyWithName(rText()),
23+
},
24+
{
25+
ResourceName: "sysdig_secure_policy.sample",
26+
ImportState: true,
27+
ImportStateVerify: true,
28+
},
29+
{
30+
Config: policyWithoutActions(rText()),
31+
},
32+
{
33+
Config: policyWithoutNotificationChannels(rText()),
34+
},
35+
{
36+
Config: policyWithMinimumConfiguration(rText()),
37+
},
38+
{
39+
Config: policiesWithDifferentSeverities(rText()),
40+
},
41+
{
42+
Config: policiesWithKillAction(rText()),
43+
},
44+
}
45+
46+
if !buildinfo.OnpremSecure {
47+
steps = append(steps,
48+
resource.TestStep{Config: policiesForAWSCloudtrail(rText())},
49+
resource.TestStep{Config: policiesForGCPAuditLog(rText())},
50+
resource.TestStep{Config: policiesForAzurePlatformlogs(rText())},
51+
resource.TestStep{Config: policiesForFalcoCloudAWSCloudtrail(rText())},
52+
resource.TestStep{Config: policiesForOkta(rText())},
53+
resource.TestStep{Config: policiesForGithub(rText())},
54+
)
55+
}
56+
1957
resource.ParallelTest(t, resource.TestCase{
2058
PreCheck: preCheckAnyEnv(t, SysdigSecureApiTokenEnv),
2159
ProviderFactories: map[string]func() (*schema.Provider, error){
2260
"sysdig": func() (*schema.Provider, error) {
2361
return sysdig.Provider(), nil
2462
},
2563
},
26-
Steps: []resource.TestStep{
27-
{
28-
Config: policyWithName(rText()),
29-
},
30-
{
31-
ResourceName: "sysdig_secure_policy.sample",
32-
ImportState: true,
33-
ImportStateVerify: true,
34-
},
35-
{
36-
Config: policyWithoutActions(rText()),
37-
},
38-
{
39-
Config: policyWithoutNotificationChannels(rText()),
40-
},
41-
{
42-
Config: policyWithMinimumConfiguration(rText()),
43-
},
44-
{
45-
Config: policiesWithDifferentSeverities(rText()),
46-
},
47-
{
48-
Config: policiesWithKillAction(rText()),
49-
},
50-
{
51-
Config: policiesForAWSCloudtrail(rText()),
52-
},
53-
{
54-
Config: policiesForGCPAuditLog(rText()),
55-
},
56-
{
57-
Config: policiesForAzurePlatformlogs(rText()),
58-
},
59-
{
60-
Config: policiesForFalcoCloudAWSCloudtrail(rText()),
61-
},
62-
{
63-
Config: policiesForOkta(rText()),
64-
},
65-
{
66-
Config: policiesForGithub(rText()),
67-
},
68-
},
64+
Steps: steps,
6965
})
7066
}
7167

0 commit comments

Comments
 (0)