@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 161 lines 6.42 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Domain, EnvironmentBlueprintConfiguration } from "@alchemy.run/aws/DataZone";
3 import * as IAM from "@alchemy.run/aws/IAM";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as datazone from "@distilled.cloud/aws/datazone";
7 import * as Effect from "effect/Effect";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 const findConfiguration = (domainId: string, blueprintId: string) =>
12 datazone
13 .getEnvironmentBlueprintConfiguration({
14 domainIdentifier: domainId,
15 environmentBlueprintIdentifier: blueprintId,
16 })
17 .pipe(
18 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
19 // once the domain is deleted, DataZone reports AccessDenied (auth is
20 // checked before existence) — also "absent".
21 Effect.catchTag("AccessDeniedException", () => Effect.succeed(undefined)),
22 );
23
24 test.provider(
25 "enable the DefaultDataLake blueprint in a domain, then remove it",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 // 1. Deploy a domain, the provisioning/manage-access roles, and the
31 // blueprint configuration.
32 const result = yield* stack.deploy(
33 Effect.gen(function* () {
34 const domain = yield* Domain("BlueprintTestDomain", {
35 description: "alchemy datazone blueprint config test",
36 });
37 const provisioningRole = yield* IAM.Role("DataZoneProvisioningRole", {
38 assumeRolePolicyDocument: {
39 Version: "2012-10-17",
40 Statement: [
41 {
42 Effect: "Allow",
43 Principal: { Service: "cloudformation.amazonaws.com" },
44 Action: ["sts:AssumeRole"],
45 },
46 ],
47 },
48 managedPolicyArns: [
49 "arn:aws:iam::aws:policy/AmazonDataZoneRedshiftGlueProvisioningPolicy",
50 ],
51 });
52 const manageAccessRole = yield* IAM.Role("DataZoneManageAccessRole", {
53 assumeRolePolicyDocument: {
54 Version: "2012-10-17",
55 Statement: [
56 {
57 Effect: "Allow",
58 Principal: { Service: "datazone.amazonaws.com" },
59 Action: ["sts:AssumeRole", "sts:TagSession"],
60 },
61 ],
62 },
63 managedPolicyArns: [
64 "arn:aws:iam::aws:policy/service-role/AmazonDataZoneGlueManageAccessRolePolicy",
65 ],
66 });
67 const config = yield* EnvironmentBlueprintConfiguration("DataLakeBlueprint", {
68 domainId: domain.domainId,
69 environmentBlueprint: "DefaultDataLake",
70 enabledRegions: ["us-west-2"],
71 provisioningRoleArn: provisioningRole.roleArn,
72 manageAccessRoleArn: manageAccessRole.roleArn,
73 });
74 return {
75 domainId: domain.domainId,
76 environmentBlueprintId: config.environmentBlueprintId,
77 environmentBlueprintName: config.environmentBlueprintName,
78 enabledRegions: config.enabledRegions,
79 provisioningRoleArn: config.provisioningRoleArn,
80 manageAccessRoleArn: config.manageAccessRoleArn,
81 };
82 }),
83 );
84
85 expect(result.environmentBlueprintName).toBe("DefaultDataLake");
86 expect(result.environmentBlueprintId).toBeDefined();
87 expect(result.enabledRegions).toEqual(["us-west-2"]);
88
89 // out-of-band: the configuration exists with the requested roles.
90 const created = yield* findConfiguration(result.domainId, result.environmentBlueprintId);
91 expect(created).toBeDefined();
92 expect(created!.enabledRegions).toEqual(["us-west-2"]);
93 expect(created!.provisioningRoleArn).toBe(result.provisioningRoleArn);
94 expect(created!.manageAccessRoleArn).toBe(result.manageAccessRoleArn);
95
96 // 2. Update — the PUT converges regional parameters in place.
97 yield* stack.deploy(
98 Effect.gen(function* () {
99 const domain = yield* Domain("BlueprintTestDomain", {
100 description: "alchemy datazone blueprint config test",
101 });
102 const provisioningRole = yield* IAM.Role("DataZoneProvisioningRole", {
103 assumeRolePolicyDocument: {
104 Version: "2012-10-17",
105 Statement: [
106 {
107 Effect: "Allow",
108 Principal: { Service: "cloudformation.amazonaws.com" },
109 Action: ["sts:AssumeRole"],
110 },
111 ],
112 },
113 managedPolicyArns: [
114 "arn:aws:iam::aws:policy/AmazonDataZoneRedshiftGlueProvisioningPolicy",
115 ],
116 });
117 const manageAccessRole = yield* IAM.Role("DataZoneManageAccessRole", {
118 assumeRolePolicyDocument: {
119 Version: "2012-10-17",
120 Statement: [
121 {
122 Effect: "Allow",
123 Principal: { Service: "datazone.amazonaws.com" },
124 Action: ["sts:AssumeRole", "sts:TagSession"],
125 },
126 ],
127 },
128 managedPolicyArns: [
129 "arn:aws:iam::aws:policy/service-role/AmazonDataZoneGlueManageAccessRolePolicy",
130 ],
131 });
132 yield* EnvironmentBlueprintConfiguration("DataLakeBlueprint", {
133 domainId: domain.domainId,
134 environmentBlueprint: "DefaultDataLake",
135 enabledRegions: ["us-west-2"],
136 provisioningRoleArn: provisioningRole.roleArn,
137 manageAccessRoleArn: manageAccessRole.roleArn,
138 regionalParameters: {
139 "us-west-2": { S3Location: "s3://alchemy-datazone-test" },
140 },
141 });
142 }),
143 );
144
145 const updated = yield* findConfiguration(result.domainId, result.environmentBlueprintId);
146 expect(updated!.regionalParameters?.["us-west-2"]?.S3Location).toBe(
147 "s3://alchemy-datazone-test",
148 );
149
150 // 3. Destroy — the configuration is deleted (before its domain). The
151 // domain delete waits until the domain is gone, so the config
152 // lookup must observe "absent" immediately after destroy.
153 yield* stack.destroy();
154 const gone = yield* findConfiguration(result.domainId, result.environmentBlueprintId);
155 expect(gone).toBeUndefined();
156 }),
157 {
158 tags: ["provider:aws", "provider:aws:datazone", "provider:aws:iam", "live"],
159 timeout: 480_000,
160 },
161 );