Structured variable replacement json not working for root elements

Hello
I have this json (abbreviated)
{
“version”: 3,
“$schema”: “https://www.krakend.io/schema/v3.json”,
“name”: “COV API Gateway (DUMMY)”,
“port”: 8080,
“timeout”: “5s”,
“cache_ttl”: “300s”,
“output_encoding”: “json”,
“tls”: {
“public_key”: “/etc/krakend/apigw.crt”,
“private_key”: “/etc/krakend/apigw.key”
},

when i use a variable called tls:public_key the replacement works.
However for the root elements like name, timeout etc. nothing is replaced

i tried these variable names
name
:name
name:

How can i replace the root element’s values with variable values?
Thank you
Fabian
but the name is not re

Hi @fhanggi,

Thanks for reaching out, great to hear from you again!

Our docs here mention that having a variable like name should be all that’s required for a ‘root’ variable to be replaced. Is it possible that variable scoping is preventing the value from being used?

I’d be happy to take a further look into this and see if I can reproduce it on my end. Could you please send through the Deployment Process Json as well as the Task logs with variable logging enabled?

You should be able to use this secure upload link but feel free to reach out if there are any issues with it or you have any questions!

Best Regards,

Hi Finnian
I have uploaded the deployment process json and the task log.
I can see many other variables named “Name” or “name”. Not sure how i can fix this though. Our Json file is produced by a tool so i cannot change “name” to something else.
Any tips for how to get this to work would be great.
Thank you
Fabian

Hi Fabian,

I’ve reviewed the files you sent through and attempted to reproduce issue you’re seeing with your Octopus version (2022.2.6872), but unfortunately it seems to be working fine for me. I’m using the following to test this, but let me know if you spot something that doesn’t match your process.

First I created a single JSON file (MyJson.json) in a package (MyJson.1.0.0.zip) with the following contents:

{
  "version": 3,
  "$schema": "https://www.krakend.io/schema/v3.json",
  "name": "COV API Gateway (DUMMY)",
  "port": 8080,
  "timeout": "5s",
  "cache_ttl": "300s",
  "output_encoding": "json",
  "tls": {
    "public_key": "/etc/krakend/apigw.crt",
    "private_key": "/etc/krakend/apigw.key"
  }
}

And then in the deploy a package step, I reference that file to have variables replaced within the MyJson package:

In the Octopus Project, I have the following variable defined with no scoping:
image

Deploying this package gives me the expected result, and I see the substitution happening in the log:

11:46:09   Verbose  |       Attempting structured variable replacement on file C:\Octopus\Applications\Tentacle 101.161_2021_3\Dev\MyJson\1.0.0\MyJson.json with format Json
11:46:09   Verbose  |       Structure found matching the variable 'name'. Replacing its content with the variable value.
11:46:09   Info     |       Structured variable replacement succeeded on file C:\Octopus\Applications\Tentacle 101.161_2021_3\Dev\MyJson\1.0.0\MyJson.json with format Json
{
  "version": 3,
  "$schema": "https://www.krakend.io/schema/v3.json",
  "name": "my_replaced_variable",
  "port": 8080,
  "timeout": "5s",
  "cache_ttl": "300s",
  "output_encoding": "json",
  "tls": {
    "public_key": "/etc/krakend/apigw.crt",
    "private_key": "/etc/krakend/apigw.key"
  }
}

So that all seems to be working, but I’m curious if you spot anything else that might be different with your configuration. For example, is there any scoping on the name variable that might be causing it to get scoped out of the deployment?

I noticed the raw deployment log you sent through showed the successful replacement occurring (with tls:public_key, so I’m wondering what you see when the replacement doesn’t work? If you’d like you can use the secure link above to provide this to me as well. Just let me know if you do that as unfortunately I don’t get any notification when that’s been done.

Best,
Patrick

Hi Patrick
I owe you guys an apology. By mistake for the “name” and other root variables i picked a scope that doesn’t exist. All is fine for now.
Thank you
Fabian

2 Likes

Hey Fabian,

No worries! I’m glad to hear you were able to determine the cause of the issue and get it working on your end. Also, thanks for following up to let us know the issue - it’s helpful in case anyone else runs into this in the future.

Let me know if you hit any other issues with this, otherwise happy deployments!

Patrick