Azure / template-specs

MIT License
31 stars 4 forks source link

PSTemplateSpecVersion object should be available as text #28

Closed ChristopherGLewis closed 4 years ago

ChristopherGLewis commented 4 years ago

The PSTemplateSpecVersion object of a PSTemplateSpecSingleVersion/PSTemplateSpecMultiVersion object should have a text version of the object.

This would be similar to how the get-AzVirtualNetwork fields work -

An alternative would be to have a .ToJSON() method on the object (yes, it can be directly passed to ConvertTo-JSON, but this would be easier and more obvious, and also could be the raw, uploaded Template vs the parsed one that's dropping comments and formattting.

alex-frankel commented 4 years ago

We're looking to improve the formatting of how the TemplateSpec template/artifact content is returned in the console. We agree that it is not ideal atm.

stuartko commented 4 years ago

@ChristopherGLewis : Just to confirm, you're looking for a simple way to access the version's ARM Template content (as JSON)? Version.Template.ToString() will return the ARM Template as raw JSON, but I agree it's not very discoverable.

I'm thinking perhaps we should just make .Template a string (the raw JSON). I think it's unlikely anyone will want to interact with .Template as a JObject directly, and having it as a string will likely make it easier for users who wish to view the latest template content. @alex-frankel : Thoughts?

alex-frankel commented 4 years ago

If that fits with in Azure PowerShell design guidelines, I definitely think that is a better experience.

FWIW, when I run:

$ts.Version.Template.toString()

the output is what I expect to see -- the full template

image

If I run:

$ts.Version.Template | ConvertTo-Json

I get a weird result:

image

I'm not sure if that is something we can fix..

ChristopherGLewis commented 4 years ago

@ChristopherGLewis : Just to confirm, you're looking for a simple way to access the version's ARM Template content (as JSON)? Version.Template.ToString() will return the ARM Template as raw JSON, but I agree it's not very discoverable.

I'm thinking perhaps we should just make .Template a string (the raw JSON). I think it's unlikely anyone will want to interact with .Template as a JObject directly, and having it as a string will likely make it easier for users who wish to view the latest template content. @alex-frankel : Thoughts?

As mentioned above, the microsoft.azure.commands.network.models.psvirtualnetwork returns both an object and text.

The only reason to return an object is if we can get the TemplateSpec, alter the object, then send it back - which is probably NOT what you want to do with a Version Object.

I'm not on my machine with the TemplateSpec code so can't reproduce the FWIW. I would imagine adding a -Depth 99 on the ConvertTo-JSon might fix it

stuartko commented 4 years ago

The only reason to return an object is if we can get the TemplateSpec, alter the object, then send it back - which is probably NOT what you want to do with a Version Object.

Absolutely agree.

The latest release now exposes the ARM Template in both versions and artifacts as strings (JSON).

I'm adding the fixed flag for now and will keep this active for a few days and then close it if there are no additional concerns.