Add data to a json file in terraform - json

I am not a software guy, but I am preparing a small script for delarative onboarding work using terraform. The declaration is in a json file and it is send to the device through terraform. But I do not want to keep the sensitive data like passwords and secret keys in the json file. I want to inject them from a seperate file in a vault to the json file when I am executing it in terraform. I can use terraform to read the data from a vault or a s3 bucket, but I am not sure how to add it to the json declaration. I saw in terraform there is a functions like jsondecode and jsonencode. But I am not sure whether they will be any use to my requirement.
Could someone help me on this please ?
Thansk.

Maybe this is something which could help you?
Create a data source which loads your template file, here you can pass in some vars.
some examples for variales:
data "template_file" "my_template" {
template = templatefile("template.json", {
foo = "bar"
another_foo = aws_s3_bucket.my_bucket.id
more_foo = var.my_variable
})
}
The template file could look like this:
{
"Value": "123",
"value_2": "${foo}",
"value_3": "${another_foo}",
"value_4": ${more_foo},
}

Related

is there a template for uploading information to ibm maximo using JSON files?

is there any way to upload files to ibm maximo using JSON files with an external system?
Let me explain, I have created my object structure and I want to upload information, then I do it with a CSV file with the following structure:
<EXTSYSNAME>;<IFACENAME>;;<LANGUAGE> <ATRIBUTE1>;<ATRIBUTE2>;<ATRIBUTE3> <VALUE1>;<VALUE2>;<VALUE3>
and everything is fine.
Now my question is could I do this but instead of using csv, using JSON and if possible, what would be the structure?
Thanks in advance
I found this template but only works for domains:
{
"domainid":"DOMAIN1",
"domaintype":"ALN",
"maxtype":"ALN",
"description":"DESCRIPTION FOR DOMAIN 1",
"length":30,
"alndomain":[
{
"value":"ALNVALUE1",
"description":"ALN value 1",
"orgid":"",
"siteid":""
}
],
"_action":"CREATE"
}

Azure Logic Apps: Read XML from file and Write a JSON with data

I'm new in it and trying to understand Azure Logic Apps.
I would like to create a LogicApp that:
Looks for new XML-Files
and for each file:
Read the XML
Check if Node "attachment" is present
and for each Attachment:
Read the Filename
Get the File from FTP and do BASE64-encoding
End for each Attachment.
Write JSON File (I have a schema)
DO HTTP-Post to API with JSON file as "application/json"
Is this possible with the Logic-Apps?
Yes, you can.
Check if a node is present, with xpath expression (e.g. xpath(xml(item()),'string(//Part/#ref)'))
For Get File from FTP, use the action FTP - Get File Content
Write JSON File, use the action Data Operations - Compose. If you need transformations, you have to use an Integration Account and Maps.
Do HTTP Post to API, use de action HTTP

For jmeter post request, how can I generate input json from csv file?

I am trying to make a post rest call to my service. My sample input json file is,
{
"$id": "1",
"description": "sfdasd"
}
I have one csv file which contain a bunch of id and description, So is there a option where I can convert csv file to json objects and pass them to post call?
Assuming your CSV file is called test.csv, located in JMeter's "bin" folder and looks like:
Add CSV Data Set Config to your Test Plan and configure it as follows:
You can inline the defined JMeter Variables directly into your request body like:
{
"$id": "${id}",
"description": "${description}"
}
So when you run the test the variables placeholders will automatically be substituted with the values from the CSV file in the HTTP Request sampler:
See Using CSV DATA SET CONFIG article for more information on JMeter tests parameterization using CSV files.
Json is just text. Send as is with the variable id taken from csv:
{ "${id}": "1", "description": "sfdasd" }
CSV data can be converted to JSON via a POJO using Jackson. If a POJO is not already defined or required, you can always use the Java Collection classes to store parsed data and later convert it to JSON. http://www.novixys.com/blog/convert-csv-json-java/ is a good reference on how to convert csv to java.
You can check the following links too.
1. directly convert CSV file to JSON file using the Jackson library
2. Converting an CSV file to a JSON object in Java

Read and write to JSON on x10Hosting

I have an angular 2 project, how can I read and write to a JSON file on my server?
I can do what I want within my code itself bit I don't want to have to change my code, recompile and upload my website every time.
Any help? Examples are greatly appreciated
Angular can read the remote JSON file using the HTTP Client but it can't directly write to the remote file.
For writing, you can use a server side script such as PHP (supported by x10Hosting) to provide a url that allows Angular to post to (also using the HTTP Client), to update the JSON.
For example something like this PHP:
$data = json_decode('./data.json'); // decode the json
$data->something = $_POST['something']; // update the something property
file_put_contents('./data.json', json_encode($data)); // write back to data.json

Powershell error when trying to edit a configuration file of type Typesafe Config / JSON

I'm trying to update a configuration file. The extension is.conf and the type is Typesafe / Json-esque. I've found various posts online with several suggestions yet none of them are working and I'm not sure why.
The configuration file is:
version = "xyz"
a {
something = "some a"
somethingElse = "some b"
}
b{anumber = 12
}
I've tried a lot of options using ConvertFrom-Json but receive the Invalid JSON Primitive error (which I imagine is because it's not well formatted json)
Could someone help please? Many thansk in advance.
You could convert it to JSON (see Config -> Serialization) then ConvertFrom-Json then change a property via powershell then return it back from Json to typesafe (I don't know if this is actually possible).
Seems like a lot of work for such a simple thing. I would go with Powershell hash tables instead and create exporter.