-
Notifications
You must be signed in to change notification settings - Fork 773
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
Added changes to allow non-DTC values for name in existing resources. #6778
Merged
davidcho23
merged 5 commits into
main
from
davidcho23/allowNameAssignmentForExistingResource
May 11, 2022
Merged
Added changes to allow non-DTC values for name in existing resources. #6778
davidcho23
merged 5 commits into
main
from
davidcho23/allowNameAssignmentForExistingResource
May 11, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shenglol
reviewed
May 9, 2022
shenglol
reviewed
May 9, 2022
shenglol
reviewed
May 9, 2022
shenglol
reviewed
May 9, 2022
shenglol
reviewed
May 10, 2022
shenglol
reviewed
May 10, 2022
shenglol
approved these changes
May 10, 2022
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.
This is great!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3169
When the "name" property for an existing resource has a value that cannot be calculated at deploy time, the current behavior in Bicep is that we block it. However, upon further investigation, it makes more sense to allow the existing resource use this non-DTC (non-DeployTimeConstant) value, and also allow other existing resources in the template to reference this non-DTC value. However, it is also necessary to make sure this non-DTC flow is managed; a non-existing resource cannot reference/use this non-DTC value because non-existing resources must require a DTC value.
Take this for example:
A resource newStg is created and has a string "test" as its name value. String literals are DTC values so this is allowed.
An existing resource is declared with the name referencing newStg.properties.accessTier. This value is not able to be calculated at deploy time, thus it is a non-DTC value. This is ok, as existing resources should be allowed to have a non-DTC value.
The problem lies with the resource foo that is declared with the existingStg.name. Because foo is not an existing resource, its "name" property must have a DTC value, like how newStg does. However, foo wants to use a non-DTC value, so we block it.
The fix
The fix here is that for all existing resources whose "name" property have a non-DTC value, remove the ReadableAtDeployTime flag from the "name" property. This flag is used to determine if a value is a DTC value or not. After removing the ReadableAtDeployTime flag, any existing resources that reference the value will know that they themselves must be non-DTC as well and also remove the ReadableAtDeployTime flag from their "name" property.
We also need to remove the DeployTimeConstant flag from these "name" properties of existing resources so that they are marked as non-DTC values.
Finally, an override method is needed in the DeployTimeConstantContainerVisitor. After our new logic, the DeployTimeConstantContainerVisitor picks up all the syntaxes as containers, and these containers are checked for DTC errors. In order to ensure that existing resources are not checked for non-DTC values and throw errors when it should not, the override method ensures that existing resources are not picked up as containers.
Microsoft Reviewers: Open in CodeFlow