IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
336 stars 645 forks source link

Documented Regex appears to be incorrect #5379

Closed Marvin-Kalchschmidt closed 1 month ago

Marvin-Kalchschmidt commented 1 month ago

Community Note

New or Affected Resource(s) or Datasource(s)

Description

I'm currently using the ibm_sm_arbitrary_secretresource and according to the documentation the nameattribute uses the following regex: ^[A-Za-z0-9][A-Za-z0-9]*(?:_*-*\\.*[A-Za-z0-9]+)*$ . I created a variable with a validation block that checks exactly that regular expression, but it appears that naming my secret something like "github-pat" is not possible bc of the hyphen "-". When removing the validation, the code executes without a problem, even when the namedoes not match the stated regex. It appears, that the regex in the documentation is not correct.

variable "secrets_list" {
  description = "List of all secrets that should be added to the secrets manager"
  sensitive   = true
  type = list(
    object({
      name            = string
      payload         = string
      description     = optional(string)
      secret_group_id = optional(string)
  }))

  validation {
    error_message = "All secret attributes must match their respective regular expressions documented here: https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_arbitrary_secret"
    condition = alltrue([
     for secret in var.secrets_list : (can(regex("^[A-Za-z0-9][A-Za-z0-9]*(?:_*-*\\.*[A-Za-z0-9]+)*$", secret.name)) && can(regex("(.*?)", secret.payload)))
    ])
  }
}

When checking the regex with the same name provided in this example, the regex fails with no match found:

image

I'm wondering what the correct regex actually looks like and appreciate any help you can provide.

References

IdanAdar commented 1 month ago

Will be fixed as part of https://github.com/IBM-Cloud/terraform-provider-ibm/pull/5374

IdanAdar commented 1 month ago

Included in the next release.