| 1 | import type * as autoscaling from "@distilled.cloud/aws/auto-scaling"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { AutoScalingGroup } from "./AutoScalingGroup.ts"; |
| 5 | |
| 6 | /** |
| 7 | * `StartInstanceRefresh` request with `AutoScalingGroupName` injected from |
| 8 | * the bound {@link AutoScalingGroup}. |
| 9 | */ |
| 10 | export interface StartInstanceRefreshRequest extends Omit< |
| 11 | autoscaling.StartInstanceRefreshType, |
| 12 | "AutoScalingGroupName" |
| 13 | > {} |
| 14 | |
| 15 | /** |
| 16 | * `CancelInstanceRefresh` request with `AutoScalingGroupName` injected from |
| 17 | * the bound {@link AutoScalingGroup}. |
| 18 | */ |
| 19 | export interface CancelInstanceRefreshRequest extends Omit< |
| 20 | autoscaling.CancelInstanceRefreshType, |
| 21 | "AutoScalingGroupName" |
| 22 | > {} |
| 23 | |
| 24 | /** |
| 25 | * `DescribeInstanceRefreshes` request with `AutoScalingGroupName` injected |
| 26 | * from the bound {@link AutoScalingGroup}. |
| 27 | */ |
| 28 | export interface DescribeInstanceRefreshesRequest extends Omit< |
| 29 | autoscaling.DescribeInstanceRefreshesType, |
| 30 | "AutoScalingGroupName" |
| 31 | > {} |
| 32 | |
| 33 | export interface InstanceRefreshClient { |
| 34 | /** |
| 35 | * Begin rolling the group's instances onto the current launch template (or |
| 36 | * the supplied `DesiredConfiguration`). Returns the refresh id to track. |
| 37 | */ |
| 38 | start: ( |
| 39 | request?: StartInstanceRefreshRequest, |
| 40 | ) => Effect.Effect< |
| 41 | autoscaling.StartInstanceRefreshAnswer, |
| 42 | autoscaling.StartInstanceRefreshError |
| 43 | >; |
| 44 | /** |
| 45 | * Cancel the in-progress refresh. Instances already replaced are not rolled |
| 46 | * back — use `rollback` for that. |
| 47 | */ |
| 48 | cancel: ( |
| 49 | request?: CancelInstanceRefreshRequest, |
| 50 | ) => Effect.Effect< |
| 51 | autoscaling.CancelInstanceRefreshAnswer, |
| 52 | autoscaling.CancelInstanceRefreshError |
| 53 | >; |
| 54 | /** |
| 55 | * Roll the group back to the configuration it had before the in-progress |
| 56 | * refresh started. |
| 57 | */ |
| 58 | rollback: () => Effect.Effect< |
| 59 | autoscaling.RollbackInstanceRefreshAnswer, |
| 60 | autoscaling.RollbackInstanceRefreshError |
| 61 | >; |
| 62 | /** |
| 63 | * Page through the group's instance refreshes (newest first), including |
| 64 | * per-refresh status and progress details. |
| 65 | */ |
| 66 | describe: ( |
| 67 | request?: DescribeInstanceRefreshesRequest, |
| 68 | ) => Effect.Effect< |
| 69 | autoscaling.DescribeInstanceRefreshesAnswer, |
| 70 | autoscaling.DescribeInstanceRefreshesError |
| 71 | >; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Runtime binding for the instance refresh operations — `StartInstanceRefresh`, |
| 76 | * `CancelInstanceRefresh`, `RollbackInstanceRefresh` (IAM actions scoped to |
| 77 | * the group ARN) and `DescribeInstanceRefreshes` (granted on `*`; EC2 Auto |
| 78 | * Scaling `Describe*` actions do not support resource-level permissions). |
| 79 | * |
| 80 | * Lets a deploy pipeline Lambda roll the fleet onto a new launch template |
| 81 | * version, watch progress, and cancel or roll back a bad deploy. Provide the |
| 82 | * implementation with `Effect.provide(AWS.AutoScaling.InstanceRefreshHttp)`. |
| 83 | * ### Rolling Deployments |
| 84 | * **Example:** Roll the fleet and watch progress |
| 85 | * ```typescript |
| 86 | * // init — bind the operations to the group |
| 87 | * const refresh = yield* AWS.AutoScaling.InstanceRefresh(group); |
| 88 | * |
| 89 | * // runtime — start a rolling replacement with auto-rollback |
| 90 | * const { InstanceRefreshId } = yield* refresh.start({ |
| 91 | * Preferences: { MinHealthyPercentage: 90, AutoRollback: true }, |
| 92 | * }); |
| 93 | * |
| 94 | * // runtime — check on it |
| 95 | * const page = yield* refresh.describe({ |
| 96 | * InstanceRefreshIds: [InstanceRefreshId!], |
| 97 | * }); |
| 98 | * ``` |
| 99 | * |
| 100 | * **Example:** Cancel a bad deploy |
| 101 | * ```typescript |
| 102 | * yield* refresh.cancel().pipe( |
| 103 | * Effect.catchTag("ActiveInstanceRefreshNotFoundFault", () => Effect.void), |
| 104 | * ); |
| 105 | * ``` |
| 106 | * |
| 107 | * @binding |
| 108 | */ |
| 109 | export interface InstanceRefresh extends Binding.Service< |
| 110 | InstanceRefresh, |
| 111 | "AWS.AutoScaling.InstanceRefresh", |
| 112 | (group: AutoScalingGroup) => Effect.Effect<InstanceRefreshClient> |
| 113 | > {} |
| 114 | |
| 115 | export const InstanceRefresh = Binding.Service<InstanceRefresh>( |
| 116 | "AWS.AutoScaling.InstanceRefresh", |
| 117 | ); |