@terraforge/terraform 0.0.17 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -36,11 +36,11 @@ type Plugin = Readonly<{
36
36
  readResource: (type: string, state: State$1) => Promise<State$1>;
37
37
  readDataSource: (type: string, state: State$1) => Promise<State$1>;
38
38
  validateResource: (type: string, state: State$1) => Promise<void>;
39
- planResourceChange: (type: string, priorState: State$1 | null, proposedNewState: State$1 | null) => Promise<{
39
+ planResourceChange: (type: string, priorState: State$1 | null, proposedNewState: State$1 | null, configState: State$1 | null) => Promise<{
40
40
  requiresReplace: Array<string | number>[];
41
41
  plannedState: State$1;
42
42
  }>;
43
- applyResourceChange: (type: string, priorState: State$1 | null, proposedNewState: State$1 | null) => Promise<State$1>;
43
+ applyResourceChange: (type: string, priorState: State$1 | null, plannedState: State$1 | null, configState: State$1 | null) => Promise<State$1>;
44
44
  }>;
45
45
  //#endregion
46
46
  //#region ../core/src/future.d.ts
package/dist/index.mjs CHANGED
@@ -257,25 +257,29 @@ var TerraformProvider = class {
257
257
  async createResource({ type, state }) {
258
258
  return {
259
259
  version: 0,
260
- state: await (await this.configure()).applyResourceChange(type, null, state)
260
+ state: await (await this.configure()).applyResourceChange(type, null, state, state)
261
261
  };
262
262
  }
263
263
  async updateResource({ type, priorState, proposedState }) {
264
264
  const plugin = await this.configure();
265
- const { requiresReplace } = await plugin.planResourceChange(type, priorState, proposedState);
265
+ const mergedState = {
266
+ ...priorState,
267
+ ...proposedState
268
+ };
269
+ const { requiresReplace, plannedState } = await plugin.planResourceChange(type, priorState, mergedState, proposedState);
266
270
  if (requiresReplace.length > 0) {
267
271
  const formattedAttrs = requiresReplace.map((p) => p.join(".")).join("\", \"");
268
272
  throw new Error(`Updating the "${formattedAttrs}" properties for the "${type}" resource will require the resource to be replaced.`);
269
273
  }
270
274
  return {
271
275
  version: 0,
272
- state: await plugin.applyResourceChange(type, priorState, proposedState)
276
+ state: await plugin.applyResourceChange(type, priorState, plannedState, proposedState)
273
277
  };
274
278
  }
275
279
  async deleteResource({ type, state }) {
276
280
  const plugin = await this.configure();
277
281
  try {
278
- await plugin.applyResourceChange(type, state, null);
282
+ await plugin.applyResourceChange(type, state, null, null);
279
283
  } catch (error) {
280
284
  try {
281
285
  if (!await plugin.readResource(type, state)) throw new ResourceNotFound();
@@ -284,7 +288,12 @@ var TerraformProvider = class {
284
288
  }
285
289
  }
286
290
  async planResourceChange({ type, priorState, proposedState }) {
287
- const result = await (await this.configure()).planResourceChange(type, priorState, proposedState);
291
+ const plugin = await this.configure();
292
+ const mergedState = {
293
+ ...priorState,
294
+ ...proposedState
295
+ };
296
+ const result = await plugin.planResourceChange(type, priorState, mergedState, proposedState);
288
297
  return {
289
298
  version: 0,
290
299
  requiresReplacement: result.requiresReplace.length > 0,
@@ -2117,19 +2126,16 @@ const createPlugin5 = async ({ server, client }) => {
2117
2126
  config: encodeDynamicValue(formatInputState(schema$1, state))
2118
2127
  });
2119
2128
  },
2120
- async planResourceChange(type, priorState, proposedState) {
2129
+ async planResourceChange(type, priorState, proposedState, configState) {
2121
2130
  const schema$1 = getResourceSchema(resources, type);
2122
2131
  const preparedPriorState = formatInputState(schema$1, priorState);
2123
- const preparedProposedState = formatInputState(schema$1, {
2124
- ...priorState,
2125
- ...proposedState
2126
- });
2127
- const configState = formatInputState(schema$1, proposedState);
2132
+ const preparedProposedState = formatInputState(schema$1, proposedState);
2133
+ const preparedConfigState = formatInputState(schema$1, configState);
2128
2134
  const plan = await client.call("PlanResourceChange", {
2129
2135
  typeName: type,
2130
2136
  priorState: encodeDynamicValue(preparedPriorState),
2131
2137
  proposedNewState: encodeDynamicValue(preparedProposedState),
2132
- config: encodeDynamicValue(configState)
2138
+ config: encodeDynamicValue(preparedConfigState)
2133
2139
  });
2134
2140
  const plannedState = decodeDynamicValue(plan.plannedState);
2135
2141
  return {
@@ -2137,19 +2143,16 @@ const createPlugin5 = async ({ server, client }) => {
2137
2143
  plannedState
2138
2144
  };
2139
2145
  },
2140
- async applyResourceChange(type, priorState, proposedState) {
2146
+ async applyResourceChange(type, priorState, plannedState, configState) {
2141
2147
  const schema$1 = getResourceSchema(resources, type);
2142
2148
  const preparedPriorState = formatInputState(schema$1, priorState);
2143
- const preparedProposedState = formatInputState(schema$1, {
2144
- ...priorState,
2145
- ...proposedState
2146
- });
2147
- const configState = formatInputState(schema$1, proposedState);
2149
+ const preparedPlannedState = formatInputState(schema$1, plannedState);
2150
+ const preparedConfigState = formatInputState(schema$1, configState);
2148
2151
  return formatOutputState(schema$1, decodeDynamicValue((await client.call("ApplyResourceChange", {
2149
2152
  typeName: type,
2150
2153
  priorState: encodeDynamicValue(preparedPriorState),
2151
- plannedState: encodeDynamicValue(preparedProposedState),
2152
- config: encodeDynamicValue(configState)
2154
+ plannedState: encodeDynamicValue(preparedPlannedState),
2155
+ config: encodeDynamicValue(preparedConfigState)
2153
2156
  })).newState));
2154
2157
  }
2155
2158
  };
@@ -2202,10 +2205,7 @@ const createPlugin6 = async ({ server, client }) => {
2202
2205
  async planResourceChange(type, priorState, proposedState) {
2203
2206
  const schema$1 = getResourceSchema(resources, type);
2204
2207
  const preparedPriorState = formatInputState(schema$1, priorState);
2205
- const preparedProposedState = formatInputState(schema$1, {
2206
- ...priorState,
2207
- ...proposedState
2208
- });
2208
+ const preparedProposedState = formatInputState(schema$1, proposedState);
2209
2209
  const configState = formatInputState(schema$1, proposedState);
2210
2210
  const plan = await client.call("PlanResourceChange", {
2211
2211
  typeName: type,
@@ -2219,19 +2219,16 @@ const createPlugin6 = async ({ server, client }) => {
2219
2219
  plannedState
2220
2220
  };
2221
2221
  },
2222
- async applyResourceChange(type, priorState, proposedState) {
2222
+ async applyResourceChange(type, priorState, plannedState, configState) {
2223
2223
  const schema$1 = getResourceSchema(resources, type);
2224
2224
  const preparedPriorState = formatInputState(schema$1, priorState);
2225
- const preparedProposedState = formatInputState(schema$1, {
2226
- ...priorState,
2227
- ...proposedState
2228
- });
2229
- const configState = formatInputState(schema$1, proposedState);
2225
+ const preparedPlannedState = formatInputState(schema$1, plannedState);
2226
+ const preparedConfigState = formatInputState(schema$1, configState);
2230
2227
  return formatOutputState(schema$1, decodeDynamicValue((await client.call("ApplyResourceChange", {
2231
2228
  typeName: type,
2232
2229
  priorState: encodeDynamicValue(preparedPriorState),
2233
- plannedState: encodeDynamicValue(preparedProposedState),
2234
- config: encodeDynamicValue(configState)
2230
+ plannedState: encodeDynamicValue(preparedPlannedState),
2231
+ config: encodeDynamicValue(preparedConfigState)
2235
2232
  })).newState));
2236
2233
  }
2237
2234
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terraforge/terraform",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",