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

Using latest api version of a resource #1002

Closed
stan-sz opened this issue Nov 25, 2020 · 5 comments
Closed

Using latest api version of a resource #1002

stan-sz opened this issue Nov 25, 2020 · 5 comments
Labels

Comments

@stan-sz
Copy link
Contributor

stan-sz commented Nov 25, 2020

In ARM template it's possible to not hardcode the API version for a given resource but dynamically (at 'run time') detect the latest api available for a resource:

"variables": {
    "acrApiVersion": "[first(providers('Microsoft.ContainerRegistry', 'registries/taskRuns').apiVersions)]"
},
resources": [
    {
      "type": "Microsoft.ContainerRegistry/registries/taskRuns",
      "apiVersion": "[variables('acrApiVersion')]",
      ...
    }
]

(note - the ordering is not guaranteed and sorting is not available, thus the first() not necessarily returns the latest available, usually it does)

In bicep this is not possible:

resource promoteRegistryTask 'Microsoft.ContainerRegistry/registries/taskRuns@${first(providers('Microsoft.ContainerRegistry', 'registries/taskRuns')).apiVersions}' = {

Error BCP047: String interpolation is unsupported for specifying the resource type.
Error BCP062: The referenced declaration with name "promoteRegistryTask" is not valid.

Can such scenario be supported in bicep? Is this something ARM template disallows by-design?

@stan-sz stan-sz added the enhancement New feature or request label Nov 25, 2020
@ghost ghost added the Needs: Triage 🔍 label Nov 25, 2020
@anthony-c-martin
Copy link
Member

Thanks for raising this! We have #622 which is similar, but I don't think covers the ability to get the 'latest' at runtime.

Some things to point out about API versioning in ARM:

  • API version is not a property of a resource - it defines the contract for interacting with a resource. Generally if you haven't changed any of the properties you supply, the effect on the underlying resource state will be identical between the older and newer version, unless the newer API contract has a breaking change (next point). Although it can feel odd to be using a very old API version, there is usually no great need to update unless for example you need to access some new properties added to a newer version.
  • Teams are permitted to make breaking changes to the structure of the API contract between API versions. They are not permitted to make breaking changes to the structure of the API contract for an existing API version. This may mean that if you upgrade versions without changing the structure of your request, you run the risk of being unexpectedly broken at deploy time.
  • Without having a known API version at authoring time, we cannot provide a great editor experience (type validation, intellisense etc), as we cannot know what properties are available.

So generally, our feeling on this is that we want to discourage people from picking up the API version at runtime and instead encourage pinning to a version and making the explicit decision to upgrade. That being said, we definitely see the need to simplify the syntax, know whether you're on the latest, and have an easy path to upgrade if you're not and want to be - currently we're thinking of addressing this with #622.

Does that make sense for your use case?

@alex-frankel
Copy link
Collaborator

@stan-sz - any thoughts on the above? otherwise, I think we will plan to close this one

@stan-sz
Copy link
Contributor Author

stan-sz commented Dec 3, 2020

Thanks for the thorough explanation, @anthony-c-martin.

@stan-sz stan-sz closed this as completed Dec 3, 2020
@stan-sz
Copy link
Contributor Author

stan-sz commented Feb 3, 2021

For reference, https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/test-cases#use-hardcoded-api-version

@stan-sz
Copy link
Contributor Author

stan-sz commented Feb 11, 2021

Also related to #516

@ghost ghost locked as resolved and limited conversation to collaborators May 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants