| 1 | import * as AWS from "@/AWS"; |
| 2 | import { Region } from "@/AWS/Account"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import * as account from "@distilled.cloud/aws/account"; |
| 5 | import { describe, expect } from "alchemy-test"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | describe.sequential( |
| 11 | "Account Region", |
| 12 | { tags: ["provider:aws", "provider:aws:account", "live"] }, |
| 13 | () => { |
| 14 | // us-east-1 is ENABLED_BY_DEFAULT: reconcile observes the status without |
| 15 | // issuing any mutation, so this exercises the full lifecycle safely against |
| 16 | // the real account. |
| 17 | test.provider( |
| 18 | "track a default-enabled region without mutation", |
| 19 | (stack) => |
| 20 | Effect.gen(function* () { |
| 21 | yield* stack.destroy(); |
| 22 | |
| 23 | const region = yield* stack.deploy( |
| 24 | Effect.gen(function* () { |
| 25 | return yield* Region("UsEast1", { |
| 26 | regionName: "us-east-1", |
| 27 | enabled: true, |
| 28 | }); |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | expect(region.regionName).toBe("us-east-1"); |
| 33 | expect(region.enabled).toBe(true); |
| 34 | expect(region.regionOptStatus).toBe("ENABLED_BY_DEFAULT"); |
| 35 | |
| 36 | // Out-of-band verification. |
| 37 | const live = yield* account.getRegionOptStatus({ |
| 38 | RegionName: "us-east-1", |
| 39 | }); |
| 40 | expect(live.RegionOptStatus).toBe("ENABLED_BY_DEFAULT"); |
| 41 | |
| 42 | // Destroy intentionally leaves the region's opt-in status untouched. |
| 43 | yield* stack.destroy(); |
| 44 | const after = yield* account.getRegionOptStatus({ |
| 45 | RegionName: "us-east-1", |
| 46 | }); |
| 47 | expect(after.RegionOptStatus).toBe("ENABLED_BY_DEFAULT"); |
| 48 | }), |
| 49 | { timeout: 120_000 }, |
| 50 | ); |
| 51 | |
| 52 | // Enabling an opt-in region mutates the account and cannot be immediately |
| 53 | // reverted (AWS enforces a waiting period before a freshly enabled region |
| 54 | // can be disabled), so this lifecycle is env-gated. Run with |
| 55 | // AWS_TEST_REGION_OPT_IN=1 against an account where enabling ap-east-1 is |
| 56 | // acceptable. |
| 57 | test.provider.skipIf(!process.env.AWS_TEST_REGION_OPT_IN)( |
| 58 | "enable an opt-in region", |
| 59 | (stack) => |
| 60 | Effect.gen(function* () { |
| 61 | yield* stack.destroy(); |
| 62 | |
| 63 | const region = yield* stack.deploy( |
| 64 | Effect.gen(function* () { |
| 65 | return yield* Region("HongKong", { |
| 66 | regionName: "ap-east-1", |
| 67 | enabled: true, |
| 68 | }); |
| 69 | }), |
| 70 | ); |
| 71 | |
| 72 | expect(region.regionName).toBe("ap-east-1"); |
| 73 | // Reconcile waits (bounded) for the transition to settle; if the |
| 74 | // enable is still propagating it reports the transitional status. |
| 75 | expect(["ENABLED", "ENABLING"]).toContain(region.regionOptStatus); |
| 76 | |
| 77 | // Out-of-band verification. |
| 78 | const live = yield* account.getRegionOptStatus({ |
| 79 | RegionName: "ap-east-1", |
| 80 | }); |
| 81 | expect(["ENABLED", "ENABLING"]).toContain(live.RegionOptStatus); |
| 82 | |
| 83 | // Destroy leaves the region enabled by design (disabling a region |
| 84 | // removes IAM access to everything in it). |
| 85 | yield* stack.destroy(); |
| 86 | }), |
| 87 | { timeout: 600_000 }, |
| 88 | ); |
| 89 | }, |
| 90 | ); |