jfrog / terraform-provider-xray

Terraform provider to manage JFrog Xray
https://jfrog.com/xray/
Apache License 2.0
151 stars 12 forks source link

Better validation error of custom severity #253

Closed oallauddin closed 1 month ago

oallauddin commented 1 month ago

** Example terraform

locals {
  team = "xyz"
}
resource "project" "project" {
  key          = local.team
  display_name = "${upper(local.team)} Project"
  description  = "${upper(local.team)} Project"

  admin_privileges {
    manage_members   = true
    manage_resources = true
    index_resources  = true
  }
}

resource "xray_license_policy" "license_policy" {
  name        = "${local.team}-license-policy"
  description = "${upper(local.team)} License Policy"
  type        = "license"
  project_key = local.team

  rule {
    name     = "${local.team}-license-rule"
    priority = 1

    criteria {
      allow_unknown            = false
      multi_license_permissive = true
    }

    actions {
      block_release_bundle_distribution  = false
      block_release_bundle_promotion     = false
      custom_severity                    = "medium"
      notify_watch_recipients            = false
      notify_deployer                    = false
      create_ticket_enabled              = false
      fail_build                         = true
      build_failure_grace_period_in_days = 0

      block_download {
        unscanned = false
        active    = false
      }
    }
  }
}

terraform {
  backend "local" {
    path = "terraform.tfstate"
  }
  required_providers {
    artifactory = {
      source  = "jfrog/artifactory"
      version = "11.9.2"
    }
    xray = {
      source  = "jfrog/xray"
      version = "2.11.2"
    }
    project = {
      source  = "jfrog/project"
      version = "1.8.0"
    }
  }
  required_version = ">= 1.6.2"
}

** Example error

│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to xray_license_policy.license_policy, provider "provider[\"registry.terraform.io/jfrog/xray\"]" produced an unexpected new value: .rule: planned set element
│ cty.ObjectVal(map[string]cty.Value{"actions":cty.SetVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{"block_download":cty.SetVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{"active":cty.False,
│ "unscanned":cty.False})}), "block_release_bundle_distribution":cty.False, "block_release_bundle_promotion":cty.False, "build_failure_grace_period_in_days":cty.NumberIntVal(0),
│ "create_ticket_enabled":cty.False, "custom_severity":cty.StringVal("medium"), "fail_build":cty.True, "mails":cty.NullVal(cty.Set(cty.String)), "notify_deployer":cty.False,
│ "notify_watch_recipients":cty.False, "webhooks":cty.NullVal(cty.Set(cty.String))})}), "criteria":cty.SetVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{"allow_unknown":cty.False,
│ "allowed_licenses":cty.NullVal(cty.Set(cty.String)), "banned_licenses":cty.NullVal(cty.Set(cty.String)), "multi_license_permissive":cty.True})}), "name":cty.StringVal("alp-license-rule"),
│ "priority":cty.NumberIntVal(1)}) does not correlate with any element in actual.
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Is your feature request related to a problem? Please describe. "medium" was used instead of "Medium" for custom severity in license policy. Error returned did not point out the problem.

Describe the solution you'd like Friendlier errors when validation errors are encountered.
Something like. Validation Error: "medium" is not a valid custom severity. Valid values are "Low", "Medium" or "High"
I thought the REST API would return the validation errors.
Maybe we are swallowing and not displaying them in the provider?

alexhung commented 1 month ago

@oallauddin Thanks for the report! I've added this to our plan.