in src/dynamicResources/commands/saveResource.ts [135:229]
export async function updateResource(
typeName: string,
identifier: string,
definition: string,
cloudControl: CloudControlClient,
window = Window.vscode(),
diff?: Operation[]
): Promise<boolean> {
return await window.withProgress(
{
location: vscode.ProgressLocation.Notification,
cancellable: false,
},
async progress => {
const startTime = new globals.clock.Date()
let result: Result = 'Succeeded'
try {
progress.report({
message: `Updating resource ${identifier} (${typeName})...`,
})
const current = await cloudControl.getResource({
TypeName: typeName,
Identifier: identifier,
})
const patch = diff ?? computeDiff(current.ResourceDescription!, definition)
if (patch.length === 0) {
result = 'Cancelled'
window.showWarningMessage(
localize(
'aws.resources.updateResource.noDiff',
'Update cancelled - no diff between local and remote definitions',
identifier,
typeName
)
)
return false
}
await cloudControl.updateResource({
TypeName: typeName,
Identifier: identifier,
PatchDocument: JSON.stringify(patch),
})
getLogger().info(`Updated resource type ${typeName} identifier ${identifier}`)
window.showInformationMessage(
localize('aws.resources.updateResource.success', 'Updated resource {0} ({1})', identifier, typeName)
)
return true
} catch (e) {
const error = e as Error
if (error.name === 'UnsupportedActionException') {
result = 'Cancelled'
getLogger().warn(
`Resource type ${typeName} does not support UPDATE action in ${cloudControl.regionCode}`
)
window.showWarningMessage(
localize(
'aws.resources.createResource.unsupported',
'{0} does not currently support resource updating in {1}',
typeName,
cloudControl.regionCode
)
)
return false
} else {
result = 'Failed'
getLogger().error(
`Failed to update resource type ${typeName} identifier ${identifier}: %O`,
error.message
)
showViewLogsMessage(
localize(
'aws.resources.updateResource.failure',
'Failed to update resource {0} ({1})',
identifier,
typeName
),
window
)
throw e
}
} finally {
recordDynamicresourceMutateResource({
dynamicResourceOperation: 'Update',
duration: millisecondsSince(startTime),
resourceType: typeName,
result: result,
})
}
}
)
}