Skip to content

Commit 79046e9

Browse files
committed
Fixed create for stateful parameters. Before the fix, stateful parameters were not added to desired during creates
1 parent aaa40c4 commit 79046e9

4 files changed

Lines changed: 52 additions & 4 deletions

File tree

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.59",
3+
"version": "1.0.60",
44
"description": "",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",

src/entities/resource-parameters.test.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,48 @@ class TestParameter extends StatefulParameter<TestConfig, string> {
2828
}
2929

3030
describe('Resource parameter tests', () => {
31+
it ('Generates a resource plan that includes stateful parameters (create)', async () => {
32+
const statefulParameter = spy(new class extends TestParameter {
33+
async refresh(): Promise<string | null> {
34+
return null;
35+
}
36+
})
37+
38+
const resource = new class extends TestResource {
39+
constructor() {
40+
super({
41+
type: 'resource',
42+
parameterOptions: {
43+
propA: { statefulParameter }
44+
},
45+
});
46+
}
47+
48+
async refresh(): Promise<any> {
49+
return null;
50+
}
51+
}
52+
53+
const plan = await resource.plan({
54+
type: 'resource',
55+
propA: 'a',
56+
propB: 10
57+
})
58+
59+
expect(statefulParameter.refresh.notCalled).to.be.true;
60+
expect(plan.currentConfig).toMatchObject({
61+
type: 'resource',
62+
propA: null,
63+
propB: null,
64+
})
65+
expect(plan.desiredConfig).toMatchObject({
66+
type: 'resource',
67+
propA: 'a',
68+
propB: 10
69+
})
70+
expect(plan.changeSet.operation).to.eq(ResourceOperation.CREATE);
71+
})
72+
3173
it('supports the creation of stateful parameters', async () => {
3274

3375
const statefulParameter = new class extends TestParameter {
@@ -39,7 +81,6 @@ describe('Resource parameter tests', () => {
3981
const statefulParameterSpy = spy(statefulParameter);
4082

4183
const resource = new class extends TestResource {
42-
4384
constructor() {
4485
super({
4586
type: 'resource',

src/entities/resource.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export abstract class Resource<T extends StringIndexedObject> {
8383
parameterOptions: this.parameterOptions,
8484
}
8585

86+
this.addDefaultValues(desiredConfig);
87+
8688
// Parse data from the user supplied config
8789
const parsedConfig = new ConfigParser(desiredConfig, this.statefulParameters, this.transformParameters)
8890
const {
@@ -93,15 +95,19 @@ export abstract class Resource<T extends StringIndexedObject> {
9395
transformParameters,
9496
} = parsedConfig;
9597

96-
this.addDefaultValues(resourceParameters);
9798
await this.applyTransformParameters(transformParameters, resourceParameters);
9899

99100
// Refresh resource parameters. This refreshes the parameters that configure the resource itself
100101
const currentParameters = await this.refreshResourceParameters(resourceParameters);
101102

102103
// Short circuit here. If the resource is non-existent, there's no point checking stateful parameters
103104
if (currentParameters == null) {
104-
return Plan.create(resourceParameters, null, resourceMetadata, planOptions);
105+
return Plan.create(
106+
{ ...resourceParameters, ...statefulParameters },
107+
null,
108+
resourceMetadata,
109+
planOptions,
110+
);
105111
}
106112

107113
// Refresh stateful parameters. These parameters have state external to the resource

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { MessageHandler } from './messages/handlers.js';
33

44
export * from './entities/resource.js'
55
export * from './entities/resource-types.js'
6+
export * from './entities/resource-options.js'
67
export * from './entities/plugin.js'
78
export * from './entities/change-set.js'
89
export * from './entities/plan.js'

0 commit comments

Comments
 (0)