From 18b46b60714de50aeb8ff984f7015f909b491fa8 Mon Sep 17 00:00:00 2001 From: HarshCasper Date: Fri, 9 Aug 2024 20:59:46 +0530 Subject: [PATCH] make the ephemeral startup configurable for users --- ephemeral/startup/action.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ephemeral/startup/action.yml b/ephemeral/startup/action.yml index e1f7f9a..97e0dc9 100644 --- a/ephemeral/startup/action.yml +++ b/ephemeral/startup/action.yml @@ -23,7 +23,10 @@ inputs: description: 'The lifetime of the ephemeral instance, how long the instance should be available for' required: false default: '30' - + configuration: + description: 'Configuration for the LocalStack environment to be created' + required: false + default: '' runs: using: composite @@ -70,6 +73,19 @@ runs: autoLoadPod="${AUTO_LOAD_POD:-${{ inputs.auto-load-pod }}}" extensionAutoInstall="${EXTENSION_AUTO_INSTALL:-${{ inputs.extension-auto-install }}}" lifetime="${{ inputs.lifetime }}" + configuration='${{ inputs.configuration }}' + + # Convert configuration to JSON format + IFS=',' read -r -a configArray <<< "$configuration" + envVarsJson=$(jq -n '{}') + for config in "${configArray[@]}"; do + IFS='=' read -r -a kv <<< "$config" + key=${kv[0]// /} + value=${kv[1]// /} + envVarsJson=$(echo $envVarsJson | jq --arg key "$key" --arg value "$value" '. + {($key): $value}') + done + + envVarsJson=$(echo $envVarsJson | jq --arg autoLoadPod "$autoLoadPod" --arg extensionAutoInstall "$extensionAutoInstall" '. + {AUTO_LOAD_POD: $autoLoadPod, EXTENSION_AUTO_INSTALL: $extensionAutoInstall}') list_response=$(curl -X GET \ -H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \ @@ -85,7 +101,7 @@ runs: https://api.localstack.cloud/v1/compute/instances/$previewName) fi - response=$(curl -X POST -d "{\"instance_name\": \"${previewName}\", \"lifetime\": ${lifetime} ,\"env_vars\": {\"AUTO_LOAD_POD\": \"${autoLoadPod}\", \"EXTENSION_AUTO_INSTALL\": \"${extensionAutoInstall}\"}}"\ + response=$(curl -X POST -d "{\"instance_name\": \"${previewName}\", \"lifetime\": ${lifetime}, \"env_vars\": ${envVarsJson}}"\ -H "ls-api-key: ${LOCALSTACK_API_KEY:-${{ inputs.localstack-api-key }}}" \ -H "content-type: application/json" \ https://api.localstack.cloud/v1/compute/instances)