| 1 | import type * as cloudcontrol from "@distilled.cloud/aws/cloudcontrol"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { CloudControlBindingOptions } from "./BindingOptions.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Runtime binding for `cloudformation:CreateResource`. |
| 8 | * |
| 9 | * Provisions any Cloud Control-supported resource from inside a Function — |
| 10 | * the building block for dynamic, per-tenant provisioning services. The call |
| 11 | * is asynchronous: poll the returned `RequestToken` with |
| 12 | * {@link GetResourceRequestStatus} until the operation settles. Because Cloud |
| 13 | * Control invokes the resource type's create handler with the caller's |
| 14 | * credentials, pass the handler's underlying permissions via |
| 15 | * {@link CloudControlBindingOptions.handlerPolicyStatements}. |
| 16 | * ### Provisioning Resources |
| 17 | * **Example:** Create an SSM Parameter at runtime |
| 18 | * ```typescript |
| 19 | * // init — account-level; grant the create handler's permissions too |
| 20 | * const createResource = yield* CloudControl.CreateResource({ |
| 21 | * handlerPolicyStatements: [ |
| 22 | * { |
| 23 | * Effect: "Allow", |
| 24 | * Action: ["ssm:PutParameter", "ssm:GetParameters", "ssm:AddTagsToResource"], |
| 25 | * Resource: ["*"], |
| 26 | * }, |
| 27 | * ], |
| 28 | * }); |
| 29 | * |
| 30 | * // runtime |
| 31 | * const created = yield* createResource({ |
| 32 | * TypeName: "AWS::SSM::Parameter", |
| 33 | * DesiredState: JSON.stringify({ |
| 34 | * Name: "/tenants/acme/greeting", |
| 35 | * Type: "String", |
| 36 | * Value: "hello", |
| 37 | * }), |
| 38 | * }); |
| 39 | * // poll created.ProgressEvent.RequestToken until SUCCESS |
| 40 | * ``` |
| 41 | * |
| 42 | * @binding |
| 43 | */ |
| 44 | export interface CreateResource extends Binding.Service< |
| 45 | CreateResource, |
| 46 | "AWS.CloudControl.CreateResource", |
| 47 | ( |
| 48 | options?: CloudControlBindingOptions, |
| 49 | ) => Effect.Effect< |
| 50 | ( |
| 51 | request: cloudcontrol.CreateResourceInput, |
| 52 | ) => Effect.Effect< |
| 53 | cloudcontrol.CreateResourceOutput, |
| 54 | cloudcontrol.CreateResourceError |
| 55 | > |
| 56 | > |
| 57 | > {} |
| 58 | |
| 59 | export const CreateResource = Binding.Service<CreateResource>( |
| 60 | "AWS.CloudControl.CreateResource", |
| 61 | ); |