Skip to content

Commit

Permalink
fix(subscription): validation rule for tag values (#359)
Browse files Browse the repository at this point in the history
* Update variables.tf

* Update subscription_test.go
  • Loading branch information
luke-taylor authored Apr 16, 2024
1 parent 2b4d457 commit 192949e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions modules/subscription/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ subscription_tags = {
DESCRIPTION
default = {}
validation {
error_message = "Tag values must contain neither `<>%&\\?/` nor control characters, and must be between 0-256 characters."
error_message = "Tag values must be between 0-256 characters."
condition = alltrue(
[for _, v in var.subscription_tags : can(regex("^[^<>%&\\?/[:cntrl:]]{0,256}$", v))]
[for _, v in var.subscription_tags : can(regex("^.{0,256}$", v))]
)
}
validation {
Expand Down
4 changes: 2 additions & 2 deletions tests/subscription/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ func TestSubscriptionInvalidTagValue(t *testing.T) {

v := getMockInputVariables()
v["subscription_tags"] = map[string]any{
"illegal-value": "illegal-<-value",
"illegal-value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum mattis velit quis nisl dictum, nec aliquet velit bibendum. Sed et ante nec arcu convallis rutrum. Nulla sed velit ac quam finibus volutpat! Duis malesuada leo nec eros laoreet, vel consectetur enim eleifend. Sed at fermentum libero. Proin sodales lectus quis est volutpat, id suscipit purus eleifend. Vivamus dignissim nulla nec dui sollicitudin, quis pharetra ipsum posuere. Pellentesque eget magna sit amet metus fermentum hendrerit ut non velit. Donec accumsan eros nec nibh porttitor, non interdum elit laoreet. Nam gravida elit ac turpis tristique, a facilisis orci suscipit. Sed eget luctus velit. Integer quis nulla nec ante tempus congue vitae id sem. Nam eget felis non risus fringilla tempor. Integer aliquam facilisis aliquam&.",
}
test, err := setuptest.Dirs(moduleDir, "").WithVars(v).InitPlanShowWithPrepFunc(t, utils.AzureRmAndRequiredProviders)
defer test.Cleanup()
assert.Contains(t, utils.SanitiseErrorMessage(err), "Tag values must contain neither `<>%&\\?/` nor control characters, and must be between 0-256 characters.")
assert.Contains(t, utils.SanitiseErrorMessage(err), "Tag values must be between 0-256 characters.")
}

func TestSubscriptionInvalidTagName(t *testing.T) {
Expand Down

0 comments on commit 192949e

Please sign in to comment.