Make an aws/cloudformation module

This includes the original CloudFormation resource type in addition
to the various tag helpers.
This commit is contained in:
joeduffy 2016-12-12 17:54:50 -08:00
parent d10f2e6bff
commit c7f0465c41
5 changed files with 59 additions and 9 deletions

1
lib/aws/.gitignore vendored
View file

@ -1,2 +1,3 @@
bin/
node_modules/

View file

@ -0,0 +1,5 @@
// Copyright 2016 Marapongo, Inc. All rights reserved.
export * from './resource';
export * from './tags';

View file

@ -1,22 +1,22 @@
import * as as mu from 'mu';
// Copyright 2016 Marapongo, Inc. All rights reserved.
import * as mu from 'mu';
// A special service that simply emits a CloudFormation template.
// @name: aws/x/cf
export default class CloudFormation extends mu.Extension {
constructor(ctx: mu.Context, args: CloudFormationArgs) {
export class Resource extends mu.Extension {
constructor(ctx: mu.Context, args: ResourceArgs) {
super(ctx);
// TODO: encode the special translation logic as code (maybe as an overridden method).
}
}
export interface CloudFormationArgs {
export interface ResourceArgs {
// The CF resource name.
readonly resource: string;
// An optional list of properties to map.
readonly properties?: Map<string, string>;
// An optional set of arbitrary key/values to merge with the mapped ones.
readonly extraProperties?: Map<string, any>;
readonly properties?: any /*actually, JSON-like*/;
// An optional list of other CloudFormation resources that this depends on.
readonly dependsOn?: mu.Stack[];
readonly dependsOn?: string[];
}

View file

@ -0,0 +1,36 @@
// Copyright 2016 Marapongo, Inc. All rights reserved.
// Tag can be applied to a resource, helping to identify and categorize those resources.
export interface Tag {
// The key name of the tag. You can specify a value that is 1 to 127 Unicode characters in length and cannot be
// prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace,
// _, ., /, =, +, and -.
key: string;
// The value for the tag. You can specify a value that is 1 to 255 Unicode characters in length and cannot be
// prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace,
// _, ., /, =, +, and -.
value: string;
}
// Tags is simply a collection of Tag values.
export type Tags = Tag[];
// TagArgs represents a base type for the common pattern of resources accepting tags and a name.
export interface TagArgs {
// An optional name for this resource.
name?: string;
// An arbitrary set of tags (key-value pairs) for this resource.
tags?: Tags;
}
// expandTags takes a TagArgs and expands the "Name" key in-place, for naming, when present.
export function expandTags(args: TagArgs): void {
if (args.name !== undefined) {
if (args.tags == undefined) {
args.tags = [];
}
args.tags.push({ key: "Name", value: args.name });
delete args.name;
}
}

View file

@ -17,14 +17,22 @@
},
"files": [
"index.ts",
"cloudformation/index.ts",
"cloudformation/resource.ts",
"cloudformation/tags.ts",
"ec2/index.ts",
"ec2/internetGateway.ts",
"ec2/route.ts",
"ec2/routeTable.ts",
"ec2/securityGroup.ts",
"ec2/securityGroupEgress.ts",
"ec2/securityGroupIngress.ts",
"ec2/subnet.ts",
"ec2/vpc.ts",
"ec2/vpcGatewayAttachment.ts"
"ec2/vpcGatewayAttachment.ts",
"ec2/vpcPeeringConnection.ts"
]
}