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

azurerm_api_management_api path validation restricts single character strings #26921

Closed
1 task done
Lakshan-Banneheke opened this issue Aug 3, 2024 · 4 comments · Fixed by #26922
Closed
1 task done

Comments

@Lakshan-Banneheke
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

Terraform Version

0.14.10

AzureRM Provider Version

3.114.0

Affected Resource(s)/Data Source(s)

azurerm_api_management_api

Terraform Configuration Files

resource "azurerm_api_management_api" "api_management_api" {
  name                  = "test-api"
  api_management_name   = "test-apim"
  resource_group_name   = "rg1"
  revision              = "1"
  api_type              = "http"
  display_name          = "Test API"
  path                  = "a"
  protocols             = ["https"]
  service_url           = "https://sample-backend"
  subscription_required = "false"
}

Debug Output/Panic Output

Error: "path" may only be up to 400 characters in length, not start or end with `/` and only contain valid url characters

Expected Behaviour

A path with a single character should be allowed as it is possible to create such an API from the Azure Portal.

The errors is coming from the validate method. The regex is incorrect and should be updated to allow a single character.

Actual Behaviour

Got the error message stating the path variable is not valid.

Steps to Reproduce

terraform apply for a resource as described in the Terraform Configuration Files section of the issue

Important Factoids

No response

References

No response

@Lakshan-Banneheke
Copy link
Contributor Author

Lakshan-Banneheke commented Aug 3, 2024

I will submit the PR to update the regex to allow single character strings for the path variable.

@Lakshan-Banneheke
Copy link
Contributor Author

Lakshan-Banneheke commented Aug 3, 2024

Analysis

Assume I want to use the string "a" for the Path variable.

The existing regex is at https://github.com/hashicorp/terraform-provider-azurerm/blob/main/internal/services/apimanagement/validate/api_management.go#L79 which is ^(?:|[\w.][\w-/.:]{0,398}[\w-])$

To match the string "a", it must:

  • Match [\w.] for the first character.
  • Optionally match [\w-/.:]{0,398} for 0 characters (since "a" has only one character).
  • Match [\w-] for the last character.

Given the existing regex, the string "a" would not match because it requires at least two characters in the non-empty case (one for [\w.] and one for [\w-]).

@Lakshan-Banneheke
Copy link
Contributor Author

Lakshan-Banneheke commented Aug 3, 2024

The regex should be modified to have the section [\w]|. This will allow a single alphanumeric character.

Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants