@terraforge/terraform 0.0.15 → 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 +2 -2
- package/dist/index.mjs +50 -36
- package/package.json +1 -1
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,
|
|
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
|
|
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
|
|
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,
|
|
@@ -1966,6 +1975,23 @@ const formatAttributePath = (state) => {
|
|
|
1966
1975
|
});
|
|
1967
1976
|
});
|
|
1968
1977
|
};
|
|
1978
|
+
const getNestedValue = (obj, path) => {
|
|
1979
|
+
let current = obj;
|
|
1980
|
+
for (const key of path) {
|
|
1981
|
+
if (current === null || current === void 0) return current;
|
|
1982
|
+
if (Array.isArray(current)) current = current[key];
|
|
1983
|
+
else if (typeof current === "object") current = current[key];
|
|
1984
|
+
else return;
|
|
1985
|
+
}
|
|
1986
|
+
return current;
|
|
1987
|
+
};
|
|
1988
|
+
const filterRequiresReplace = (paths, priorState, proposedState) => {
|
|
1989
|
+
return paths.filter((path) => {
|
|
1990
|
+
const priorValue = getNestedValue(priorState, path);
|
|
1991
|
+
const proposedValue = getNestedValue(proposedState, path);
|
|
1992
|
+
return JSON.stringify(priorValue) !== JSON.stringify(proposedValue);
|
|
1993
|
+
});
|
|
1994
|
+
};
|
|
1969
1995
|
var IncorrectType = class extends TypeError {
|
|
1970
1996
|
constructor(type, path) {
|
|
1971
1997
|
super(`${path.join(".")} should be a ${type}`);
|
|
@@ -2018,7 +2044,7 @@ const formatInputState = (schema, state, includeSchemaFields = true, path = [])
|
|
|
2018
2044
|
throw new Error(`Unknown schema type: ${schema.type}`);
|
|
2019
2045
|
};
|
|
2020
2046
|
const formatOutputState = (schema, state, path = []) => {
|
|
2021
|
-
if (state === null) return;
|
|
2047
|
+
if (state === null) return null;
|
|
2022
2048
|
if (schema.type === "array") {
|
|
2023
2049
|
if (Array.isArray(state)) return state.map((item, i) => formatOutputState(schema.item, item, [...path, i]));
|
|
2024
2050
|
throw new IncorrectType(schema.type, path);
|
|
@@ -2050,7 +2076,7 @@ const formatOutputState = (schema, state, path = []) => {
|
|
|
2050
2076
|
object[camelCase(key)] = formatOutputState(prop, value, [...path, key]);
|
|
2051
2077
|
}
|
|
2052
2078
|
return object;
|
|
2053
|
-
} else return;
|
|
2079
|
+
} else return null;
|
|
2054
2080
|
throw new IncorrectType(schema.type, path);
|
|
2055
2081
|
}
|
|
2056
2082
|
return state;
|
|
@@ -2100,39 +2126,33 @@ const createPlugin5 = async ({ server, client }) => {
|
|
|
2100
2126
|
config: encodeDynamicValue(formatInputState(schema$1, state))
|
|
2101
2127
|
});
|
|
2102
2128
|
},
|
|
2103
|
-
async planResourceChange(type, priorState, proposedState) {
|
|
2129
|
+
async planResourceChange(type, priorState, proposedState, configState) {
|
|
2104
2130
|
const schema$1 = getResourceSchema(resources, type);
|
|
2105
2131
|
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2106
|
-
const preparedProposedState = formatInputState(schema$1,
|
|
2107
|
-
|
|
2108
|
-
...proposedState
|
|
2109
|
-
});
|
|
2110
|
-
const configState = formatInputState(schema$1, proposedState);
|
|
2132
|
+
const preparedProposedState = formatInputState(schema$1, proposedState);
|
|
2133
|
+
const preparedConfigState = formatInputState(schema$1, configState);
|
|
2111
2134
|
const plan = await client.call("PlanResourceChange", {
|
|
2112
2135
|
typeName: type,
|
|
2113
2136
|
priorState: encodeDynamicValue(preparedPriorState),
|
|
2114
2137
|
proposedNewState: encodeDynamicValue(preparedProposedState),
|
|
2115
|
-
config: encodeDynamicValue(
|
|
2138
|
+
config: encodeDynamicValue(preparedConfigState)
|
|
2116
2139
|
});
|
|
2117
2140
|
const plannedState = decodeDynamicValue(plan.plannedState);
|
|
2118
2141
|
return {
|
|
2119
|
-
requiresReplace: formatAttributePath(plan.requiresReplace),
|
|
2142
|
+
requiresReplace: filterRequiresReplace(formatAttributePath(plan.requiresReplace), preparedPriorState, preparedProposedState),
|
|
2120
2143
|
plannedState
|
|
2121
2144
|
};
|
|
2122
2145
|
},
|
|
2123
|
-
async applyResourceChange(type, priorState,
|
|
2146
|
+
async applyResourceChange(type, priorState, plannedState, configState) {
|
|
2124
2147
|
const schema$1 = getResourceSchema(resources, type);
|
|
2125
2148
|
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2126
|
-
const
|
|
2127
|
-
|
|
2128
|
-
...proposedState
|
|
2129
|
-
});
|
|
2130
|
-
const configState = formatInputState(schema$1, proposedState);
|
|
2149
|
+
const preparedPlannedState = formatInputState(schema$1, plannedState);
|
|
2150
|
+
const preparedConfigState = formatInputState(schema$1, configState);
|
|
2131
2151
|
return formatOutputState(schema$1, decodeDynamicValue((await client.call("ApplyResourceChange", {
|
|
2132
2152
|
typeName: type,
|
|
2133
2153
|
priorState: encodeDynamicValue(preparedPriorState),
|
|
2134
|
-
plannedState: encodeDynamicValue(
|
|
2135
|
-
config: encodeDynamicValue(
|
|
2154
|
+
plannedState: encodeDynamicValue(preparedPlannedState),
|
|
2155
|
+
config: encodeDynamicValue(preparedConfigState)
|
|
2136
2156
|
})).newState));
|
|
2137
2157
|
}
|
|
2138
2158
|
};
|
|
@@ -2185,10 +2205,7 @@ const createPlugin6 = async ({ server, client }) => {
|
|
|
2185
2205
|
async planResourceChange(type, priorState, proposedState) {
|
|
2186
2206
|
const schema$1 = getResourceSchema(resources, type);
|
|
2187
2207
|
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2188
|
-
const preparedProposedState = formatInputState(schema$1,
|
|
2189
|
-
...priorState,
|
|
2190
|
-
...proposedState
|
|
2191
|
-
});
|
|
2208
|
+
const preparedProposedState = formatInputState(schema$1, proposedState);
|
|
2192
2209
|
const configState = formatInputState(schema$1, proposedState);
|
|
2193
2210
|
const plan = await client.call("PlanResourceChange", {
|
|
2194
2211
|
typeName: type,
|
|
@@ -2198,23 +2215,20 @@ const createPlugin6 = async ({ server, client }) => {
|
|
|
2198
2215
|
});
|
|
2199
2216
|
const plannedState = decodeDynamicValue(plan.plannedState);
|
|
2200
2217
|
return {
|
|
2201
|
-
requiresReplace: formatAttributePath(plan.requiresReplace),
|
|
2218
|
+
requiresReplace: filterRequiresReplace(formatAttributePath(plan.requiresReplace), preparedPriorState, preparedProposedState),
|
|
2202
2219
|
plannedState
|
|
2203
2220
|
};
|
|
2204
2221
|
},
|
|
2205
|
-
async applyResourceChange(type, priorState,
|
|
2222
|
+
async applyResourceChange(type, priorState, plannedState, configState) {
|
|
2206
2223
|
const schema$1 = getResourceSchema(resources, type);
|
|
2207
2224
|
const preparedPriorState = formatInputState(schema$1, priorState);
|
|
2208
|
-
const
|
|
2209
|
-
|
|
2210
|
-
...proposedState
|
|
2211
|
-
});
|
|
2212
|
-
const configState = formatInputState(schema$1, proposedState);
|
|
2225
|
+
const preparedPlannedState = formatInputState(schema$1, plannedState);
|
|
2226
|
+
const preparedConfigState = formatInputState(schema$1, configState);
|
|
2213
2227
|
return formatOutputState(schema$1, decodeDynamicValue((await client.call("ApplyResourceChange", {
|
|
2214
2228
|
typeName: type,
|
|
2215
2229
|
priorState: encodeDynamicValue(preparedPriorState),
|
|
2216
|
-
plannedState: encodeDynamicValue(
|
|
2217
|
-
config: encodeDynamicValue(
|
|
2230
|
+
plannedState: encodeDynamicValue(preparedPlannedState),
|
|
2231
|
+
config: encodeDynamicValue(preparedConfigState)
|
|
2218
2232
|
})).newState));
|
|
2219
2233
|
}
|
|
2220
2234
|
};
|