bicep icon indicating copy to clipboard operation
bicep copied to clipboard

Increase MaxLiteralCharacterLimit for loadTextContent (specifically for non-JSON content)

Open JayDoubleu opened this issue 4 years ago • 57 comments

Increase MaxLiteralCharacterLimit for loadTextContent https://github.com/Azure/bicep/blob/main/src/Bicep.Core/LanguageConstants.cs#L32

Some of logic app JSON code as well as Azure Workbooks cannot be used with this function due to them being larger than 131072 characters. A lot of these resources would be created via azure portal and then used within arm templates/bicep for deployment. It would be great to have the ability to load it's content from within a separate file.

JayDoubleu avatar Sep 06 '21 18:09 JayDoubleu

+1

slavizh avatar Sep 07 '21 10:09 slavizh

Options to implement this:

  • We could increase the limit in the runtime.
  • We could put the content into a variable instead of a JSON expression string literal. (Would have to avoid clashes with user-defined variables, though.)

majastrz avatar Sep 07 '21 17:09 majastrz

Related:

  • #3315

alex-frankel avatar Sep 08 '21 17:09 alex-frankel

Exactly I got the same issue with string literal limit length

minhquang avatar Sep 09 '21 20:09 minhquang

We are going to investigate increasing the runtime limit

alex-frankel avatar Sep 29 '21 19:09 alex-frankel

Is there any update on this investigation? I've found the same character limitation brings down an idea of using otherwise fully functioning API Management api publishments using bicep, because openapi files can be larger than the current 131072 character limitation allows.

stutommi avatar Dec 09 '21 15:12 stutommi

I'd really like this feature too. I have a separate process that adds a lot of elements to an app gateway, which I then update intermittently via Bicep as part of my core infrastructure maintenance. I read in the appGw config as it stands and can output it to a file for Bicep to use so that the appGw template is made up of all the features I need without overwriting the separate process changes that were made. The file size limit really restricts this as my appGw grows in size though, so runtime changes would be brilliant to amend this higher... @alex-frankel is this on a roadmap for future implementation at all?

BCOps avatar Dec 21 '21 17:12 BCOps

It's something we would like to do, but I doubt it will be dealt with in the next 3-6 months. It would be helpful if this issue gets more upvotes, so we can shift priorities accordingly.

alex-frankel avatar Dec 22 '21 00:12 alex-frankel

@alex-frankel I have a monitor workbook with more than 131072 characters. I wonder can you somehow make the function to not account for tabs/whitespaces or that does not matter for the function?

slavizh avatar Jan 28 '22 10:01 slavizh

You can try to deploy the SOC Process Framework Sentinel workbook from https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/Workbooks/SOCProcessFramework.json - I have found no way to do this using Bicep, because of this limitation. The same number appears when i try to add the content using json() with a string rather than through loadTextContent

mariussm avatar Feb 09 '22 08:02 mariussm

It is a blocker for deploying open api spec files for an API. Those files can get larger if they have more operations :(

raunaknarooka avatar Feb 23 '22 11:02 raunaknarooka

Any ETA on when this could be implemented ? im hitting this problem right now with a workbook im trying to use.

jessicalavoie avatar Mar 30 '22 19:03 jessicalavoie

As someone mentioned above it's a blocker really. Bicep seems ok when you want to build something simple but if you got something advanced to do it might be better to stick to something else like terraform. Is there any information when we can expect solution for that issue?

lukaszgx avatar Apr 08 '22 12:04 lukaszgx

We'll discuss it again in triage this week, but I'm moving this to the 1.0 milestone for now. We'll see if we can get it done sooner.

alex-frankel avatar Apr 08 '22 22:04 alex-frankel

maximum size of 131072 characters. Please make sure you understand this is characters not bytes. This makes this feature unusable. Any work arounds?

enterpriseSoftware avatar Jun 07 '22 22:06 enterpriseSoftware

Upvote

verschaevesiebe avatar Jun 16 '22 09:06 verschaevesiebe

I hit the same problem today with a swagger import file that was 213,293 bytes.

I found a workaround for large json files, by using loadJsonContent() then wrapping the result with string(..) as follows...

var swagger = string(loadJsonContent('api.swagger.json'))

qualitas-software avatar Jun 28 '22 13:06 qualitas-software

@qualitas-software thank you for posting that, I needed that.

enterpriseSoftware avatar Jun 28 '22 14:06 enterpriseSoftware

@qualitas-software i see you highlight json, i assume this doesn't work for loadTextContent ? 😄

verschaevesiebe avatar Jun 28 '22 22:06 verschaevesiebe

@verschaevesiebe yeah the original issue is about loadTextContent(). I haven't tried it, but could you put the encoded file into json, use a version of the method above and extract it? Eg- { "encoded": "<base64 encoded file>" } then load it var fileContent = string(loadJsonContent('file.encoded.as.json').encoded) ? Good luck.

qualitas-software avatar Jun 30 '22 12:06 qualitas-software

@qualitas-software nice workaround, would have come up with it myself but I need structure so I've translated all OpenAPI Specs from YAML to JSON and we're now using the loadJsonContent 😄

Goodluck to anyone else running into file size limitations 🤗

verschaevesiebe avatar Jul 06 '22 16:07 verschaevesiebe

loadJsonContent

Nice this save me so much searching.

davidbambridge avatar Jul 08 '22 12:07 davidbambridge

+1

Kaloszer avatar Jan 25 '23 09:01 Kaloszer

Turns out that loadJsonContent() does not have this same problem. It seems most, if not all, of the cases where someone would run into this limit is for JSON content. Given that, we are going to close this and recommend you use loadJsonContent() instead.

If we are missing any cases that do not involve JSON content, please let us know and we can revisit.

alex-frankel avatar Feb 13 '23 21:02 alex-frankel

@alex-frankel may be for both commands will be best to document the maximum limits of size/characters? If not already, I have not checked.

slavizh avatar Feb 14 '23 07:02 slavizh

If we are missing any cases that do not involve JSON content, please let us know and we can revisit.

I have several cases of xml files (edifact xsd schemas) which exceeds the text limit by far, so this is absolutely not for just json documents.

Why are there even different size limits for json and text content?

johan-burman avatar Feb 17 '23 10:02 johan-burman

It would be great to have some transparency on this. Is there some sort of limitation that would prevent this limit to be raised globally?

Without this transparency we might be guessing the reasons for this not being implemented which isn't exactly helpful both for Microsoft nor open-source community.

JayDoubleu avatar Feb 17 '23 10:02 JayDoubleu

Why are there even different size limits for json and text content?

@miqm knows better than me, but my guess is we can handle JSON more efficiently because it's the same format as the template.

Thank you for sharing the examples @johan-burman. Which resource types are you using those XML schemas for? I will re-open the issue and make it more specific to non-JSON content.

@JayDoubleu -- hopefully you have seen that we always try to be as transparent as possible. The reason we closed this is because we thought it only needed to cover JSON content. At this point, we will need to take another look and see if we need to prioritize this sooner.

alex-frankel avatar Feb 17 '23 17:02 alex-frankel

The limit for loadTextContent is a limit for ARM template expression as noted here

As Alex pointed, loadJsonContent leverages ARM's JSON structure to "omit" the bicep compilation and put file directly into Intermediate Language - which is ARM JSON (load is not direct though - any potential ARM Template expression escaping is done to avoid loaded file being processed by ARM runtime).

LoadJsonContent does not enforce any limit - the only limit is 4MB - which is a limit for ARM template. So even if you have a 4MB JSON file your template most probably will fail due to other compiled resources "taking space" in the intermediate ARM file.

AFAIK the expression limit is in ARM Runtime to not process too long expressions. However @anthony-c-martin or @majastrz can give more light on this.

Perhaps a solution would be to give ability to provide some storage account details which could be used as intermediate artifact storage during deployment?

miqm avatar Feb 18 '23 21:02 miqm

Thanks for re-opening the ticket!

Thank you for sharing the examples @johan-burman. Which resource types are you using those XML schemas for? I will re-open the issue and make it more specific to non-JSON content.

The case I'm looking at right now is adding a large edi flatfile schema (xsd) to an integration account. Before this I came across the same limit with an Xslt, but was able to make it fit by removing whitespace.

If this limit needs to stay as-is, maybe there's some other way to achieve the same result, which we are overlooking?

johan-burman avatar Feb 20 '23 07:02 johan-burman