Loading...
Loading...
### Terraform Version ```shell Terraform v1.4.0 // (or whatever you're using) required_version = ">= 0.14.10" ``` ### Terraform Configuration Files ```terraform data "azurerm_service_plan" "service_plan" { name = format(local.resource_name_template, "function-serviceplan") resource_group_name = local.resource_group_name } ``` ### Debug Output While validating Terraform configuration using terraform validate, I encountered the following error: ``` Error: "name" may only contain alphanumeric characters, dashes and underscores up to 60 characters in length with data.azurerm_service_plan.service_plan, on main.tf line 61, in data "azurerm_service_plan" "service_plan": 61: name = format(local.resource_name_template, "function-serviceplan") ``` The variable `local.resource_name_template` is dynamically constructed (in our case it's a valid, static string like `"svcv-pricebook-dev"`) and is well within Azure's naming restrictions (length < 60 characters, valid characters only). However, the validation fails at the static analysis phase despite the eventual value being compliant. ### Expected Behavior Terraform should not throw a hard validation error for expressions that are dynamically evaluated at apply time. Instead: - This condition could be downgraded to a warning rather than an error if the value can't be evaluated statically but is expected to be compliant. - Alternatively, a smarter static analysis could be used to attempt to validate dynamic strings only when they are fully interpolated with known-safe values. ## Suggested Resolution - If the name value is built using dynamic expressions (like format() or variables), and Terraform can't check it exactly at the time of validation, this should not be treated as an error. - Instead, show it as a warning to inform the user without stopping the validation process. - If possible, try to make the validation smarter so it can recognize when dynamic values are still safe and follow the rules. ### Actual Behavior The terraform validate command fails prematurely with a hard error during the static validation phase, even though: - The actual value of name is compliant - terraform apply and pipelines execute the deployment successfully ### Steps to Reproduce ```` locals { resource_name_template = "svcv-pricebook-dev" } data "azurerm_service_plan" "service_plan" { name = format(local.resource_name_template, "function-serviceplan") # Still < 60 chars resource_group_name = "my-rg" } ```` Run: ```` terraform validate ```` ### Additional Context - Our CI/CD pipelines run terraform apply and the name resolves correctly. - We believe this strict validation behavior results in false negatives and creates confusion during initial development and peer reviews. - A more lenient validation or warning-level feedback could improve DX (developer experience). ### References _No response_ ### Generative AI / LLM assisted development? _No response_
Click on a version to see all relevant bugs
Terraform Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.