nomoss 0.0.3 → 0.0.5
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/CHANGELOG.md +34 -0
- package/README.md +5 -15
- package/ROADMAP.md +2 -0
- package/docs/README.md +1 -1
- package/docs/application/aws-resource-coverage.md +26 -0
- package/docs/application/aws-resource-lifecycle-management.md +13 -23
- package/docs/application/cli-workflow.md +1 -1
- package/docs/application/engine-design.md +2 -2
- package/docs/application/generation-architecture.md +10 -45
- package/docs/application/resource-command-policy-stage.md +2 -2
- package/docs/application/resource-graph.md +1 -1
- package/docs/application/resource-lifecycle-tracker.md +1 -9
- package/docs/application/resource-mapping.md +4 -9
- package/docs/application/resource-operations.md +4 -2
- package/docs/application/tracing.md +2 -6
- package/docs/development/code-documentation.md +2 -0
- package/docs/development/effect-native-development.md +44 -0
- package/docs/development/linting.md +1 -1
- package/docs/development/review-code.md +22 -6
- package/docs/development/review-remediation-spec.md +28 -37
- package/docs/development/spec-writing.md +1 -1
- package/docs/development/testing.md +23 -9
- package/docs/operations/observability-sop.md +11 -17
- package/docs/operations/releasing.md +3 -1
- package/examples/README.md +3 -26
- package/examples/commands.ts +2 -36
- package/examples/queue/application.ts +8 -2
- package/examples/state-machine/application.ts +3 -1
- package/package.json +40 -46
- package/providers/aws/README.md +21 -0
- package/providers/aws/awsEnvironment.ts +114 -0
- package/providers/aws/generated/managementRegistry.ts +136 -0
- package/{src/providers/aws/resources/generated/native/apigatewayv2/api/index.ts → providers/aws/generated/resources/apigatewayv2/api.ts} +13 -50
- package/{src/providers/aws/resources/generated/native/apigatewayv2/integration/index.ts → providers/aws/generated/resources/apigatewayv2/integration.ts} +13 -37
- package/{src/providers/aws/resources/generated/native/apigatewayv2/route/index.ts → providers/aws/generated/resources/apigatewayv2/route.ts} +23 -40
- package/{src/providers/aws/resources/generated/native/apigatewayv2/stage/index.ts → providers/aws/generated/resources/apigatewayv2/stage.ts} +13 -38
- package/providers/aws/generated/resources/iam/accesskey.ts +184 -0
- package/{src/providers/aws/resources/generated/native/iam/group/index.ts → providers/aws/generated/resources/iam/group.ts} +13 -38
- package/{src/providers/aws/resources/generated/native/iam/grouppolicy/index.ts → providers/aws/generated/resources/iam/grouppolicy.ts} +29 -59
- package/{src/providers/aws/resources/generated/native/iam/instanceprofile/index.ts → providers/aws/generated/resources/iam/instanceprofile.ts} +13 -41
- package/{src/providers/aws/resources/generated/native/iam/managedpolicy/index.ts → providers/aws/generated/resources/iam/managedpolicy.ts} +13 -95
- package/providers/aws/generated/resources/iam/oidcprovider.ts +314 -0
- package/{src/providers/aws/resources/generated/native/iam/policy/index.ts → providers/aws/generated/resources/iam/policy.ts} +13 -28
- package/{src/providers/aws/resources/generated/native/iam/role/index.ts → providers/aws/generated/resources/iam/role.ts} +13 -47
- package/{src/providers/aws/resources/generated/native/iam/rolepolicy/index.ts → providers/aws/generated/resources/iam/rolepolicy.ts} +29 -59
- package/providers/aws/generated/resources/iam/samlprovider.ts +463 -0
- package/providers/aws/generated/resources/iam/servercertificate.ts +465 -0
- package/providers/aws/generated/resources/iam/servicelinkedrole.ts +187 -0
- package/{src/providers/aws/resources/generated/native/iam/user/index.ts → providers/aws/generated/resources/iam/user.ts} +13 -38
- package/{src/providers/aws/resources/generated/native/iam/userpolicy/index.ts → providers/aws/generated/resources/iam/userpolicy.ts} +29 -59
- package/{src/providers/aws/resources/generated/native/iam/usertogroupaddition/index.ts → providers/aws/generated/resources/iam/usertogroupaddition.ts} +13 -27
- package/providers/aws/generated/resources/iam/virtualmfadevice.ts +298 -0
- package/{src/providers/aws/resources/generated/native/kms/key/index.ts → providers/aws/generated/resources/kms/key.ts} +13 -41
- package/{src/providers/aws/resources/generated/native/lambda/function/index.ts → providers/aws/generated/resources/lambda/function.ts} +13 -63
- package/{src/providers/aws/resources/generated/native/lambda/permission/index.ts → providers/aws/generated/resources/lambda/permission.ts} +13 -55
- package/{src/providers/aws/resources/generated/native/s3/bucket/index.ts → providers/aws/generated/resources/s3/bucket.ts} +14 -104
- package/{src/providers/aws/resources/generated/native/sns/topic/index.ts → providers/aws/generated/resources/sns/topic.ts} +14 -29
- package/{src/providers/aws/resources/generated/native/sqs/queue/index.ts → providers/aws/generated/resources/sqs/queue.ts} +14 -38
- package/{src/providers/aws/resources/generated/native/stepfunctions/statemachine/index.ts → providers/aws/generated/resources/stepfunctions/statemachine.ts} +15 -58
- package/providers/aws/management/mappings/iam/group.ts +63 -0
- package/providers/aws/management/mappings/iam/iamIdentity.ts +41 -0
- package/providers/aws/management/mappings/iam/iamLifecycleSettings.ts +8 -0
- package/providers/aws/management/mappings/iam/inlinePolicies.ts +159 -0
- package/providers/aws/management/mappings/iam/instanceProfile.ts +77 -0
- package/providers/aws/management/mappings/iam/oidcProvider.ts +94 -0
- package/providers/aws/management/mappings/iam/role.ts +74 -0
- package/providers/aws/management/mappings/iam/samlProvider.ts +98 -0
- package/providers/aws/management/mappings/iam/serverCertificate.ts +72 -0
- package/providers/aws/management/mappings/iam/user.ts +61 -0
- package/providers/aws/management/mappings/iam/userToGroupAddition.ts +75 -0
- package/providers/aws/management/operations/iam/accessKey.ts +206 -0
- package/providers/aws/management/operations/iam/managedPolicy.ts +491 -0
- package/providers/aws/management/operations/iam/policy.ts +476 -0
- package/providers/aws/management/operations/iam/serviceLinkedRole.ts +172 -0
- package/providers/aws/management/operations/iam/virtualMfaDevice.ts +253 -0
- package/providers/aws/management/resourceAssociationConfiguration.ts +112 -0
- package/providers/aws/management/resourceAssociationRegistration.ts +349 -0
- package/providers/aws/management/resourceAssociations.ts +168 -0
- package/{src/providers → providers}/aws/management/resourceConfiguration.ts +24 -26
- package/providers/aws/management/resourceLifecycleRegistration.ts +540 -0
- package/providers/aws/management/resourceManagementModule.ts +31 -0
- package/providers/aws/management/resourceManagementRegistry.ts +62 -0
- package/providers/aws/management/resourceMapping.ts +84 -0
- package/providers/aws/management/resourceOperation.ts +134 -0
- package/providers/aws/management/resourceTagOperations.ts +108 -0
- package/providers/aws/management/resourceTiming.ts +4 -0
- package/providers/aws/runtime.ts +52 -0
- package/src/core/resource/resourceCommandPolicy.ts +20 -0
- package/src/core/resource/resourceLifecycle.ts +644 -0
- package/src/core/resource/resourceStabilization.ts +120 -0
- package/src/core/resource/resourceVersions.ts +102 -0
- package/src/core/stack/planner.ts +9 -0
- package/src/core/stack/resourceStackLifecycle.ts +36 -3
- package/src/core/state/resourceState.ts +6 -4
- package/src/core/state/stateStore.ts +57 -10
- package/src/providers/file/resourcePolicy.ts +13 -12
- package/src/providers/providerRuntimeLayer.ts +5 -2
- package/src/providers/resourceCommandPolicyLayer.ts +117 -37
- package/src/providers/stripe/management/resourcePolicy.ts +22 -11
- package/examples/http-echo/application.ts +0 -87
- package/src/providers/aws/client/awsClient.ts +0 -418
- package/src/providers/aws/client/awsClientConfig.ts +0 -133
- package/src/providers/aws/client/awsClientModel.ts +0 -119
- package/src/providers/aws/client/awsHttpOperation.ts +0 -153
- package/src/providers/aws/client/awsQueryOperation.ts +0 -149
- package/src/providers/aws/client/awsRequestSigner.ts +0 -115
- package/src/providers/aws/client/awsResponseDecoder.ts +0 -135
- package/src/providers/aws/client/awsRetryPolicy.ts +0 -62
- package/src/providers/aws/client/generated/apiGatewayV2.ts +0 -3025
- package/src/providers/aws/client/generated/cloudControl.ts +0 -5746
- package/src/providers/aws/client/generated/iam.ts +0 -10892
- package/src/providers/aws/client/generated/lambda.ts +0 -5403
- package/src/providers/aws/client/generated/sqs.ts +0 -3769
- package/src/providers/aws/client/generated/stepFunctions.ts +0 -1726
- package/src/providers/aws/client/openapi/cloudControl/CancelResourceRequest.json +0 -579
- package/src/providers/aws/client/openapi/cloudControl/CreateResource.json +0 -1019
- package/src/providers/aws/client/openapi/cloudControl/DeleteResource.json +0 -1018
- package/src/providers/aws/client/openapi/cloudControl/GetResource.json +0 -883
- package/src/providers/aws/client/openapi/cloudControl/GetResourceRequestStatus.json +0 -655
- package/src/providers/aws/client/openapi/cloudControl/ListResourceRequests.json +0 -566
- package/src/providers/aws/client/openapi/cloudControl/ListResources.json +0 -913
- package/src/providers/aws/client/openapi/cloudControl/UpdateResource.json +0 -1027
- package/src/providers/aws/cloudControl/client.ts +0 -69
- package/src/providers/aws/cloudControl/requestTracker.ts +0 -138
- package/src/providers/aws/cloudControl/resourceCommandPolicyLayer.ts +0 -63
- package/src/providers/aws/cloudControl/resourceLifecycle.ts +0 -479
- package/src/providers/aws/cloudControl/resources/generated/certificatemanager/certificate/index.ts +0 -179
- package/src/providers/aws/cloudControl/resources/generated/kms/key/index.ts +0 -362
- package/src/providers/aws/cloudControl/resources/generated/s3/bucket/index.ts +0 -2364
- package/src/providers/aws/cloudControl/resources/generated/sns/topic/index.ts +0 -326
- package/src/providers/aws/cloudControl/resources/generated/sqs/queue/index.ts +0 -307
- package/src/providers/aws/cloudControl/resources/generated/sqs/queueinlinepolicy/index.ts +0 -108
- package/src/providers/aws/cloudControl/runtime.ts +0 -127
- package/src/providers/aws/management/resourceMapping.ts +0 -343
- package/src/providers/aws/management/resourceOperation.ts +0 -57
- package/src/providers/aws/management/resourcePolicy.ts +0 -549
- package/src/providers/aws/management/resourceRegistration.ts +0 -294
- package/src/providers/aws/resources/apiGatewayV2/httpApi.ts +0 -327
- package/src/providers/aws/resources/generated/native/resourceCommands.ts +0 -152
- package/src/providers/aws/resources/iam/grant.ts +0 -150
- package/src/providers/aws/resources/iam/grantCommands.ts +0 -283
- package/src/providers/aws/resources/iam/policyDocument.ts +0 -30
- package/src/providers/aws/resources/iam/policyStatement.ts +0 -59
- package/src/providers/aws/resources/iam/role.ts +0 -426
- package/src/providers/aws/resources/iam/roleDeclaration.ts +0 -105
- package/src/providers/aws/resources/lambda/function.ts +0 -403
- package/src/providers/aws/resources/lambda/functionDeclaration.ts +0 -234
- package/src/providers/aws/resources/lambda/permission.ts +0 -363
- package/src/providers/aws/resources/stepFunctions/stateMachine.ts +0 -95
- package/src/providers/aws/runtime.ts +0 -70
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Context,
|
|
3
|
+
type Duration,
|
|
4
|
+
Effect,
|
|
5
|
+
flow,
|
|
6
|
+
Layer,
|
|
7
|
+
Option,
|
|
8
|
+
Schedule,
|
|
9
|
+
} from "effect";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The ResourceStabilization service lets resource policies wait for provider
|
|
13
|
+
* changes to become visible. The runtime sets the interval between attempts.
|
|
14
|
+
*
|
|
15
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/Context.ts (Service)
|
|
16
|
+
*/
|
|
17
|
+
export class ResourceStabilization extends Context.Service<ResourceStabilization>()(
|
|
18
|
+
"nomoss/core/resource/resourceStabilization",
|
|
19
|
+
{
|
|
20
|
+
make: (interval: Duration.Input) =>
|
|
21
|
+
Effect.sync(() => {
|
|
22
|
+
const schedule = Schedule.spaced(interval);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The waitFor function returns the first observation that satisfies
|
|
26
|
+
* the condition. A provider failure or an expired deadline fails the wait.
|
|
27
|
+
*
|
|
28
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/Effect.ts (repeat and timeout)
|
|
29
|
+
*/
|
|
30
|
+
const waitFor = <A>(
|
|
31
|
+
accepts: (state: A) => boolean,
|
|
32
|
+
timeout: Duration.Input,
|
|
33
|
+
) => {
|
|
34
|
+
const policy = { until: accepts, schedule };
|
|
35
|
+
|
|
36
|
+
return flow(
|
|
37
|
+
Effect.repeat<typeof policy, A>(policy),
|
|
38
|
+
Effect.timeout(timeout),
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The waitForPresence service method returns the first present
|
|
44
|
+
* observation. Callers can filter each read for the desired state.
|
|
45
|
+
*
|
|
46
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/Effect.ts (repeat and fromOption)
|
|
47
|
+
*/
|
|
48
|
+
const waitForPresence = <A>(timeout: Duration.Input) =>
|
|
49
|
+
flow(
|
|
50
|
+
waitFor<Option.Option<A>>(Option.isSome, timeout),
|
|
51
|
+
Effect.flatMap((state: Option.Option<A>) =>
|
|
52
|
+
Effect.fromOption(state),
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The waitForAbsence service method lets teardown complete once a provider
|
|
58
|
+
* read confirms the resource is gone. A failed read or an expired
|
|
59
|
+
* deadline leaves deletion unconfirmed.
|
|
60
|
+
*
|
|
61
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/Effect.ts (repeat)
|
|
62
|
+
*/
|
|
63
|
+
const waitForAbsence = (timeout: Duration.Input) =>
|
|
64
|
+
flow(
|
|
65
|
+
waitFor<Option.Option<unknown>>(Option.isNone, timeout),
|
|
66
|
+
Effect.asVoid,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The observeWithinAttempts service method returns the first matching
|
|
71
|
+
* observation or the final observation when the allowed repeats run
|
|
72
|
+
* out. The repeat count excludes the initial read. A provider error
|
|
73
|
+
* ends the wait.
|
|
74
|
+
*
|
|
75
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/Schedule.ts (upTo)
|
|
76
|
+
*/
|
|
77
|
+
const observeWithinAttempts = <A>(
|
|
78
|
+
accepts: (state: A) => boolean,
|
|
79
|
+
repeats: number,
|
|
80
|
+
) => {
|
|
81
|
+
const policy = {
|
|
82
|
+
until: accepts,
|
|
83
|
+
schedule: schedule.pipe(Schedule.upTo({ times: repeats })),
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return Effect.repeat<typeof policy, A>(policy);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The retrySchedule service method gives dependent resources time to
|
|
91
|
+
* become usable. The caller selects transient failures with Effect.retry.
|
|
92
|
+
* The schedule checks elapsed time before it schedules another attempt.
|
|
93
|
+
*
|
|
94
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/Effect.ts (retry)
|
|
95
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/Schedule.ts (upTo)
|
|
96
|
+
*/
|
|
97
|
+
const retrySchedule = (duration: Duration.Input) =>
|
|
98
|
+
schedule.pipe(Schedule.upTo({ duration }));
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
schedule,
|
|
102
|
+
waitForPresence,
|
|
103
|
+
waitForAbsence,
|
|
104
|
+
observeWithinAttempts,
|
|
105
|
+
retrySchedule,
|
|
106
|
+
};
|
|
107
|
+
}),
|
|
108
|
+
},
|
|
109
|
+
) {}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The resourceStabilizationLayer Layer sets a one-second interval for
|
|
113
|
+
* repeated reads and retries. Tests can advance these waits with TestClock.
|
|
114
|
+
*
|
|
115
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/Layer.ts (effect)
|
|
116
|
+
*/
|
|
117
|
+
export const resourceStabilizationLayer = Layer.effect(
|
|
118
|
+
ResourceStabilization,
|
|
119
|
+
ResourceStabilization.make("1 second"),
|
|
120
|
+
);
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Array as Arr,
|
|
3
|
+
Context,
|
|
4
|
+
Data,
|
|
5
|
+
DateTime,
|
|
6
|
+
Effect,
|
|
7
|
+
Layer,
|
|
8
|
+
Option,
|
|
9
|
+
Order,
|
|
10
|
+
} from "effect";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The ResourceVersion interface supplies the identity, age, and protection
|
|
14
|
+
* status for a version returned by the provider. A protected version stays
|
|
15
|
+
* in the inventory even when it is ineligible for removal.
|
|
16
|
+
*/
|
|
17
|
+
export interface ResourceVersion<Id extends string | number> {
|
|
18
|
+
readonly id: Id;
|
|
19
|
+
readonly createdAt: DateTime.Utc;
|
|
20
|
+
readonly protected: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The ResourceVersionCapacityUnavailable error tells the caller that
|
|
25
|
+
* publishing would require removal of a protected version.
|
|
26
|
+
*/
|
|
27
|
+
class ResourceVersionCapacityUnavailable extends Data.TaggedError(
|
|
28
|
+
"ResourceVersionCapacityUnavailable",
|
|
29
|
+
)<{ readonly limit: number }> {
|
|
30
|
+
override get message() {
|
|
31
|
+
return `The protected resource versions leave no room to publish within the limit of ${this.limit}.`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The ResourceVersions service selects which versions a provider may remove before
|
|
37
|
+
* publication or during teardown. Protected versions always count toward capacity.
|
|
38
|
+
*
|
|
39
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/Context.ts (Service)
|
|
40
|
+
*/
|
|
41
|
+
export class ResourceVersions extends Context.Service<ResourceVersions>()(
|
|
42
|
+
"nomoss/core/resource/resourceVersions",
|
|
43
|
+
{
|
|
44
|
+
make: Effect.sync(() => {
|
|
45
|
+
/**
|
|
46
|
+
* The selectForRetirement service method chooses the oldest eligible versions
|
|
47
|
+
* that must give way to a new publication. Teardown selects every eligible
|
|
48
|
+
* version. The caller supplies the complete inventory before deleting any version.
|
|
49
|
+
*
|
|
50
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/Array.ts (filter, sort, and take)
|
|
51
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/DateTime.ts (Order)
|
|
52
|
+
*/
|
|
53
|
+
const selectForRetirement = Effect.fn(
|
|
54
|
+
"ResourceVersions.selectForRetirement",
|
|
55
|
+
)(function* <Id extends string | number>(
|
|
56
|
+
inventory: ReadonlyArray<ResourceVersion<Id>>,
|
|
57
|
+
limit?: number,
|
|
58
|
+
) {
|
|
59
|
+
const eligible = Arr.filter(inventory, (version) => !version.protected);
|
|
60
|
+
const oldestFirst = Order.mapInput(
|
|
61
|
+
DateTime.Order,
|
|
62
|
+
(version: ResourceVersion<Id>) => version.createdAt,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const capacity = Option.fromUndefinedOr(limit).pipe(
|
|
66
|
+
Option.map((limit) => ({
|
|
67
|
+
limit,
|
|
68
|
+
needed: Math.max(inventory.length + 1 - limit, 0),
|
|
69
|
+
})),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
yield* capacity.pipe(
|
|
73
|
+
Option.filter(({ needed }) => eligible.length < needed),
|
|
74
|
+
Option.map(({ limit }) =>
|
|
75
|
+
Effect.fail(new ResourceVersionCapacityUnavailable({ limit })),
|
|
76
|
+
),
|
|
77
|
+
Effect.transposeOption,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const selected = Option.match(capacity, {
|
|
81
|
+
onNone: () => eligible,
|
|
82
|
+
onSome: ({ needed }) =>
|
|
83
|
+
Arr.take(Arr.sort(eligible, oldestFirst), needed),
|
|
84
|
+
});
|
|
85
|
+
return selected;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return { selectForRetirement };
|
|
89
|
+
}),
|
|
90
|
+
},
|
|
91
|
+
) {}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The resourceVersionsLayer Layer provides version management to the
|
|
95
|
+
* resource command runtime.
|
|
96
|
+
*
|
|
97
|
+
* @see ../../../../command-options-fund/refs/effect/packages/effect/src/Layer.ts (effect)
|
|
98
|
+
*/
|
|
99
|
+
export const resourceVersionsLayer = Layer.effect(
|
|
100
|
+
ResourceVersions,
|
|
101
|
+
ResourceVersions.make,
|
|
102
|
+
);
|
|
@@ -272,16 +272,19 @@ export class ResourcePlanner extends Context.Service<ResourcePlanner>()(id, {
|
|
|
272
272
|
onSome: (state) => resourceGeneration(state.node),
|
|
273
273
|
});
|
|
274
274
|
const target: ResourceNode = { ...node, generation };
|
|
275
|
+
|
|
275
276
|
const rule = Option.match(pending, {
|
|
276
277
|
onNone: () => node.schema.replacement,
|
|
277
278
|
onSome: (state) => state.node.schema.replacement,
|
|
278
279
|
});
|
|
279
280
|
const create = PlanAction.Create({ node: target });
|
|
280
281
|
const remove = PlanAction.Destroy({ node: current });
|
|
282
|
+
//CLEANUP_Q [DERAIL] The planner groups both steps before dependent updates. An IAM role with a managed inline policy must keep its previous instance until the policy has moved.
|
|
281
283
|
const ordered = Match.value(rule?.order).pipe(
|
|
282
284
|
Match.when("createBeforeDestroy", () => [create, remove]),
|
|
283
285
|
Match.orElse(() => [remove, create]),
|
|
284
286
|
);
|
|
287
|
+
|
|
285
288
|
const operations = Arr.filter(
|
|
286
289
|
ordered,
|
|
287
290
|
Predicate.not((operation: typeof create | typeof remove) =>
|
|
@@ -311,6 +314,7 @@ export class ResourcePlanner extends Context.Service<ResourcePlanner>()(id, {
|
|
|
311
314
|
|
|
312
315
|
return PlanAction.Replace({ node: target, current, operations });
|
|
313
316
|
};
|
|
317
|
+
|
|
314
318
|
/**
|
|
315
319
|
* The selectCreateOrUpdateActions helper keeps a dependent resource in the
|
|
316
320
|
* plan when an earlier action may change its request values. Execution must
|
|
@@ -325,6 +329,7 @@ export class ResourcePlanner extends Context.Service<ResourcePlanner>()(id, {
|
|
|
325
329
|
): ReadonlyArray<SelectedAction> => {
|
|
326
330
|
const currentByKey = currentResourcesByKey(current);
|
|
327
331
|
const ordered = Arr.fromIterable(Graph.topo(desired));
|
|
332
|
+
|
|
328
333
|
const selected = Arr.reduce(
|
|
329
334
|
ordered,
|
|
330
335
|
HashMap.empty<Graph.NodeIndex, SelectedAction>(),
|
|
@@ -346,6 +351,7 @@ export class ResourcePlanner extends Context.Service<ResourcePlanner>()(id, {
|
|
|
346
351
|
),
|
|
347
352
|
),
|
|
348
353
|
);
|
|
354
|
+
|
|
349
355
|
return Option.match(HashMap.get(currentByKey, node.key.logicalId), {
|
|
350
356
|
onNone: () =>
|
|
351
357
|
HashMap.set(selected, index, {
|
|
@@ -385,6 +391,7 @@ export class ResourcePlanner extends Context.Service<ResourcePlanner>()(id, {
|
|
|
385
391
|
resourceGeneration(candidate),
|
|
386
392
|
),
|
|
387
393
|
);
|
|
394
|
+
|
|
388
395
|
const action = Match.value(
|
|
389
396
|
Predicate.or(
|
|
390
397
|
() => Option.isSome(pending),
|
|
@@ -414,10 +421,12 @@ export class ResourcePlanner extends Context.Service<ResourcePlanner>()(id, {
|
|
|
414
421
|
});
|
|
415
422
|
},
|
|
416
423
|
);
|
|
424
|
+
|
|
417
425
|
const actions: ReadonlyArray<SelectedAction> = Arr.flatMap(
|
|
418
426
|
ordered,
|
|
419
427
|
([index]) => HashMap.get(selected, index).pipe(Option.toArray),
|
|
420
428
|
);
|
|
429
|
+
|
|
421
430
|
return actions;
|
|
422
431
|
};
|
|
423
432
|
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
resourceInstanceKey,
|
|
36
36
|
} from "../resource/model.js";
|
|
37
37
|
import {
|
|
38
|
+
ResourceCommandCreation,
|
|
38
39
|
ResourceCommandPolicy,
|
|
39
40
|
ResourceCommandProgress,
|
|
40
41
|
ResourceCommandStackName,
|
|
@@ -238,7 +239,8 @@ export class ResourceStackLifecycle extends Context.Service<ResourceStackLifecyc
|
|
|
238
239
|
|
|
239
240
|
yield* stateStore.markResourceStarted(stackName, action);
|
|
240
241
|
|
|
241
|
-
const resources
|
|
242
|
+
const { resources, states } =
|
|
243
|
+
yield* stateStore.loadSnapshot(stackName);
|
|
242
244
|
|
|
243
245
|
const resolvedAction: ResourceOperation = yield* resolveAction(
|
|
244
246
|
graph,
|
|
@@ -269,6 +271,35 @@ export class ResourceStackLifecycle extends Context.Service<ResourceStackLifecyc
|
|
|
269
271
|
Match.orElse(() => Option.none<ResourceNode>()),
|
|
270
272
|
);
|
|
271
273
|
|
|
274
|
+
const submitted = Arr.findFirst(
|
|
275
|
+
states,
|
|
276
|
+
(state) =>
|
|
277
|
+
state._tag === "Creating" &&
|
|
278
|
+
state.submitted === true &&
|
|
279
|
+
resourceInstanceKey(state.node) ===
|
|
280
|
+
resourceInstanceKey(resolvedAction.node),
|
|
281
|
+
).pipe(Option.map(({ node }) => node));
|
|
282
|
+
|
|
283
|
+
yield* submitted.pipe(
|
|
284
|
+
Option.filter(
|
|
285
|
+
(node) => !model.propsEqual(node, resolvedAction.node),
|
|
286
|
+
),
|
|
287
|
+
Option.map(() =>
|
|
288
|
+
Effect.fail(
|
|
289
|
+
new ResourceOperationInProgress({
|
|
290
|
+
logicalId: action.node.key.logicalId,
|
|
291
|
+
}),
|
|
292
|
+
),
|
|
293
|
+
),
|
|
294
|
+
Effect.transposeOption,
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
const creation = Option.some({
|
|
298
|
+
submitted,
|
|
299
|
+
record: (node: ResourceNode) =>
|
|
300
|
+
stateStore.recordResourceCreation(stackName, node),
|
|
301
|
+
});
|
|
302
|
+
|
|
272
303
|
yield* Effect.annotateCurrentSpan({
|
|
273
304
|
"nomoss.resource.inputs_unchanged": Option.isSome(unchanged),
|
|
274
305
|
});
|
|
@@ -283,8 +314,9 @@ export class ResourceStackLifecycle extends Context.Service<ResourceStackLifecyc
|
|
|
283
314
|
Match.exhaustive,
|
|
284
315
|
);
|
|
285
316
|
|
|
286
|
-
// The applyAction operation
|
|
287
|
-
//
|
|
317
|
+
// The applyAction operation keeps the stack's recovery data available
|
|
318
|
+
// to the provider. A retried create can reuse its physical name or
|
|
319
|
+
// confirm the provider identity already saved for that generation.
|
|
288
320
|
const result = yield* policy
|
|
289
321
|
.execute(ResourceCommand.Apply({ decision }))
|
|
290
322
|
.pipe(
|
|
@@ -292,6 +324,7 @@ export class ResourceStackLifecycle extends Context.Service<ResourceStackLifecyc
|
|
|
292
324
|
ResourceCommandStackName,
|
|
293
325
|
Option.some(stackName),
|
|
294
326
|
),
|
|
327
|
+
Effect.provideService(ResourceCommandCreation, creation),
|
|
295
328
|
Effect.interruptible,
|
|
296
329
|
Effect.tapErrorTag(
|
|
297
330
|
"ResourceCommandExecutionFailed",
|
|
@@ -13,14 +13,16 @@ export const ResourceFailureSchema = Schema.Struct({
|
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* The ResourceStateSchema schema
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* The ResourceStateSchema schema lets the stack resume a submitted creation
|
|
17
|
+
* with the identity the provider already returned. Until confirmation, the
|
|
18
|
+
* stack can remove that instance and keeps its outputs unavailable to
|
|
19
|
+
* dependents. An unfinished update retains the previous applied node, and a
|
|
20
|
+
* completed removal remains recorded until the containing operation commits.
|
|
20
21
|
*/
|
|
21
22
|
export const ResourceStateSchema = Schema.Union([
|
|
22
23
|
Schema.TaggedStruct("Creating", {
|
|
23
24
|
node: ResourceNodeSchema,
|
|
25
|
+
submitted: Schema.optionalKey(Schema.Literal(true)),
|
|
24
26
|
startedAt: Schema.NonEmptyString,
|
|
25
27
|
lastFailure: Schema.optional(ResourceFailureSchema),
|
|
26
28
|
}),
|
|
@@ -100,10 +100,10 @@ export class ResourceStateStore extends Context.Service<ResourceStateStore>()(
|
|
|
100
100
|
);
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
* The ownedResources service method
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
103
|
+
* The ownedResources service method includes instances that teardown can
|
|
104
|
+
* locate from saved state. An accepted creation qualifies once its
|
|
105
|
+
* provider identity is saved, even if confirmation has yet to finish.
|
|
106
|
+
* An unfinished update still uses the last applied identity.
|
|
107
107
|
*/
|
|
108
108
|
const ownedResources = (
|
|
109
109
|
states: ReadonlyArray<ResourceState>,
|
|
@@ -112,7 +112,11 @@ export class ResourceStateStore extends Context.Service<ResourceStateStore>()(
|
|
|
112
112
|
Match.value(state).pipe(
|
|
113
113
|
Match.tag("Created", "Updated", "Deleting", ({ node }) => [node]),
|
|
114
114
|
Match.tag("Updating", ({ previous }) => [previous]),
|
|
115
|
-
Match.
|
|
115
|
+
Match.when({ _tag: "Creating", submitted: true }, ({ node }) => [
|
|
116
|
+
node,
|
|
117
|
+
]),
|
|
118
|
+
Match.tag("Creating", () => []),
|
|
119
|
+
Match.tag("Deleted", () => []),
|
|
116
120
|
Match.exhaustive,
|
|
117
121
|
),
|
|
118
122
|
);
|
|
@@ -300,10 +304,10 @@ export class ResourceStateStore extends Context.Service<ResourceStateStore>()(
|
|
|
300
304
|
);
|
|
301
305
|
|
|
302
306
|
/**
|
|
303
|
-
* The markResourceStarted service method
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* the
|
|
307
|
+
* The markResourceStarted service method identifies work by resource
|
|
308
|
+
* generation. Starting the same creation again preserves any provider
|
|
309
|
+
* identity already recorded for that generation. A replacement keeps
|
|
310
|
+
* the previous generation available for teardown.
|
|
307
311
|
*/
|
|
308
312
|
const markResourceStarted = Effect.fn(
|
|
309
313
|
"ResourceStateStore.markResourceStarted",
|
|
@@ -316,7 +320,17 @@ export class ResourceStateStore extends Context.Service<ResourceStateStore>()(
|
|
|
316
320
|
|
|
317
321
|
const resourceState: ResourceState = Match.value(action).pipe(
|
|
318
322
|
Match.tag("Create", ({ node }) =>
|
|
319
|
-
|
|
323
|
+
Arr.findFirst(
|
|
324
|
+
states,
|
|
325
|
+
(state) =>
|
|
326
|
+
state._tag === "Creating" &&
|
|
327
|
+
state.submitted === true &&
|
|
328
|
+
resourceInstanceKey(state.node) === resourceInstanceKey(node),
|
|
329
|
+
).pipe(
|
|
330
|
+
Option.getOrElse(() =>
|
|
331
|
+
ResourceStateSchema.make({ _tag: "Creating", node, startedAt }),
|
|
332
|
+
),
|
|
333
|
+
),
|
|
320
334
|
),
|
|
321
335
|
Match.tag("Update", ({ node, current }) =>
|
|
322
336
|
ResourceStateSchema.make({
|
|
@@ -345,6 +359,38 @@ export class ResourceStateStore extends Context.Service<ResourceStateStore>()(
|
|
|
345
359
|
yield* persistResourceStates(stack, resourceStates);
|
|
346
360
|
}, changes.withPermits(1));
|
|
347
361
|
|
|
362
|
+
/**
|
|
363
|
+
* The recordResourceCreation service method requires an active creation
|
|
364
|
+
* for the supplied generation. The saved identity is available to
|
|
365
|
+
* teardown, and dependent resources must wait for confirmation before
|
|
366
|
+
* they can use the outputs.
|
|
367
|
+
*
|
|
368
|
+
* @see ../../../node_modules/effect/src/Semaphore.ts (withPermits)
|
|
369
|
+
*/
|
|
370
|
+
const recordResourceCreation = Effect.fn(
|
|
371
|
+
"ResourceStateStore.recordResourceCreation",
|
|
372
|
+
)(function* (stack: string, node: ResourceNode) {
|
|
373
|
+
const states = yield* restoreResourceStates(stack);
|
|
374
|
+
const active = yield* Arr.findFirst(
|
|
375
|
+
states,
|
|
376
|
+
(state): state is Extract<ResourceState, { _tag: "Creating" }> =>
|
|
377
|
+
state._tag === "Creating" &&
|
|
378
|
+
resourceInstanceKey(state.node) === resourceInstanceKey(node),
|
|
379
|
+
).pipe(Effect.fromOption);
|
|
380
|
+
|
|
381
|
+
yield* persistResourceStates(
|
|
382
|
+
stack,
|
|
383
|
+
Arr.map(states, (state) =>
|
|
384
|
+
Match.value(state === active).pipe(
|
|
385
|
+
Match.when(true, () =>
|
|
386
|
+
ResourceStateSchema.make({ ...active, node, submitted: true }),
|
|
387
|
+
),
|
|
388
|
+
Match.orElse(() => state),
|
|
389
|
+
),
|
|
390
|
+
),
|
|
391
|
+
);
|
|
392
|
+
}, changes.withPermits(1));
|
|
393
|
+
|
|
348
394
|
/**
|
|
349
395
|
* The markResourceApplied service method requires a validated node and
|
|
350
396
|
* its completed operation status. Its saved result belongs to that node's
|
|
@@ -529,6 +575,7 @@ export class ResourceStateStore extends Context.Service<ResourceStateStore>()(
|
|
|
529
575
|
saveResourceStates,
|
|
530
576
|
saveResources,
|
|
531
577
|
markResourceStarted,
|
|
578
|
+
recordResourceCreation,
|
|
532
579
|
markResourceApplied,
|
|
533
580
|
deleteResourceState,
|
|
534
581
|
completeResourceActions,
|
|
@@ -13,8 +13,10 @@ import {
|
|
|
13
13
|
readResourceSchemaAnnotation,
|
|
14
14
|
resourceModelLayer,
|
|
15
15
|
} from "../../core/resource/model.js";
|
|
16
|
-
import {
|
|
17
|
-
|
|
16
|
+
import {
|
|
17
|
+
providerCommandPolicyTag,
|
|
18
|
+
registerResourceCommands,
|
|
19
|
+
} from "../resourceCommandPolicyLayer.js";
|
|
18
20
|
import { JsonFile, jsonFileLayer } from "./jsonFile.js";
|
|
19
21
|
import type { JsonFileResourceDefinition } from "./model.js";
|
|
20
22
|
|
|
@@ -92,6 +94,7 @@ export class JsonFileResourcePolicy extends Context.Service<JsonFileResourcePoli
|
|
|
92
94
|
node: ResourceNode,
|
|
93
95
|
) {
|
|
94
96
|
const outputPath = yield* savedPath(definition, node);
|
|
97
|
+
|
|
95
98
|
const document = yield* files.read(
|
|
96
99
|
outputPath,
|
|
97
100
|
definition.documentSchema,
|
|
@@ -101,6 +104,7 @@ export class JsonFileResourcePolicy extends Context.Service<JsonFileResourcePoli
|
|
|
101
104
|
onNone: () => ResourceObservation.Missing({ node }),
|
|
102
105
|
onSome: (observed) => ResourceObservation.Present({ node, observed }),
|
|
103
106
|
});
|
|
107
|
+
|
|
104
108
|
const result: ResourceCommandResult = ResourceCommandResult.Observed({
|
|
105
109
|
observation,
|
|
106
110
|
});
|
|
@@ -209,9 +213,7 @@ export class JsonFileResourcePolicy extends Context.Service<JsonFileResourcePoli
|
|
|
209
213
|
* The execute service method lets command dispatch observe a managed file,
|
|
210
214
|
* apply a reviewed change, or tear it down. Direct Diff, Create, Update,
|
|
211
215
|
* and Delete commands fail with ResourceCommandUnsupported because file
|
|
212
|
-
* mutations require an Apply decision.
|
|
213
|
-
* ResourceCommandExecutionFailed with the original command and cause so
|
|
214
|
-
* the stack can identify the resource and preserve recovery information.
|
|
216
|
+
* mutations require an Apply decision.
|
|
215
217
|
*/
|
|
216
218
|
const execute = Effect.fn("JsonFileResourcePolicy.execute")(function* (
|
|
217
219
|
definition: JsonFileResourceDefinition,
|
|
@@ -225,9 +227,6 @@ export class JsonFileResourcePolicy extends Context.Service<JsonFileResourcePoli
|
|
|
225
227
|
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
226
228
|
),
|
|
227
229
|
Match.exhaustive,
|
|
228
|
-
Effect.mapError(
|
|
229
|
-
(cause) => new ResourceCommandExecutionFailed({ command, cause }),
|
|
230
|
-
),
|
|
231
230
|
);
|
|
232
231
|
|
|
233
232
|
return result;
|
|
@@ -258,13 +257,15 @@ export const jsonFileResourcePolicyLayer = Layer.effect(
|
|
|
258
257
|
export const jsonFileResourcePolicyRegistration = (
|
|
259
258
|
definition: JsonFileResourceDefinition,
|
|
260
259
|
) =>
|
|
261
|
-
Layer.
|
|
260
|
+
Layer.effectContext(
|
|
262
261
|
Effect.gen(function* () {
|
|
263
262
|
const policy = yield* JsonFileResourcePolicy;
|
|
263
|
+
|
|
264
264
|
const schema = yield* policy.register(definition);
|
|
265
265
|
|
|
266
|
-
return
|
|
267
|
-
|
|
268
|
-
|
|
266
|
+
return registerResourceCommands(
|
|
267
|
+
(command) => policy.execute(definition, command),
|
|
268
|
+
providerCommandPolicyTag(schema),
|
|
269
|
+
);
|
|
269
270
|
}),
|
|
270
271
|
).pipe(Layer.provide(jsonFileResourcePolicyLayer));
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { NodeServices } from "@effect/platform-node";
|
|
2
|
+
import { awsClientConfigurationLayerLive } from "@tradedal/aws-credentials";
|
|
2
3
|
import { Layer } from "effect";
|
|
4
|
+
import { awsServiceResourceCommandLayer } from "../../providers/aws/runtime.js";
|
|
3
5
|
import { resourceStackRuntimeLayer } from "../core/runtime/stackRuntimeLayer.js";
|
|
4
6
|
import { ConfiguredStateSecretServiceLayer } from "../core/state/stateSecretService.js";
|
|
5
7
|
import { resourceStateFileStorageLayer } from "../core/state/stateStore.js";
|
|
6
|
-
import { awsCloudControlResourceCommandLayerLive } from "./aws/cloudControl/runtime.js";
|
|
7
8
|
import { providerResourceCommandPolicyLayerLive } from "./resourceCommandPolicyLayer.js";
|
|
8
9
|
import { stripeResourcesLayer } from "./stripe/management/resources.js";
|
|
9
10
|
import { stripeResourceCommandLayerLive } from "./stripe/runtime.js";
|
|
@@ -11,7 +12,9 @@ import { stripeResourceCommandLayerLive } from "./stripe/runtime.js";
|
|
|
11
12
|
const providerCommandsLayer = providerResourceCommandPolicyLayerLive.pipe(
|
|
12
13
|
Layer.provideMerge([
|
|
13
14
|
stripeResourceCommandLayerLive,
|
|
14
|
-
|
|
15
|
+
awsServiceResourceCommandLayer.pipe(
|
|
16
|
+
Layer.provide(awsClientConfigurationLayerLive),
|
|
17
|
+
),
|
|
15
18
|
]),
|
|
16
19
|
);
|
|
17
20
|
|