UNPKG

cloudformation-declarations

Version:

TypeScript declarations and helpers for writing CloudFormation templates in TS or JS.

153 lines (152 loc) 5.73 kB
import { ConditionId } from './template'; export declare type TODO = any; export declare type Diff<T extends string, U extends string> = ({ [P in T]: P; } & { [P in U]: never; } & { [x: string]: never; })[T]; export declare type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>; export declare type CFString = string; export declare type CFBoolean = 'true' | 'false'; export declare type CFInteger = string; export declare type CFDouble = string; export declare type CFLong = string; export declare type CFTimestamp = string; export declare type CFJson = object; export declare type CFList<T> = Array<T>; export declare type CFMap<T> = { [key: string]: T; }; export declare type LiteralOrRef<V = any> = V | Ref; export declare namespace Functions { const Base64: (v: Yields<string>) => Base64; interface Base64 { 'Fn::Base64': Yields<CFString>; } function FindInMap<V>(v: FindInMap<V>['Fn::FindInMap']): FindInMap<V>; interface FindInMap<V> { 'Fn::FindInMap': [Yields<CFString>, Yields<CFString>, Yields<CFString>]; } const GetAtt: (v: [string, LiteralOrRef<string>]) => GetAtt; interface GetAtt { 'Fn::GetAtt': [CFString, LiteralOrRef<CFString>]; } const GetAZs: (v: LiteralOrRef<string>) => GetAZs; interface GetAZs { 'Fn::GetAZs': LiteralOrRef<CFString>; } function ImportValue<V>(v: ImportValue<V>['Fn::ImportValue']): ImportValue<V>; interface ImportValue<V> { 'Fn::ImportValue': Yields<CFString>; } const Join: (v: [string, Yields<Yields<string>[]>]) => Join; interface Join { 'Fn::Join': [CFString, Yields<Array<Yields<CFString>>>]; } function Select<V>(v: Select<V>['Fn::Select']): Select<V>; interface Select<V> { 'Fn::Select': [Yields<CFInteger>, Yields<Array<Yields<V>>>]; } const Split: (v: [string, Yields<string>]) => Split; interface Split { 'Fn::Split': [CFString, Yields<CFString>]; } const Sub: (v: string | Ref<string> | Select<string> | If<string> | ImportValue<string> | [Yields<string>, Yields<CFMap<Yields<string>>>]) => Sub; interface Sub { 'Fn::Sub': [Yields<CFString>, Yields<CFMap<Yields<CFString>>>] | Yields<CFString>; } const And: (v: BooleanCondition[]) => And; interface And { 'Fn::And': Array<BooleanCondition>; } const Equals: (v: [any, any]) => Equals; interface Equals { 'Fn::Equals': [Yields<any>, Yields<any>]; } function If<V>(v: If<V>['Fn::If']): If<V>; interface If<V> { 'Fn::If': [ConditionId, Yields<V>, Yields<V>]; } const Not: (v: [BooleanCondition]) => Not; interface Not { 'Fn::Not': [BooleanCondition]; } const Or: (v: BooleanCondition[]) => Or; interface Or { 'Fn::Or': Array<BooleanCondition>; } } export declare type BooleanCondition = Functions.And | Functions.Equals | Functions.Not | Functions.Or | ConditionRef; export interface ConditionRef { Condition: ConditionId; } /** * Yields a value of type V. In other words, can appear in the JSON where that type of value is expected and where functions are allowed to execute. * Can be a function that returns the value, or can be the literal value itself. */ export declare type Yields<V> = V | Returns<V>; export declare type Returns<V> = Functions.Select<V> | Functions.If<V> | Functions.ImportValue<V> | Ref; export declare type YieldsBoolean = Yields<CFBoolean> | ReturnsBoolean; export declare type ReturnsBoolean = Returns<CFBoolean> | Functions.And | Functions.Equals | Functions.Not | Functions.Or | ConditionRef; export declare type YieldsString = Yields<CFString> | ReturnsString; export declare type ReturnsString = Returns<CFString> | Functions.Base64 | Functions.Join | Functions.Sub; /** * This is some sort of function or reference that ultimately yields a value of type V. * Allows the type system to understand what type a condition, value, reference, etc. will return. */ export interface AbstractResource { type: string; Condition?: ConditionId; DeletionPolicy?: 'Delete' | 'Retain' | 'Snapshot'; DependsOn?: CFString | Array<CFString>; Metadata?: object; } declare module './generated/aws-cloudformation' { namespace AWS.AutoScaling { interface AutoScalingGroup extends HasCreationPolicy, HasUpdatePolicy { } } namespace AWS.EC2 { interface Instance extends HasCreationPolicy { } } namespace AWS.CloudFormation { interface WaitCondition extends HasCreationPolicy { } } } export interface HasCreationPolicy { CreationPolicy?: { AutoScalingCreationPolicy?: { MinSuccessfulInstancesPercent?: CFInteger; }; ResourceSignal?: { Count?: CFString; Timeout?: CFInteger; }; }; } export interface HasUpdatePolicy { UpdatePolicy?: { AutoScalingRollingUpdate?: { MaxBatchSize?: CFInteger; MinInstancesInService?: CFInteger; MinSuccessfulInstancesPercent?: CFInteger; PauseTime: CFString; SuspendProcesses?: Array<TODO>; WaitOnResourceSignals?: CFBoolean; }; AutoScalingReplacingUpdate?: { WillReplace?: CFBoolean; }; AutoScalingScheduledAction?: { IgnoreUnmodifiedGroupSizeProperties?: CFBoolean; }; }; } export interface Ref<K extends CFString = CFString> { Ref: K; } export declare function Ref<K extends CFString>(ref: K): Ref<K>;