I have created a cloud function to update my remote configs in a specific manner. I followed the guide as per documentation.
Following is the code snippet.
exports.updateTenantFeatures = functions
.region(DEFAULT_LOCATION)
.https.onCall(async (data, context) => {
try {
if (!context.auth) {
throw new UnauthenticatedError(
constants.ERROR_TEXT.CIVIS_UNAUTHENTICATED_TEXT,
constants.ERROR_CODE.CIVIS_UNAUTHENTICATED,
);
}
const country = getCountryName(data.countryCode);
const poolId = data.poolId;
const remoteConfig = admin.remoteConfig();
const template = await remoteConfig.getTemplate();
const featureList = JSON.stringify({ [data.featureName]: data.featureState });
template.parameterGroups[`${country}_${poolId}`].parameters[`${country}_${poolId}_features`] = {
valueType: "JSON",
defaultValue: {
value: featureList,
},
description: `tenant of pool id ${poolId} from ${country}'s feature list`
}
const result = await remoteConfig.publishTemplate(template);
return {
result: constants.RESULT.SUCCESS,
tenantFeatuerList: result.parameters[`${country}_${poolId}_features`]
};
} catch (error: any) {
if (error?.type === constants.ERROR_TYPE.UNAUTHENTICATED ||
error?.type === constants.ERROR_TYPE.UNAUTHORIZED)
{
return { result: constants.RESULT.ERROR, code: error.code, details: error.message }
}
return { result: constants.RESULT.ERROR }
}
});
The goal of this function is to create parameters nested inside a parameter group programmatically. Attached image depicts how this is expected to be structured.
Problem is when I'm using template.parameterGroups[`${country}_${poolId}`]... it doesn't create a parameter group as expected. It throws the following error in Logs.
error in updateTenantFeatures : TypeError: Cannot read properties of undefined (reading 'parameters')
But however if I ignore creating the parameter group and focus on creating parameters by removing the parameterGroups as template.parameters[`${country}_${poolId}_features`] = ... it creates just the parameter.
Is the parameter group creation restricted by the admin sdk ? Or is the SDK having some issue(s) in creating parameter groups ?

template.parameterGroups[`${country}_${poolId}`]is undefined. What are you expecting it to be instead? You have a lot of variables here that we can't see, so we don't know much about what you're actually working with. Try logging everything to see that it's all what you expect.