@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 74 lines 2.72 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Group, GroupMembership, InstanceProfile, Role, User } from "@alchemy.run/aws/IAM";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as IAM from "@distilled.cloud/aws/iam";
6 import * as Effect from "effect/Effect";
7
8 const { test } = Test.make({ providers: AWS.providers() });
9
10 test.provider(
11 "create user, group membership, and instance profile",
12 (stack) =>
13 Effect.gen(function* () {
14 yield* stack.destroy();
15
16 const resources = yield* stack.deploy(
17 Effect.gen(function* () {
18 const role = yield* Role("ProfileRole", {
19 assumeRolePolicyDocument: {
20 Version: "2012-10-17",
21 Statement: [
22 {
23 Effect: "Allow",
24 Principal: { Service: "ec2.amazonaws.com" },
25 Action: ["sts:AssumeRole"],
26 },
27 ],
28 },
29 });
30 const user = yield* User("IamUser", { tags: { env: "test" } });
31 const group = yield* Group("IamGroup", {});
32 const membership = yield* GroupMembership("IamMembership", {
33 groupName: group.groupName,
34 userNames: [user.userName],
35 });
36 const profile = yield* InstanceProfile("IamInstanceProfile", {
37 roleName: role.roleName,
38 tags: { env: "test" },
39 });
40
41 return { user, group, membership, profile, role };
42 }),
43 );
44
45 const group = yield* IAM.getGroup({ GroupName: resources.group.groupName });
46 expect(group.Users.some((user) => user.UserName === resources.user.userName)).toBe(true);
47
48 const profile = yield* IAM.getInstanceProfile({
49 InstanceProfileName: resources.profile.instanceProfileName,
50 });
51 expect(profile.InstanceProfile.Roles[0]?.RoleName).toBe(resources.role.roleName);
52
53 yield* stack.destroy();
54
55 // Everything the stack created is gone.
56 const deletedUser = yield* IAM.getUser({ UserName: resources.user.userName }).pipe(
57 Effect.option,
58 );
59 expect(deletedUser._tag).toBe("None");
60 const deletedGroup = yield* IAM.getGroup({ GroupName: resources.group.groupName }).pipe(
61 Effect.option,
62 );
63 expect(deletedGroup._tag).toBe("None");
64 const deletedProfile = yield* IAM.getInstanceProfile({
65 InstanceProfileName: resources.profile.instanceProfileName,
66 }).pipe(Effect.option);
67 expect(deletedProfile._tag).toBe("None");
68 const deletedRole = yield* IAM.getRole({ RoleName: resources.role.roleName }).pipe(
69 Effect.option,
70 );
71 expect(deletedRole._tag).toBe("None");
72 }),
73 { tags: ["provider:aws", "provider:aws:iam", "live"] },
74 );