Skip to content

Plan does not complain if xray_security_policy has multiple rules with duplicate priorities #348

@deiga

Description

@deiga

Describe the bug
I created a new xray_security_policy with generated rules, but didn't know I had to set separate priority for each. terraform plan passed nicely, so we merged the changes. But when we tried to apply the changes we get this error:

╷
│ Error: Unable to Create Resource
│ 
│   with module.xray.xray_security_policy.security_policy["2025-09-npm-supply-chain-attack"],
│   on ../../modules/xray/security_policies.tf line 33, in resource "xray_security_policy" "security_policy":
│   33: resource "xray_security_policy" "security_policy" {
│ 
│ An unexpected error occurred while creating the resource update request.
│ Please report this issue to the provider developers.
│ 
│ Error: Found Invalid Policy: rule block-ansi-styles-6.2.2 priority 1 is
│ duplicated
╵

Requirements for and issue

  • A fully functioning terraform snippet that can be copy&pasted (no outside files or ENV vars unless that's part of the issue)
locals {
  policies = [
    {
      name = "2025-09-npm-supply-chain-attack"
      description = "Large scale supply chain attack on NPM packages. https://arstechnica.com/security/2025/09/software-packages-with-more-than-2-billion-weekly-downloads-hit-in-supply-chain-attack/"
      rules = {
        blocked_packages = {
        backslash           = "0.2.1"
        chalk               = "5.6.1"
        chalk-template      = "1.1.1"
        color-convert       = "3.1.1"
        color-name          = "2.0.1"
        color-string        = "2.1.1"
        wrap-ansi           = "9.0.1"
        supports-hyperlinks = "4.1.1"
        strip-ansi          = "7.1.1"
        slice-ansi          = "7.1.1"
        simple-swizzle      = "0.2.3"
        is-arrayish         = "0.3.3"
        error-ex            = "1.3.3"
        has-ansi            = "6.0.1"
        ansi-regex          = "6.2.1"
        ansi-styles         = "6.2.2"
        supports-color      = "10.2.1"
        proto-tinker-wc     = "1.8.7"
        debug               = "4.4.2"
      }
      }
    }
  ]
}

resource "xray_security_policy" "security_policy" {
  for_each = { for policy in local.policies : policy.name => policy }
  name        = each.value.name
  description = each.value.description
  type        = "security"

  dynamic "rule" {
    for_each = {for package, version in each.value.rules.blocked_packages : package => version}
    content {
      name     = "block-${rule.key}-${rule.value}"
      priority = 1
      criteria {
        package_name = rule.key
        package_type = "Npm"
        package_versions = [ "[${rule.value}]" ]
      }
      actions {
        block_download {
          active = true
          unscanned = true
        }
        block_release_bundle_distribution = true
        block_release_bundle_promotion = true
        fail_build = true
        notify_watch_recipients = true
        notify_deployer = true
      }
    }
  }
}
  • Your version of Artifactory (7.104.5) and Xray (3.107.30)
  • Your version of terraform: 1.13.1
  • Your version of terraform provider: 3.1.0
  • Your product license E+
  • Is your Xray Cloud or Self-Hosted: Self-Hosted

Expected behavior
I would expect that terraform plan (or I guess it's the validate part of plan) would throw an error that priority needs to be unique among all the rules of a policy

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions