trendmicro / terraform-provider-conformity

Conformity Terraform provider
https://registry.terraform.io/providers/trendmicro/conformity/latest/docs
Mozilla Public License 2.0
10 stars 12 forks source link

conformity_report_config: Cannot set risk_levels filter #24

Open jbrmg opened 2 years ago

jbrmg commented 2 years ago

Hi,

the risk_levels filter on the conformity_report_config cannot be set successfully as the Terraform provider uses type string but the backend requires an array.

Example:

resource "conformity_report_config" "test" {
  account_id = conformity_azure_account.test.id

  configuration {
    emails     = ["mymail@me.com"]
    frequency  = "* * *"
    scheduled  = true
    send_email = true
    title      = "Security Report for ${conformity_azure_account.test.name}"
    tz         = "Europe/Berlin"
  }
  filter {
    categories  = ["security"]
    risk_levels = "EXTREME"
  }
}

Error response from backend:

{"errors":[{"source":{"pointer":"/data/attributes/configuration/filter/riskLevels"},"status":422,"detail":"Configuration filter riskLevels should be array"}]}

Ideally, the Terraform provided would support array instead of string so that multiple risk_levels can be provided for any given filter.

jbrmg commented 2 years ago

Please note that this issue has not been resolved with 0.4.3 as the supposed bugfix was incomplete.

https://github.com/trendmicro/terraform-provider-conformity/blob/22dd59a1c8abd6728101530086d5496b6bc73261/conformity/resource_conformity_report_config.go#L421

needs to be changed to

payload.Data.Attributes.Configuration.Filter.RiskLevels = expandStringList(f["risk_levels"].(*schema.Set).List())

and

https://github.com/trendmicro/terraform-provider-conformity/blob/27ef21fb9203b3f2bbb5030fe1363c2ca9659628/pkg/cloudconformity/models.go#L291

needs to be changed to

RiskLevels                 []string `json:"riskLevels,omitempty"`