Skip to content
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

CosmosDB: fixing the validation on the name field #263

Merged
merged 2 commits into from
Aug 22, 2017

Conversation

tombuildsstuff
Copy link
Contributor

Following on from #262 - this fixes the validation to ensure upper-case characters are rejected in the plan phase rather than the apply phase.

@@ -398,7 +398,7 @@ func resourceAzureRMCosmosDBAccountFailoverPolicyHash(v interface{}) int {
func validateAzureRmCosmosDBAccountName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)

r, _ := regexp.Compile("[a-z0-9-]")
r, _ := regexp.Compile("^([a-z0-9\\-]+)$")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can believe the escaping & quantifier (+) is necessary, but are the control characters like brackets & ^ & $ too?
I mean, it applies to the whole string anyway and you don't need to capture anything via subgroup here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running the tests it looks like we can remove the brackets but not the ^&$ - updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently I have still a lot to learn about regular expressions! 😅

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression does no harm and does what it's supposed to do, so LGTM, but can be less verbose, IMO.

@tombuildsstuff
Copy link
Contributor Author

Tests pass:

$ acctests azurerm TestAccAzureRMCosmosDBAccountName_validation
=== RUN   TestAccAzureRMCosmosDBAccountName_validation
--- PASS: TestAccAzureRMCosmosDBAccountName_validation (0.00s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	0.017s

@tombuildsstuff tombuildsstuff merged commit 4a6f115 into master Aug 22, 2017
@tombuildsstuff tombuildsstuff deleted the cosmosdb-name branch August 22, 2017 17:14
tombuildsstuff added a commit that referenced this pull request Aug 22, 2017
@ghost
Copy link

ghost commented Apr 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants