Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from pulumi/donna-wip
Minor improvements to voting-app and webserver
- Loading branch information
Showing
17 changed files
with
263 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Voting app", | ||
"type": "typescript", | ||
"tsconfig": "voting-app/tsconfig.json", | ||
"option": "watch", | ||
"problemMatcher": [ | ||
"$tsc-watch" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
}, | ||
{ | ||
"label": "url shortener", | ||
"type": "typescript", | ||
"tsconfig": "url-shortener/tsconfig.json", | ||
"option": "watch", | ||
"problemMatcher": [ | ||
"$tsc-watch" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
}, | ||
{ | ||
"label": "webserver", | ||
"type": "typescript", | ||
"tsconfig": "webserver/tsconfig.json", | ||
"option": "watch", | ||
"problemMatcher": [ | ||
"$tsc-watch" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
}, | ||
{ | ||
"label": "webserver-component", | ||
"type": "typescript", | ||
"tsconfig": "webserver-component/tsconfig.json", | ||
"option": "watch", | ||
"problemMatcher": [ | ||
"$tsc-watch" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.pulumi/ | ||
/bin/ | ||
/node_modules/ | ||
/yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: webserver | ||
runtime: nodejs | ||
description: Basic example of an AWS web server accessible over HTTP. | ||
stacks: | ||
testing: | ||
config: | ||
aws:config:region: us-west-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as aws from "@pulumi/aws"; | ||
import * as webserver from "./webserver"; // use the new custom component | ||
|
||
let webInstance = webserver.createInstance("web-server-www", "t2.micro"); | ||
let appInstance = webserver.createInstance("web-server-app", "t2.nano"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "webserver", | ||
"version": "0.1", | ||
"main": "bin/index.js", | ||
"typings": "bin/index.d.ts", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^2.5.3" | ||
}, | ||
"peerDependencies": { | ||
"@pulumi/aws": "*", | ||
"pulumi": "*" | ||
}, | ||
"dependencies": { | ||
"@types/node": "^8.0.26" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es6", | ||
"lib": [ | ||
"es6" | ||
], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"stripInternal": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strictNullChecks": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as aws from "@pulumi/aws"; | ||
|
||
// create a new security group for port 80 | ||
let group = new aws.ec2.SecurityGroup("web-secgrp", { | ||
description: "Enable HTTP access", | ||
ingress: [ | ||
{ protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] }, | ||
], | ||
}); | ||
|
||
// (optional) create a simple web server using the startup script for the instance | ||
// use the AWS metadata service to get the availability zone for the instance | ||
let userData = | ||
`#!/bin/bash | ||
echo "Hello, World!\nInstance metadata:" > index.html | ||
curl http://169.254.169.254/latest/meta-data/placement/availability-zone >> index.html | ||
nohup python -m SimpleHTTPServer 80 &`; | ||
|
||
export function createInstance(name: string, size: aws.ec2.InstanceType): aws.ec2.Instance { | ||
let result = new aws.ec2.Instance(name, { | ||
tags: { "Name": name }, // use the `name` parameter | ||
instanceType: size, // use function argument for size | ||
securityGroups: [ group.name ], // reference the group object above | ||
ami: aws.ec2.getLinuxAMI(size), // call built-in function (can also be custom) | ||
userData: userData // set up a simple web server | ||
}); | ||
|
||
result.publicDns.then(url => console.log(`Server URL: http://${url}`)); | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.pulumi/ | ||
/bin/ | ||
/node_modules/ | ||
/yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: webserver | ||
runtime: nodejs | ||
description: Basic example of an AWS web server accessible over HTTP. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Pulumi web server | ||
|
||
Starting point for building the Pulumi web server sample. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as aws from "@pulumi/aws"; | ||
import * as webserver from "./webserver"; // use the new custom component | ||
|
||
// the async block is currently required, due to the use of `await` | ||
// this will be improved in the future | ||
(async () => { | ||
let zones: string[] = (await aws.getAvailabilityZones()).names; | ||
for (let i = 0; i < zones.length; i++) { | ||
let server = webserver.createInstance(`web-server-www-${i}`, "t2.micro", zones[i]); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "webserver", | ||
"version": "0.1", | ||
"main": "bin/index.js", | ||
"typings": "bin/index.d.ts", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^2.5.3" | ||
}, | ||
"peerDependencies": { | ||
"@pulumi/aws": "*", | ||
"pulumi": "*" | ||
}, | ||
"dependencies": { | ||
"@types/node": "^8.0.26" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es6", | ||
"lib": [ | ||
"es6" | ||
], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"stripInternal": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strictNullChecks": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
import * as aws from "@pulumi/aws"; | ||
import * as webserver from "./webserver"; // use our custom component | ||
|
||
(async () => { | ||
let zones: string[] = (await aws.getAvailabilityZones()).names; | ||
for (let i = 0; i < zones.length; i++) { | ||
let server = webserver.createInstance("web-server-www-" + i, "t2.micro", zones[i]); | ||
} | ||
})(); | ||
|
||
// the type InstanceType contains friendly names for AWS instance sizes | ||
let size: aws.ec2.InstanceType = "t2.micro"; | ||
|
||
// create a new security group for port 80 | ||
let group = new aws.ec2.SecurityGroup("web-secgrp", { | ||
description: "Enable HTTP access", | ||
ingress: [ | ||
{ protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] }, | ||
], | ||
}); | ||
|
||
// (optional) create a simple web server using the startup script for the instance | ||
// use the AWS metadata service to get the availability zone for the instance | ||
let userData = | ||
`#!/bin/bash | ||
echo "Hello, World!\nInstance metadata:" > index.html | ||
curl http://169.254.169.254/latest/meta-data/placement/availability-zone >> index.html | ||
nohup python -m SimpleHTTPServer 80 &`; | ||
|
||
let server = new aws.ec2.Instance("web-server-www", { | ||
tags: { "Name": "web-server-www" }, | ||
instanceType: size, | ||
securityGroups: [ group.name ], // reference the group object above | ||
ami: aws.ec2.getLinuxAMI(size), // call built-in function (can also be custom) | ||
userData: userData // set up a simple web server | ||
}); | ||
|
||
server.publicDns.then(dns => console.log(`Server URL: http://${dns}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters