Skip to content

fix(tests): Skip onprem unsupported policy types #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sysdig/data_source_sysdig_secure_aws_ml_policy_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws || tf_acc_onprem_secure
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws

package sysdig_test

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tf_acc_sysdig_secure || tf_acc_onprem_secure
//go:build tf_acc_sysdig_secure

package sysdig_test

Expand Down
2 changes: 1 addition & 1 deletion sysdig/resource_sysdig_secure_aws_ml_policy_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws || tf_acc_onprem_secure
//go:build tf_acc_sysdig_secure || tf_acc_policies_aws

package sysdig_test

Expand Down
20 changes: 10 additions & 10 deletions sysdig/resource_sysdig_secure_custom_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sysdig
import (
"context"
"errors"
"fmt"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -51,7 +50,7 @@ func resourceSysdigSecureCustomPolicy() *schema.Resource {
ValidateDiagFunc: validateDiagFunc(validation.IntBetween(0, 7)),
},
"rules": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -100,11 +99,11 @@ func customPolicyFromResourceData(d *schema.ResourceData) v2.Policy {

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

rules := d.Get("rules").([]interface{})
for index := range rules {
for _, ruleItr := range d.Get("rules").(*schema.Set).List() {
ruleInfo := ruleItr.(map[string]interface{})
rule := &v2.PolicyRule{
Name: d.Get(fmt.Sprintf("rules.%d.name", index)).(string),
Enabled: d.Get(fmt.Sprintf("rules.%d.enabled", index)).(bool),
Name: ruleInfo["name"].(string),
Enabled: ruleInfo["enabled"].(bool),
}
policy.Rules = append(policy.Rules, rule)
}
Expand Down Expand Up @@ -147,13 +146,14 @@ func customPolicyToResourceData(policy *v2.Policy, d *schema.ResourceData) {
}

func getPolicyRulesFromResourceData(d *schema.ResourceData) []*v2.PolicyRule {
rules := d.Get("rules").([]interface{})
rules := d.Get("rules").(*schema.Set).List()
policyRules := make([]*v2.PolicyRule, len(rules))

for i, rule := range rules {
for i, ruleItr := range rules {
ruleInfo := ruleItr.(map[string]interface{})
policyRules[i] = &v2.PolicyRule{
Name: rule.(map[string]interface{})["name"].(string),
Enabled: rule.(map[string]interface{})["enabled"].(bool),
Name: ruleInfo["name"].(string),
Enabled: ruleInfo["enabled"].(bool),
}
}

Expand Down
83 changes: 43 additions & 40 deletions sysdig/resource_sysdig_secure_custom_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,62 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/draios/terraform-provider-sysdig/buildinfo"
"github.com/draios/terraform-provider-sysdig/sysdig"
)

func TestAccCustomPolicy(t *testing.T) {
rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) }
policy1 := rText()

steps := []resource.TestStep{
{
Config: customPolicyWithName(policy1),
},
{
ResourceName: "sysdig_secure_custom_policy.sample",
ImportState: true,
ImportStateVerify: true,
},
{
Config: customPolicyWithRulesOrderChange(policy1),
},
{
Config: customPolicyWithoutActions(rText()),
},
{
Config: customPolicyWithoutNotificationChannels(rText()),
},
{
Config: customPolicyWithMinimumConfiguration(rText()),
},
{
Config: customPoliciesWithDifferentSeverities(rText()),
},
{
Config: customPoliciesWithKillAction(rText()),
},
{
Config: customPoliciesWithDisabledRules(rText()),
},
}

if !buildinfo.OnpremSecure {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this method. I was thinking we would have to separate out these steps into new file. Great job

steps = append(steps,
resource.TestStep{Config: customPoliciesForAWSCloudtrail(rText())},
resource.TestStep{Config: customPoliciesForGCPAuditLog(rText())},
resource.TestStep{Config: customPoliciesForAzurePlatformlogs(rText())},
)
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: preCheckAnyEnv(t, SysdigSecureApiTokenEnv),
ProviderFactories: map[string]func() (*schema.Provider, error){
"sysdig": func() (*schema.Provider, error) {
return sysdig.Provider(), nil
},
},
Steps: []resource.TestStep{
{
Config: customPolicyWithName(policy1),
},
{
ResourceName: "sysdig_secure_custom_policy.sample",
ImportState: true,
ImportStateVerify: true,
},
{
Config: customPolicyWithRulesOrderChange(policy1),
},
{
Config: customPolicyWithoutActions(rText()),
},
{
Config: customPolicyWithoutNotificationChannels(rText()),
},
{
Config: customPolicyWithMinimumConfiguration(rText()),
},
{
Config: customPoliciesWithDifferentSeverities(rText()),
},
{
Config: customPoliciesWithKillAction(rText()),
},
{
Config: customPoliciesForAWSCloudtrail(rText()),
},
{
Config: customPoliciesForGCPAuditLog(rText()),
},
{
Config: customPoliciesForAzurePlatformlogs(rText()),
},
{
Config: customPoliciesWithDisabledRules(rText()),
},
},
Steps: steps,
})
}

Expand Down
82 changes: 39 additions & 43 deletions sysdig/resource_sysdig_secure_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,58 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/draios/terraform-provider-sysdig/buildinfo"
"github.com/draios/terraform-provider-sysdig/sysdig"
)

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

steps := []resource.TestStep{
{
Config: policyWithName(rText()),
},
{
ResourceName: "sysdig_secure_policy.sample",
ImportState: true,
ImportStateVerify: true,
},
{
Config: policyWithoutActions(rText()),
},
{
Config: policyWithoutNotificationChannels(rText()),
},
{
Config: policyWithMinimumConfiguration(rText()),
},
{
Config: policiesWithDifferentSeverities(rText()),
},
{
Config: policiesWithKillAction(rText()),
},
}

if !buildinfo.OnpremSecure {
steps = append(steps,
resource.TestStep{Config: policiesForAWSCloudtrail(rText())},
resource.TestStep{Config: policiesForGCPAuditLog(rText())},
resource.TestStep{Config: policiesForAzurePlatformlogs(rText())},
resource.TestStep{Config: policiesForFalcoCloudAWSCloudtrail(rText())},
resource.TestStep{Config: policiesForOkta(rText())},
resource.TestStep{Config: policiesForGithub(rText())},
)
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: preCheckAnyEnv(t, SysdigSecureApiTokenEnv),
ProviderFactories: map[string]func() (*schema.Provider, error){
"sysdig": func() (*schema.Provider, error) {
return sysdig.Provider(), nil
},
},
Steps: []resource.TestStep{
{
Config: policyWithName(rText()),
},
{
ResourceName: "sysdig_secure_policy.sample",
ImportState: true,
ImportStateVerify: true,
},
{
Config: policyWithoutActions(rText()),
},
{
Config: policyWithoutNotificationChannels(rText()),
},
{
Config: policyWithMinimumConfiguration(rText()),
},
{
Config: policiesWithDifferentSeverities(rText()),
},
{
Config: policiesWithKillAction(rText()),
},
{
Config: policiesForAWSCloudtrail(rText()),
},
{
Config: policiesForGCPAuditLog(rText()),
},
{
Config: policiesForAzurePlatformlogs(rText()),
},
{
Config: policiesForFalcoCloudAWSCloudtrail(rText()),
},
{
Config: policiesForOkta(rText()),
},
{
Config: policiesForGithub(rText()),
},
},
Steps: steps,
})
}

Expand Down
Loading