Skip to content

Commit 7735a9e

Browse files
committed
feat: Add ability to skip destroys for a resource
1 parent 34e4d56 commit 7735a9e

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codify-plugin-lib",
3-
"version": "1.0.173",
3+
"version": "1.0.174",
44
"description": "Library plugin library",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",

src/plan/change-set.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ export class ChangeSet<T extends StringIndexedObject> {
7272
return new ChangeSet(ResourceOperation.CREATE, parameterChanges);
7373
}
7474

75+
static noop<T extends StringIndexedObject>(parameters: Partial<T>): ChangeSet<T> {
76+
const parameterChanges = Object.entries(parameters)
77+
.map(([k, v]) => ({
78+
name: k,
79+
operation: ParameterOperation.NOOP,
80+
previousValue: v ?? null,
81+
newValue: v ?? null,
82+
}))
83+
84+
return new ChangeSet(ResourceOperation.NOOP, parameterChanges);
85+
}
86+
7587
static destroy<T extends StringIndexedObject>(current: Partial<T>): ChangeSet<T> {
7688
const parameterChanges = Object.entries(current)
7789
.map(([k, v]) => ({

src/plan/plan.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ export class Plan<T extends StringIndexedObject> {
126126

127127
// DESTROY
128128
if (filteredCurrentParameters && !desired) {
129+
// We can manually override destroys. If a resource cannot be destroyed (for instance the npm resource relies on NodeJS being created and destroyed)
130+
if (!settings.canDestroy) {
131+
return new Plan(
132+
uuidV4(),
133+
ChangeSet.noop(filteredCurrentParameters),
134+
core,
135+
isStateful,
136+
)
137+
}
138+
129139
return new Plan(
130140
uuidV4(),
131141
ChangeSet.destroy(filteredCurrentParameters),

src/resource/parsed-resource-settings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
6464
return this.id;
6565
}
6666

67+
get canDestroy(): boolean {
68+
return !this.settings.importAndDestroy?.preventDestroy;
69+
}
70+
6771
get statefulParameters(): Map<keyof T, StatefulParameterController<T, T[keyof T]>> {
6872
return this.getFromCacheOrCreate('statefulParameters', () => {
6973

src/resource/resource-settings.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,18 @@ export interface ResourceSettings<T extends StringIndexedObject> {
113113
importAndDestroy?: {
114114
/**
115115
* Can this resources be imported? If set to false then the codifyCLI will skip over/not consider this
116-
* resource valid for imports. Defaults to true.
116+
* resource valid for imports. Defaults to false.
117117
*
118118
* Resources that can't be imported in the core library for example are: action resources
119119
*/
120120
preventImport?: boolean;
121121

122+
/**
123+
* Can this resources be destroyed? If set to false then the codifyCLI will skip over/not consider this
124+
* resource valid for destroys. Defaults to false.
125+
*/
126+
preventDestroy?: boolean;
127+
122128
/**
123129
* Customize the required parameters needed to import this resource. By default, the `requiredParameters` are taken
124130
* from the identifyingParameters for allowMultiple. The `requiredParameters` parameter must be declared if a complex required is declared in

0 commit comments

Comments
 (0)