in src/AWS.Deploy.CLI/Commands/DeployCommand.cs [346:398]
private async Task<Recommendation> GetSelectedRecommendationFromPreviousDeployment(Orchestrator orchestrator, List<Recommendation> recommendations, CloudApplication deployedApplication, DeploymentSettings? deploymentSettings, string deploymentProjectPath)
{
var deploymentSettingRecipeId = deploymentSettings?.RecipeId;
var selectedRecommendation = await GetRecommendationForRedeployment(recommendations, deployedApplication, deploymentProjectPath);
if (selectedRecommendation == null)
{
var errorMessage = $"{deployedApplication.Name} already exists as a {deployedApplication.ResourceType} but a compatible recommendation used to perform a re-deployment was not found.";
throw new FailedToFindCompatibleRecipeException(DeployToolErrorCode.CompatibleRecommendationForRedeploymentNotFound, errorMessage);
}
if (!string.IsNullOrEmpty(deploymentSettingRecipeId) && !string.Equals(deploymentSettingRecipeId, selectedRecommendation.Recipe.Id, StringComparison.InvariantCultureIgnoreCase))
{
var errorMessage = $"The existing {deployedApplication.ResourceType} {deployedApplication.Name} was created from a different deployment recommendation. " +
"Deploying to an existing target must be performed with the original deployment recommendation to avoid unintended destructive changes to the resources.";
if (_toolInteractiveService.Diagnostics)
{
errorMessage += Environment.NewLine + $"The original deployment recipe ID was {deployedApplication.RecipeId} and the current deployment recipe ID is {deploymentSettingRecipeId}";
}
throw new InvalidDeploymentSettingsException(DeployToolErrorCode.StackCreatedFromDifferentDeploymentRecommendation, errorMessage.Trim());
}
IDictionary<string, object> previousSettings;
if (deployedApplication.ResourceType == CloudApplicationResourceType.CloudFormationStack)
{
var metadata = await _cloudFormationTemplateReader.LoadCloudApplicationMetadata(deployedApplication.Name);
previousSettings = metadata.Settings.Union(metadata.DeploymentBundleSettings).ToDictionary(x => x.Key, x => x.Value);
}
else
{
previousSettings = await _deployedApplicationQueryer.GetPreviousSettings(deployedApplication, selectedRecommendation);
}
await orchestrator.ApplyAllReplacementTokens(selectedRecommendation, deployedApplication.Name);
selectedRecommendation = await orchestrator.ApplyRecommendationPreviousSettings(selectedRecommendation, previousSettings);
var header = $"Loading {deployedApplication.DisplayName} settings:";
_toolInteractiveService.WriteLine(header);
_toolInteractiveService.WriteLine(new string('-', header.Length));
var optionSettings =
selectedRecommendation
.Recipe
.OptionSettings
.Where(x => _optionSettingHandler.IsSummaryDisplayable(selectedRecommendation, x))
.ToArray();
foreach (var setting in optionSettings)
{
DisplayOptionSetting(selectedRecommendation, setting, -1, optionSettings.Length, DisplayOptionSettingsMode.Readonly);
}
return selectedRecommendation;
}