in source/packages/services/installer/src/commands/modules/service/greengrass2Provisioning.ts [71:236]
public async prompts(answers: Answers): Promise<Answers> {
delete answers.greengrass2Provisioning?.redeploy;
let updatedAnswers: Answers = await inquirer.prompt(
[redeployIfAlreadyExistsPrompt(this.name, this.stackName)],
answers
);
if (updatedAnswers.greengrass2Provisioning?.redeploy ?? true) {
updatedAnswers = await inquirer.prompt(
[
{
message: `Do you want the module to publish all operation events to CDF EventBridge?`,
type: 'confirm',
name: 'greengrass2Provisioning.enablePublishEvents',
default: answers.greengrass2Provisioning?.enablePublishEvents ?? true,
askAnswered: true,
},
{
message:
'When using the Asset Library module as an enhanced device registry, the Greengrass2 Provisioning module can use it to help search across devices and groups to define the deployment targets. You have not chosen to install the Asset Library module - would you like to install it?\nNote: as there is additional cost associated with installing the Asset Library module, ensure you familiarize yourself with its capabilities and benefits in the online CDF github documentation.',
type: 'confirm',
name: 'greengrass2Provisioning.useAssetLibrary',
default: updatedAnswers.greengrass2Provisioning?.useAssetLibrary ?? false,
askAnswered: true,
},
],
updatedAnswers
);
updatedAnswers.greengrass2Provisioning.installerConfigGenerators =
updatedAnswers.greengrass2Provisioning.installerConfigGenerators ||
this.defaultInstallerConfigGenerators;
let configGeneratorsPromptAction: configGeneratorsPromptActionChoices;
enum configGeneratorsPromptActionChoices {
Confirm,
Add,
Delete,
}
while (configGeneratorsPromptAction != configGeneratorsPromptActionChoices.Confirm) {
if (
Object.keys(updatedAnswers.greengrass2Provisioning.installerConfigGenerators)
.length === 0
) {
configGeneratorsPromptAction = configGeneratorsPromptActionChoices.Add;
} else {
const installerConfigGeneratorsAsStringList = Object.entries(
updatedAnswers.greengrass2Provisioning.installerConfigGenerators
)
.map(([k, v]) => ` * ${k}: ${v}`)
.join('\n');
({ configGeneratorsPromptAction } = await inquirer.prompt(
[
{
type: 'list',
name: 'configGeneratorsPromptAction',
message: `The following config generator aliases are currently configured:\n${installerConfigGeneratorsAsStringList}\nWhat do you want to do next?`,
choices: [
{
name: 'confirm list and continue',
value: configGeneratorsPromptActionChoices.Confirm,
},
{
name: 'add another config generator alias',
value: configGeneratorsPromptActionChoices.Add,
},
{
name: 'delete an entry from the list',
value: configGeneratorsPromptActionChoices.Delete,
},
],
default: configGeneratorsPromptActionChoices.Confirm,
},
],
{}
));
}
if (configGeneratorsPromptAction === configGeneratorsPromptActionChoices.Add) {
const newConfigGenerator: { alias: string; lambda: string } =
await inquirer.prompt(
[
{
type: 'input',
name: 'alias',
message: `Enter the config generator alias which will be used in requests to the CDF API`,
validate: (answer) => {
if (
updatedAnswers.greengrass2Provisioning
.installerConfigGenerators[answer] !== undefined
) {
return `The alias "${answer} is already in use, aliases must be unique."`;
}
if (answer.length === 0) {
return 'Please enter a value.';
}
return true;
},
},
{
type: 'input',
name: 'lambda',
message: `Enter the the name of the Lambda that CDF will invoke for this config generator`,
validate: (answer) => {
if (answer.startsWith('arn:')) {
return `Please enter the name of the Lambda, not the ARN."`;
}
if (answer.length === 0) {
return 'Please enter a value.';
}
return true;
},
},
],
{}
);
updatedAnswers.greengrass2Provisioning.installerConfigGenerators[
newConfigGenerator.alias
] = newConfigGenerator.lambda;
} else if (
configGeneratorsPromptAction === configGeneratorsPromptActionChoices.Delete
) {
const configGeneratorAliasesToDelete: { list: string[] } =
await inquirer.prompt(
[
{
type: 'checkbox',
name: 'list',
message: `Select one or more config generators to delete from the list`,
choices: Object.keys(
updatedAnswers.greengrass2Provisioning
.installerConfigGenerators
),
default: configGeneratorsPromptActionChoices.Confirm,
},
],
{}
);
configGeneratorAliasesToDelete.list.forEach(
(alias) =>
delete updatedAnswers.greengrass2Provisioning
.installerConfigGenerators[alias]
);
}
}
updatedAnswers = await inquirer.prompt(
[
enableAutoScaling(this.name, answers),
provisionedConcurrentExecutions(this.name, answers),
...applicationConfigurationPrompt(this.name, answers, []),
...customDomainPrompt(this.name, answers),
],
updatedAnswers
);
}
includeOptionalModule(
'assetLibrary',
updatedAnswers.modules,
updatedAnswers.greengrass2Provisioning.useAssetLibrary
);
return updatedAnswers;
}