Use array in JSON configuration file in serverless framework - serverless-framework

My serverless framework is trying to set an environment variable, CONFIG, to be contents of a JSON object.
My serverless.yml has this entry:
environment:
${file(./config.json)}
and my config.json looks like this:
{
"VARIABLE1": "value1",
"VARIABLE2": "value2",
"INT_VARIABLE": 3
"BOOLEAN_TEST": true
}
This seems to work just fine. ie:
console.log(process.env.VARIABLE1) outputs value1
console.log(process.env.INT_VARIABLE) outputs 3 (as a string... but I can convert if needed)
console.log(process.env.BOOLEAN_TEST) outputs true (as a string... but that's not the end of the world)
But when I go to add an array to the config.json, making the config.json look like this:
{
"VARIABLE1": "value1",
"VARIABLE2": "value2",
"INT_VARIABLE": 3
"BOOLEAN_TEST": true
"ARRAY_TEST": ["arrVal1", "arrVal2", "arrVal3"]
}
I get the following error:
Warning: Invalid configuration encountered at
'provider.environment.ARRAY_TEST': unsupported configuration format
How can I add an array as a environmental variable in serverless framework? (same basic question about adding sub-objects)

I believe you can split the elements by a delimiter:
serverless.yml
environment:
VARIABLE_1: ${file(./config.json):VARIABLE_1}
ARRAY_TEST:
"Fn::Split":
- ","
- ${file(./config.json):ARRAY_TEST}
config.json
{
"VARIABLE_1": "value1",
"ARRAY_TEST": "arrVal1,arrVal2,arrVal3"
}

Related

Automatically determine values for Terraform Azure Private endpoint module

I need a help with a terraform module that I've created. It works perfectly, but I need to add some automation.
I created a module which creates multiple private endpoints, but I always need to put the variable values in manually.
This is the module:
resource "azurerm_private_endpoint" "endpoint" {
for_each = try({ for endpoint in var.endpoints : endpoint.name => endpoint }, toset([]))
name = each.key
location = var.location
resource_group_name = var.resource_group_name
subnet_id = each.value.subnet_id
dynamic "private_service_connection" {
for_each = each.value.private_service_connection
content {
name = each.key
private_connection_resource_id = private_service_connection.value.private_connection_resource_id
is_manual_connection = false
subresource_names = var.subresource_name ### see values on : https://learn.microsoft.com/fr-fr/azure/private-link/private-endpoint-overview#private-link-resource
}
}
lifecycle {
ignore_changes = [
private_dns_zone_group
]
}
tags = var.tags
}
I need to have:
1 - for the private endpoint name : I need it to be automatically provided: "pendp-(the subresource_name value in lower cases- my resource_name =>(mysql server for example))"
2 - for the private connection name: I need the values to be automatically: "connection-(the subresource_name value in lower cases- my ressource_name =>(mysql server for exemple))"
3 - some automation to detect automatically the subresource_name ( if I create a private endpoint for a blob or for a mariadb or for a mysqlserver, the module should detected it.
terraform version:
terraform {
required_version = "~> 1"
required_providers {
azurerm = "~> 3.0"
}
}
The easiest way to combine values automatically would be to use the Terraform string join() function to join multiple strings together. For lower case strings, you can use the lower() function.
Some examples:
name = join("-", ["pandp", lower(var.subresource_name)])
...
name = join("-", ["connection", lower(var.subresource_name), lower(each.key)])
For your third rule, you want to use a conditional expression to determine if it's a blob, or mariadb, or mysqlserver.
In this example, we set an example_name local with a value some-blob-value if var.subresource_name contains a string that starts with "blob", and set it to something-else if the condition is false:
locals {
example_name = startswith(lower(var.subresource_name), "blob") ? "some-blob-value" : "something-else"
}
There are many options available for doing a conditional on if a value is passed to what you expect and then determine a result based on that value. What exactly you want isn't clear in the question, but hopefully this will get you pointed in the right direction.
Terraform even has several helper functions that might help you if you only need part of a string, such as startswith(), endswith(), or contains() depending on your needs.

Karate : dynamic test data using scenario outline is not working in some cases

I was tryiny to solve dynamic test data problem using dynamic scenario outline as mentioned in the documentation https://github.com/karatelabs/karate#dynamic-scenario-outline
It worked perfectly fine when I passed something like this in Example section
Examples:
|[{'entity':country},{'entity':state},{'entity':district},{'entity':corporation}]]
But I tried to generate this json object programatically , I am getting aa strange error
WARN com.intuit.karate - ignoring dynamic expression, did not evaluate to list: users - [type: MAP, value: com.intuit.karate.ScriptObjectMap#2b8bb184]
Code to generate json object
* def user =
"""
function(response){
entity_type_ids =[]
var entityTypes = response.entityTypes
for(var i =0;i<entityTypes.length;i++ ){
object = {}
object['entity'] = entityTypes[i].id
entity_type_ids.push(object)
}
return JSON.stringify(entity_type_ids)
}
"""

Jackson YAML Merge Operator Deserialization Wrong

I'm using Jackson to serialize and deserialize YAML but I'm encountering a problem with deserializing merge operator.
For example:
- &item001
boolean: true
integer: 7
float: 3.14
- &item002
boolean: false
- <<: [ *item002, *item001 ]
This yaml file isn't deserialized properly with jackson yaml.
This is the code I'm using:
val text = ..... //
val mapper = ObjectMapper(YAMLFactory()
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER))
.registerKotlinModule()
val list = mapper.readValue<Any>(text)
And it outputs basically:
[{"boolean":true,"integer":7, "float": 3.14}, {"boolean": false}, {"<<": 2}]
Rather than:
[{"boolean":true,"integer":7, "float": 3.14}, {"boolean": false}, {"boolean":false,"integer":7, "float": 3.14}]
It's strange though because Jackson YAML uses SnakeYAML underlying and if I perform the same operation with SnakeYAML it deserializes correctly.
Of course I could switch to SnakeYAML but my project needs both json and yaml converters and Jackson provides me with both.
Any suggestions?

unable to puppet lookup a hiera interpolated hash

getting a string instead of array
this is my common.yaml
aa::params:
- '--params:"abc.com'
- 'abc2.com'
test::packages:
package1:
ensure:'present'
install_options: "%{lookup('aa:params')}"
this is my manifest file
$packages = lookup("test::packages",undef,undef,'')
$params= lookup("aa::params",undef,undef,'')
$packages.each | String $packagename, Hash $attributes | {
notify { " ${packagename}, ${attributes[ensure]},${attributes['install_options]},${params} hello ":
}
}
expected
"package1,present,[--params="abc.com, abc2.com"],[--params="abc.com, abc2.com"] hello"
actual
"package1,present,["--params=\"abc.com", "abc2.com\""],[--params="abc.com, abc2.com"] hello"
It looks like array is getting stringified can someone please explain why I am getting like this
Interpolating the results of a lookup into a string always results in a string. If you want the actual array instead of a strigyfied version you should use alias instead. Your common.yaml would look something like this:
aa::params:
- '--params:"abc.com'
- 'abc2.com'
test::packages:
package1:
ensure:'present'
install_options: "%{alias('aa:params')}"
Here is the related documentation.

Properly accessing cluster_config '__default__' values

I have a cluster.json file that looks like this:
{
"__default__":
{
"queue":"normal",
"memory":"12288",
"nCPU":"1",
"name":"{rule}_{wildcards.sample}",
"o":"logs/cluster/{wildcards.sample}/{rule}.o",
"e":"logs/cluster/{wildcards.sample}/{rule}.e",
"jvm":"10240m"
},
"aln_pe":
{
"memory":"61440",
"nCPU":"16"
},
"GenotypeGVCFs":
{
"jvm":"102400m",
"memory":"122880"
}
}
In my snakefile I have a few rules that try to access the cluster_config object in their params
params:
memory=cluster_config['__default__']['jvm']
But this will give me a 'KeyError'
KeyError in line 27 of home/bwubb/projects/Germline/S0330901/haplotype.snake:
'__default__'
Does this have something to do with '__default__' being a special object? It pprints in a visually appealing dictionary where as the others are labeled OrderDict, but when I look at the json it looks the same.
If nothing is wrong with my json, then should I refrain from accessing '__default__'?
The default value is accessed via the keyword "cluster", not
__default__
See here in this example in the tutorial:
{
"__default__" :
{
"account" : "my account",
"time" : "00:15:00",
"n" : 1,
"partition" : "core"
},
"compute1" :
{
"time" : "00:20:00"
}
}
The JSON list in the URL above and listed above is the one being accessed in this example. It's unfortunate they are not on the same page.
To access time, J.K. uses the following call.
#!python
#!/usr/bin/env python3
import os
import sys
from snakemake.utils import read_job_properties
jobscript = sys.argv[1]
job_properties = read_job_properties(jobscript)
# do something useful with the threads
threads = job_properties[threads]
# access property defined in the cluster configuration file (Snakemake >=3.6.0)
job_properties["cluster"]["time"]
os.system("qsub -t {threads} {script}".format(threads=threads, script=jobscript))