Skip to content

Commit

Permalink
Provider Crashes Resolved and Schema Changes (#55)
Browse files Browse the repository at this point in the history
* Provider Crashes Resolved and Schema Changes

* fixes syntax issue

* fixes syntax issue

* bug fixes

* test case fixes

Co-authored-by: Pulkit <[email protected]>
  • Loading branch information
AmitChotaliya and pulkitshunyeka authored Dec 19, 2022
1 parent c6413ae commit bdee0b7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
14 changes: 7 additions & 7 deletions conformity/account_settings.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package conformity

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/trendmicro/terraform-provider-conformity/pkg/cloudconformity"
"reflect"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func flattenAccountSettings(settings *cloudconformity.AccountSettings, rule []cloudconformity.GetRuleSettings) []interface{} {
Expand Down Expand Up @@ -96,9 +96,9 @@ func flattenExceptions(exceptions *cloudconformity.RuleSettingExceptions) []inte
c["filter_tags"] = exceptions.FilterTags

c["resources"] = exceptions.Resources
if len(exceptions.Tags) == 0{
if len(exceptions.Tags) == 0 {
c["tags"] = nil
}else{
} else {
c["tags"] = exceptions.Tags
}
return []interface{}{c}
Expand Down Expand Up @@ -157,10 +157,10 @@ func flattenRuleValues(values []interface{}) []interface{} {
if l, ok := item["label"].(string); ok && l != "" {
v["label"] = l
}
if val, ok := item["value"].(string); ok && val != "" {
v["value"] = val
itemvalue := fmt.Sprintf("%s", item["value"])
if itemvalue != "" {
v["value"] = string((itemvalue))
}

if enabled, ok := item["enabled"]; ok && enabled != nil {
v["enabled"] = item["enabled"].(bool)

Expand Down
18 changes: 12 additions & 6 deletions conformity/resource_conformity_report_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func resourceConformityReportConfig() *schema.Resource {
Default: "GENERIC",
ValidateFunc: validation.StringInSlice([]string{"GENERIC", "COMPLIANCE-STANDARD"}, false),
},
"include_account_names": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"include_checks": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -122,16 +127,17 @@ func resourceConformityReportConfig() *schema.Resource {
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"security", "cost-optimisation", "reliability", "performance-efficiency",
"operational-excellence"}, false),
"operational-excellence", "sustainability"}, false),
},
},
"compliance_standards": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"AWAF", "CISAWSF", "CISAZUREF", "PCI", "HIPAA", "GDPR", "APRA", "NIST4", "SOC2",
"NIST-CSF", "ISO27001", "AGISM", "ASAE-3150", "MAS", "FEDRAMP"}, false),

ValidateFunc: validation.StringInSlice([]string{"AWAF", "CISAWSF", "CISAWSF-1_3_0", "CISAWSF-1_4_0", "CISAZUREF", "CISGCPF", "CIS-V8", "PCI", "HIPAA", "GDPR", "APRA", "NIST4", "NIST5", "SOC2",
"NIST-CSF", "ISO27001", "AGISM", "ASAE-3150", "MAS", "FEDRAMP", "ENISA", "FISC-V9", "LGPD", "AZUREWAF"}, false),
},
},
"filter_tags": {
Expand Down Expand Up @@ -171,8 +177,8 @@ func resourceConformityReportConfig() *schema.Resource {
"report_compliance_standard_id": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"AWAF", "CISAWSF", "CISAZUREF", "PCI", "HIPAA", "GDPR", "APRA", "NIST4", "SOC2",
"NIST-CSF", "ISO27001", "AGISM", "ASAE-3150", "MAS", "FEDRAMP"}, false),
ValidateFunc: validation.StringInSlice([]string{"AWAF", "CISAWSF", "CISAWSF-1_3_0", "CISAWSF-1_4_0", "CISAZUREF", "CISGCPF", "CIS-V8", "PCI", "HIPAA", "GDPR", "APRA", "NIST4", "NIST5", "SOC2",
"NIST-CSF", "ISO27001", "AGISM", "ASAE-3150", "MAS", "FEDRAMP", "ENISA", "FISC-V9", "LGPD", "AZUREWAF"}, false),
},
"resource": {
Type: schema.TypeString,
Expand All @@ -193,7 +199,7 @@ func resourceConformityReportConfig() *schema.Resource {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"LOW", "MEDIUM", "HIGH", "VERY_HIGH", "EXTREME"}, false),
},
},
Expand Down
6 changes: 6 additions & 0 deletions conformity/resource_conformity_report_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type configuration struct {
Emails []string
Frequency string
GenerateReportType string
IncludeAccountName string // bool converted to string
IncludeChecks string // bool converted to string
Scheduled string // bool converted to string
SendEmail string // bool converted to string
Expand Down Expand Up @@ -77,6 +78,7 @@ func TestAccResourceconformityReportConfig(t *testing.T) {
Emails: []string{"[email protected]"},
Frequency: "* * *",
GenerateReportType: "GENERIC",
IncludeAccountName: "false",
IncludeChecks: "true",
Scheduled: "true",
SendEmail: "true",
Expand All @@ -91,6 +93,7 @@ func TestAccResourceconformityReportConfig(t *testing.T) {
UpdatedConfig.Emails = []string{"[email protected]"}
UpdatedConfig.Frequency = "*/3 * *"
UpdatedConfig.GenerateReportType = "COMPLIANCE-STANDARD"
UpdatedConfig.IncludeAccountName = "false"
UpdatedConfig.IncludeChecks = "false"
UpdatedConfig.ShouldEmailIncludeCsv = "false"
UpdatedConfig.ShouldEmailIncludePdf = "false"
Expand Down Expand Up @@ -173,6 +176,7 @@ func TestAccResourceconformityReportConfig(t *testing.T) {
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.emails.0", "[email protected]"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.frequency", "* * *"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.generate_report_type", "GENERIC"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.include_account_names", "false"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.include_checks", "true"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.scheduled", "true"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.send_email", "true"),
Expand Down Expand Up @@ -219,6 +223,7 @@ func TestAccResourceconformityReportConfig(t *testing.T) {
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.emails.0", "[email protected]"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.frequency", "*/3 * *"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.generate_report_type", "COMPLIANCE-STANDARD"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.include_account_names", "false"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.include_checks", "false"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.scheduled", "true"),
resource.TestCheckResourceAttr("conformity_report_config.report", "configuration.0.send_email", "true"),
Expand Down Expand Up @@ -323,6 +328,7 @@ func testAccCheckConformityReportConfigBasic(f filter, c configuration, groupId
emails = ["` + c.Emails[0] + `"]
` + frequency + `
generate_report_type = "` + c.GenerateReportType + `"
include_account_names="` + c.IncludeAccountName + `"
include_checks = "` + c.IncludeChecks + `"
scheduled = "` + c.Scheduled + `"
send_email = "` + c.SendEmail + `"
Expand Down
2 changes: 2 additions & 0 deletions example/report_config/template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ resource "conformity_report_config" "report" {
// optional | type: string | default: GENERIC
// value can be: "GENERIC", "COMPLIANCE-STANDARD"
generate_report_type = ""
// optional | type: bool | default: true
include_account_names=""
// optional | type: bool | default: false
include_checks = bool
// optional | type: bool | default: false
Expand Down
5 changes: 5 additions & 0 deletions pkg/cloudconformity/get_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ func (c *Client) GetAccount(accountId string) (*accountAccessAndDetails, error)
if err != nil {
return nil, err
}

accessSettings, err := c.GetAccountAccessSettings(accountId)
if err != nil {
return nil, err
}

ruleSettings, err := c.GetAccountRuleSettings(accountId)
if err != nil {
return nil, err
Expand Down Expand Up @@ -66,11 +68,13 @@ func (c *Client) GetAccountAccessSettings(accountId string) (*accountData, error
// allows you to get the details of the specified account
// return the account name and evironment
func (c *Client) GetAccountDetails(accountId string) (*accountDetails, error) {

accountDetails := &accountDetails{}
_, err := c.ClientRequest(Get{}, fmt.Sprintf("/accounts/%s", accountId), nil, "", accountDetails)
if err != nil {
return nil, err
}

return accountDetails, nil
}

Expand All @@ -81,5 +85,6 @@ func (c *Client) GetAccountRuleSettings(accountId string) (*GetAccountRuleSettin
if err != nil && !strings.Contains(err.Error(), "404") {
return nil, err
}

return ruleSettings, nil
}

0 comments on commit bdee0b7

Please sign in to comment.