Hello Everyone,
One of our vendors do expect pem certificate in a json without escaping ‘\n’:
{
"pemEncodedCert": "-----BEGIN CERTIFICATE-----\nMIIELTCCAxWgAwIBAgIJAMn+G3YSmOujMA0GCSqGSIb3DQEBBQUAMIGsMQswCQYD\n........\n-----END CERTIFICATE-----",
"selfSigned": true
}
The problem is that the cert is coming as a variable and whenever I try to create a template() and include the cert variable containing the cert it escapes next lines with ‘\\n’, which is not recognised by the API when submitting the request. Is there any way to avoid such behaviour without preparing json payload as an external command ?
I hope I formulated my though good enough:)
Thank you in advance
Hi @dimatha,
The JSON specification which Terraform implements doesn’t allow for literal newline characters inside strings, so escaped newlines are the only valid representation. If you need to generate a value that isn’t valid JSON per that RFC then unfortunately you will need to construct that string directly yourself, without using the jsonencode
function.
With that said, a JSON parser that doesn’t support escaping seems very unusual – it would presumably then also not allow strings containing quotes or backslashes. Are you sure that’s actually the requirement for this API?
Hi @apparentlymart,
Thanks for your prompt reply and the explanation!
I just skipped JSON parsing and I got the result I need.
That’s Akamai PAPI … it is indeed the case I also confirmed it with their representatives.
Thanks once more
have a great day !