Skip to content

Instantly share code, notes, and snippets.

@akiyoshi83
Last active October 19, 2016 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akiyoshi83/bb520c4119c91a3273c30891c6b184f8 to your computer and use it in GitHub Desktop.
Save akiyoshi83/bb520c4119c91a3273c30891c6b184f8 to your computer and use it in GitHub Desktop.
class CloudFormation {
createStack(version: AWSTemplateFormatVersion): CloudFormationStack {
return new CloudFormationStack(version);
}
}
class AWSTemplateFormatVersion {
private version: string;
private constructor(version: string) {
this.version = version;
}
toString(): string {
return this.version;
}
static V2010_09_09 = new AWSTemplateFormatVersion("2010-09-09");
static DEFAULT = AWSTemplateFormatVersion.V2010_09_09;
}
class CloudFormationStack {
constructor(version: AWSTemplateFormatVersion);
constructor(option: any) {
if (option instanceof AWSTemplateFormatVersion) {
this.version = option;
} else {
this.version = option.version;
this.description = option.description;
this.parameters = option.parameters;
this.resources = option.resources;
this.mappings = option.mappings;
this.outputs = option.outputs;
}
}
version: AWSTemplateFormatVersion;
description: string = "Empty Template"
parameters: Parameter[] = [];
resources: Resource[] = [];
mappings: Mapping[] = [];
outputs: Output[] = [];
toJSON(): string {
let ret: Object = {
AWSTemplateFormatVersion: this.version.toString(),
Description: this.description,
Parameters: this.parameters.map(e => e.toJSON()),
Resources: this.resources.map(e => e.toJSON()),
Mappings: this.mappings.map(e => e.toJSON()),
Outputs: this.outputs.map(e => e.toJSON()),
};
return JSON.stringify(ret);
}
}
interface Parameter {
toJSON(): string;
toYAML(): string;
}
interface Resource {
toJSON(): string;
toYAML(): string;
}
interface Mapping {
toJSON(): string;
toYAML(): string;
}
interface Output {
toJSON(): string;
toYAML(): string;
}
class Ec2 implements Resource {
amiId: string
instanceType: string
securityGroups: SecurityGroup[]
toJSON(): string { return "" }
toYAML(): string { return "" }
}
class SecurityGroup implements Resource {
securityGroupId: string
toJSON(): string { return "" }
toYAML(): string { return "" }
}
let cf = new CloudFormation();
let stack = cf.createStack(AWSTemplateFormatVersion.V2010_09_09);
console.log(stack.toJSON());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment