diff --git a/ephemeral/startup/action.yml b/ephemeral/startup/action.yml index e1f7f9a..2397a8e 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]// /} # Trim whitespace + value=${kv[1]// /} # Trim whitespace + 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)