Storing multiple parameters in AWS SSM using Terraform and a JSON configuration file

In the process of migrating a couple of legacy applications to ec2, we are faced with the challenge of storing multiple application configuration parameters individually. The goal is to have separate parameters for each application.

The current approach seems to be appending all values to a single parameter per application. Here's what we're trying:

locals {
  application = {
    "application1" = { app_shortcode = "app1"},
    "application2" = { app_shortcode = "app2"}
}

resource "aws_ssm_parameter" "application_parameters" {
  for_each = local.application
  name     = each.key
  value    = jsonencode(file("${path.module}/${each.key}/ssm_param.json"))
}

For example, the contents of ssm_param.json for app1 look like this:

{
    "app1_config1": "config_value_1",
    "app1_config2": "config_value_2",
    "app1_config3": "config_value_3"
}

And for app2, it's as follows:

{
    "app2_config_a": "config_value_a",
    "app2_config_b": "config_value_b",
    "app2_config_c": "config_value_c"
}

Currently, the output combines all configurations into a single parameter for each application. We're seeking suggestions on how to achieve the desired outcome.

Answer №1

My solution involved taking a slightly different approach than my original one, but it worked well for me:

I implemented the use of a ssm_params.yaml file provided by the project team with the configuration settings in YAML format.

parameter:
    app1:
      name: app1_config1
      description: "application config test"
      type: "String"
      value: "some_randoM_value"
    app1:
      name: app_config2
      description: "another test"
      type: "SecureString"
      value: "some_random123_value###"
    app2:
      name: app_config_2
      description: "config test"
      type: "String"
      value: "some_randoM_value_2"
locals {
params             = yamldecode(file("${path.module}/ssm_params.yaml"))
}

resource "aws_ssm_parameter" "app_params" {
  for_each = local.params.parameter
  name     = each.value.name
  type     = each.value.type
  value    = each.value.value
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Undefined Return Value from Node's Exports Function

I have a function that exports data and is supposed to return a JSON array of draft results. However, when I try to access the draft_results variable in the route provided below in app.js, it shows as undefined. app.get('/draft-results', functio ...

The signature does not match, so the SignedURL is being rejected

I recently started using AWS S3 and encountered the SignatureDoesNotMatch error while trying to upload an image. I double-checked for any typos in my keys, ensured that my system time was accurate, but still couldn't resolve the issue. My workflow, mo ...

What is the best way to merge an array into a single object?

I have an array object structured like this. [ { "name": "name1", "type": "type1", "car": "car1", "speed": 1 }, { "name": &q ...

Is there a specific method to access a JSON file with (js/node.js)?

Searching for a way to access user information stored in a JSON file using the fs module in node.js. Specifically looking to read only one user at a time. app.get("/1", function(req, res) { fs.readFile("users.json",function(data, err){res.write(data)}} W ...

Utilize S3 to host images and implement via Express in a Lambda-based project

I store all my user-related files in a bucket and I want users to be able to download those files. The issue I'm facing is that I need to proxy the request through an API URL like https://myproject.com/api/file/:key where :key corresponds to the obj ...

I encountered a ReferenceError stating that the variable "html" is not defined

Recently, I delved into the world of Node.js for the first time. During my attempt to connect my index.html file, an error message stating 'ReferenceError: html is not defined' popped up. Below is the code snippet from my index.js: var http = re ...

Exploring the process of transforming a JSON array into separate JSON objects using Node.js

I am struggling with converting a JSON array to multiple JSON objects in Node.js. I've attempted using loops but have been unsuccessful. I'm seeking assistance to send the data as separate objects, not an array. router.get('/frontpage-mobil ...

Experiencing a lack of email delivery when using the "adminCreateUser" feature in AWS Cognito

My current challenge involves utilizing the `adminCreateUser` function to create a new User, but I am encountering an issue where the temporary password is not being sent to my email address. var RegisterUser = exports.RegisterUser = function (data) { v ...

retrieve information in json format from a specified web address

I need to figure out why the data from a specific URL is not being displayed properly on my node application. It seems like there might be an error in my code. const extractRefDefaultSchema = async (data) => { const url = "https://mos.esante.gouv.f ...

Repairing unclean JSON requests with Node.js

My node.js API is receiving JSON data that is usually good, but sometimes contains bad characters at the end. { "test": "test" }��� I am trying to find a way to intercept this data before it reaches the BodyParser and causes errors. I attempted t ...

What could be the reason for the failure of my multer file uploads to AWS s3?

I managed to successfully upload my files locally, but I'm facing challenges with getting them onto AWS S3 Buckets. Whenever I submit a request, I encounter vague errors stating "Cannot set headers after they are sent to the client". It seems like the ...

The collaboration between a JSON response and Node.js allows for seamless

Within my node app, I am passing a series of queries as an Object. It is crucial for me to structure the request in an exact format. Here is an example of my request: {q0:{query0},q1:{query1},q2:{query1}} The expected response should look like this: {q0 ...

Steps to retrieve the JSON response using newman

After successfully testing the endpoint on Postman, I exported it as a collection and now running it using Newman on Jenkins CI. Command: newman run <POSTMAN_COLLECTION>.json -r json,cli The response.json file is generated in the current direct ...

A node is receiving a JSON object through an axios POST request

I am working on a project where I have two unique URLs. The first URL receives a form action from an HTML page along with data and then makes a post request to the second URL. The second URL, in turn, receives a JSON and uses Express to make a GET request ...

How can I prevent writeFileSync from replacing existing data?

When I use this line of code, it deletes all existing data. Is there a method or function that will append the new data on a new line instead? fs.writeFileSync(path.resolve(__dirname, 'quotes.json'), JSON.stringify(quotey)); ...

Transmit data using both jQuery and JSON technology

I'm struggling to figure out how to send a JSON structure with a file using AJAX. Whenever I try to include an image in the structure, I encounter an error. var professionalCardNumber = $("#professional_card_number_input").val(); var professi ...

Understanding JSON Parsing in Jade

I am facing a challenge with handling a large array of objects that I am passing through express into a Jade template. The structure of the data looks similar to this: [{ big object }, { big object }, { big object }, ...] To pass it into the Jade templat ...

Troubleshooting steps for resolving a node.js error during execution

I recently delved into server side programming with node.js, but I'm encountering some issues when trying to execute it. My server is set up at 127.0.0.1:80, however, I keep running into errors. Console: Server running at http://127.0.0.1:80/ node:ev ...

What is the best way to retrieve my data/json from req.body in Express?

Recently, I started working with node.js and encountered an issue while trying to access JSON data on my node.js server through a post request. The goal is to send this data to an API and then pass it back to my front-end JavaScript file. Despite being abl ...

Reading cached JSON value in a Node.js application

Recently, I embarked on creating a node.js application and reached a stage where I needed to retrieve a value from an updated JSON file. However, my attempts using the 'sleep' module to introduce a small delay were unsuccessful. I'm relativ ...