-
Notifications
You must be signed in to change notification settings - Fork 5k
cognitive_account_rai_blocklist_resource - support tags property and add validation for name property
#31871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
4639bbb
f68138f
5d7044f
26bf37a
207637f
3b64e83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Copyright IBM Corp. 2014, 2026 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package validate | ||
|
|
||
| import ( | ||
| "regexp" | ||
|
|
||
| "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" | ||
| ) | ||
|
|
||
| func RaiBlocklistName() pluginsdk.SchemaValidateFunc { | ||
| return validation.StringMatch( | ||
| regexp.MustCompile("^[a-zA-Z0-9_-]{2,64}$"), | ||
| "The RAI Blocklist Name must be between 2 and 64 characters long, contain only alphanumeric characters, hyphens(-) or underscores(_).", | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Copyright IBM Corp. 2014, 2026 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package validate | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestValidateCognitiveServicesRaiBlocklistName(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| input string | ||
| valid bool | ||
| }{ | ||
| { | ||
| name: "empty name", | ||
| input: "", | ||
| valid: false, | ||
| }, | ||
| { | ||
| name: "Invalid single character", | ||
| input: "a", | ||
| valid: false, | ||
| }, | ||
| { | ||
| name: "Valid two characters", | ||
| input: "ab", | ||
| valid: true, | ||
| }, | ||
| { | ||
| name: "Valid alphanumeric", | ||
| input: "hello1", | ||
| valid: true, | ||
| }, | ||
| { | ||
| name: "Valid contains underscore", | ||
| input: "hello_world", | ||
| valid: true, | ||
| }, | ||
| { | ||
| name: "Valid contains hyphen", | ||
| input: "hello-world", | ||
| valid: true, | ||
| }, | ||
| { | ||
| name: "Valid starts with digit", | ||
| input: "1hello", | ||
| valid: true, | ||
| }, | ||
| { | ||
| name: "Valid starts with underscore", | ||
| input: "_hello", | ||
| valid: true, | ||
| }, | ||
| { | ||
| name: "Valid starts with hyphen", | ||
| input: "-hello", | ||
| valid: true, | ||
| }, | ||
| { | ||
| name: "Valid ends with underscore", | ||
| input: "hello_", | ||
| valid: true, | ||
| }, | ||
| { | ||
| name: "Valid ends with hyphen", | ||
| input: "hello-", | ||
| valid: true, | ||
| }, | ||
| { | ||
| name: "Invalid contains period", | ||
| input: "a.bc", | ||
| valid: false, | ||
| }, | ||
| { | ||
| name: "Invalid contains whitespace", | ||
| input: "a bc", | ||
| valid: false, | ||
| }, | ||
| { | ||
| name: "Invalid contains special character", | ||
| input: "a@bc", | ||
| valid: false, | ||
| }, | ||
| { | ||
| name: "contains slash", | ||
| input: "a/bc", | ||
| valid: false, | ||
| }, | ||
| { | ||
| name: "Valid 64 characters", | ||
| input: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789012", | ||
| valid: true, | ||
| }, | ||
| { | ||
| name: "Invalid starts with period", | ||
| input: ".heyo", | ||
| valid: false, | ||
| }, | ||
| { | ||
| name: "Invalid 65 characters", | ||
| input: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890123", | ||
| valid: false, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| _, err := RaiBlocklistName()(tt.input, "") | ||
| valid := err == nil | ||
| if valid != tt.valid { | ||
| t.Errorf("Expected valid status %t but got %t for input %s", tt.valid, valid, tt.input) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 👍, thank you for adding unit tests |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,12 @@ subcategory: "Cognitive Services" | |
| layout: "azurerm" | ||
| page_title: "Azure Resource Manager: azurerm_cognitive_account_rai_blocklist" | ||
| description: |- | ||
| Manages a Cognitive Account Rai Blocklist. | ||
| Manages a Microsoft Foundry "Guardrails + Controls" blocklist. Microsoft Foundry was previously known as "Cognitive Account". | ||
| --- | ||
|
|
||
| # azurerm_cognitive_account_rai_blocklist | ||
|
|
||
| Manages a Cognitive Account Rai Blocklist. | ||
| Manages a Microsoft Foundry "Guardrails + Controls" blocklist. Microsoft Foundry was previously known as "Cognitive Account". | ||
|
|
||
| ## Example Usage | ||
|
|
||
|
|
@@ -41,6 +41,8 @@ The following arguments are supported: | |
|
|
||
| * `cognitive_account_id` - (Required) The ID of the Cognitive Services Account. Changing this forces a new Cognitive Account Rai Blocklist to be created. | ||
|
|
||
| * `tags` - (Optional) A mapping of tags assigned to the resource. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit of scope creep, but I was struggling to correlate "Guardrail + Controls" -> blocklist in portal to this resource. Perhaps you can improve this docs a bit to help our customers.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is fixed |
||
|
|
||
| --- | ||
|
|
||
| * `description` - (Optional) A short description for the Cognitive Account Rai Blocklist. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapping this in a
!= nilif block is not necessary. Ifmodel.Tagsis nil (zero value for map),pointer.Towill still return a pointer to this zero value and subsequent JSON serialisation logic will handle this just fine.Do a codebase search for
Tags.*pointer\.Toand observe how we never wrap such code in this kind of if block.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed