forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add StackReference example. (pulumi#217)
* Add aws-ts-stackreference example.
- Loading branch information
Showing
17 changed files
with
383 additions
and
0 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,2 @@ | ||
/bin/ | ||
/node_modules/ |
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,186 @@ | ||
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new) | ||
|
||
# StackReference Example | ||
|
||
This example creates a "team" EC2 Instance with tags set from _upstream_ "company" and "department" | ||
stacks via [StackReference](https://pulumi.io/reference/organizing-stacks-projects.html#inter-stack-dependencies). | ||
|
||
``` | ||
/** | ||
* company | ||
* └─ department | ||
* └─ team | ||
*/ | ||
``` | ||
|
||
## Getting Started | ||
|
||
1. Change directory to `company` and install dependencies. | ||
|
||
```bash | ||
$ cd company | ||
$ npm install | ||
```` | ||
|
||
1. Create a new stack: | ||
|
||
```bash | ||
$ pulumi stack init dev | ||
``` | ||
|
||
1. Set the required configuration variables: | ||
|
||
```bash | ||
$ pulumi config set companyName 'ACME Widget Co.' | ||
``` | ||
|
||
1. Deploy everything with the `pulumi up` command. | ||
|
||
```bash | ||
$ pulumi up | ||
Previewing update (dev): | ||
Type Name Plan | ||
+ pulumi:pulumi:Stack aws-ts-stackreference-company-dev create | ||
Resources: | ||
+ 1 to create | ||
Do you want to perform this update? yes | ||
Updating (dev): | ||
Type Name Status | ||
+ pulumi:pulumi:Stack aws-ts-stackreference-company-dev created | ||
Outputs: | ||
companyName: "ACME Widget Company" | ||
Resources: | ||
+ 1 created | ||
Duration: 1s | ||
Permalink: https://app.pulumi.com/clstokes/aws-ts-stackreference-company/dev/updates/1 | ||
``` | ||
|
||
1. Change directory to `department` and install dependencies. | ||
|
||
```bash | ||
$ cd ../company | ||
$ npm install | ||
```` | ||
|
||
1. Create a new stack: | ||
|
||
```bash | ||
$ pulumi stack init dev | ||
``` | ||
|
||
1. Set the required configuration variables: | ||
|
||
```bash | ||
$ pulumi config set departmentName 'E-Commerce' | ||
``` | ||
|
||
1. Deploy everything with the `pulumi up` command. | ||
|
||
```bash | ||
$ pulumi up | ||
Previewing update (dev): | ||
|
||
Type Name Plan | ||
+ pulumi:pulumi:Stack aws-ts-stackreference-department-dev create | ||
|
||
Resources: | ||
+ 1 to create | ||
|
||
Do you want to perform this update? yes | ||
Updating (dev): | ||
|
||
Type Name Status | ||
+ pulumi:pulumi:Stack aws-ts-stackreference-department-dev created | ||
|
||
Outputs: | ||
departmentName: "E-Commerce" | ||
|
||
Resources: | ||
+ 1 created | ||
|
||
Duration: 1s | ||
|
||
Permalink: https://app.pulumi.com/clstokes/aws-ts-stackreference-department/dev/updates/1 | ||
``` | ||
|
||
1. Change directory to `team` and install dependencies. | ||
|
||
```bash | ||
$ cd ../team | ||
$ npm install | ||
```` | ||
|
||
1. Create a new stack: | ||
|
||
```bash | ||
$ pulumi stack init dev | ||
``` | ||
|
||
1. Set the required configuration variables, replacing `YOUR_ORG` with the name of your Pulumi organization: | ||
|
||
```bash | ||
$ pulumi config set companyStack YOUR_ORG/aws-ts-stackreference-company/dev | ||
$ pulumi config set departmentStack YOUR_ORG/aws-ts-stackreference-department/dev | ||
$ pulumi config set teamName 'Frontend Dev' | ||
$ pulumi config set aws:region us-west-2 # any valid AWS zone works | ||
``` | ||
|
||
1. Deploy everything with the `pulumi up` command. | ||
|
||
```bash | ||
$ envchain aws pulumi up | ||
Previewing update (dev): | ||
Type Name Plan | ||
+ pulumi:pulumi:Stack aws-ts-stackreference-team-dev create | ||
>- ├─ pulumi:pulumi:StackReference clstokes/aws-ts-stackreference-department/dev read | ||
>- ├─ pulumi:pulumi:StackReference clstokes/aws-ts-stackreference-company/dev read | ||
+ └─ aws:ec2:Instance tagged create | ||
Resources: | ||
+ 2 to create | ||
Do you want to perform this update? yes | ||
Updating (dev): | ||
Type Name Status | ||
+ pulumi:pulumi:Stack aws-ts-stackreference-team-dev created | ||
>- ├─ pulumi:pulumi:StackReference clstokes/aws-ts-stackreference-company/dev read | ||
>- ├─ pulumi:pulumi:StackReference clstokes/aws-ts-stackreference-department/dev read | ||
+ └─ aws:ec2:Instance tagged created | ||
Outputs: | ||
instanceId : "i-0a9ede9c446503903" | ||
instanceTags: { | ||
Managed By: "Pulumi" | ||
company : "ACME Widget Company" | ||
department: "E-Commerce" | ||
team : "Frontend Dev" | ||
} | ||
Resources: | ||
+ 2 created | ||
Duration: 28s | ||
Permalink: https://app.pulumi.com/clstokes/aws-ts-stackreference-team/dev/updates/1 | ||
``` | ||
|
||
|
||
## Clean Up | ||
|
||
1. Once you are done, destroy all of the resources and the stack. Repeat this in each | ||
of the `company`, `department`, and `team` directories from above that you ran `pulumi up` within. | ||
|
||
```bash | ||
$ pulumi destroy | ||
$ pulumi stack rm | ||
``` |
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,2 @@ | ||
/bin/ | ||
/node_modules/ |
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,9 @@ | ||
name: aws-ts-stackreference-company | ||
runtime: nodejs | ||
description: An AWS TypeScript Pulumi program demonstrating sharing configuration | ||
via StackReference resources | ||
template: | ||
description: A minimal AWS TypeScript Pulumi program | ||
config: | ||
companyName: | ||
description: The company name to use |
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 pulumi from "@pulumi/pulumi"; | ||
|
||
/** | ||
* company | ||
* └─ department | ||
* └─ team | ||
*/ | ||
|
||
const config = new pulumi.Config(); | ||
|
||
export const companyName = config.require("companyName"); |
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,10 @@ | ||
{ | ||
"name": "aws-typescript", | ||
"devDependencies": { | ||
"@types/node": "latest" | ||
}, | ||
"dependencies": { | ||
"@pulumi/pulumi": "latest", | ||
"@pulumi/aws": "latest" | ||
} | ||
} |
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,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es6", | ||
"lib": [ | ||
"es6" | ||
], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": 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,2 @@ | ||
/bin/ | ||
/node_modules/ |
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,9 @@ | ||
name: aws-ts-stackreference-department | ||
runtime: nodejs | ||
description: An AWS TypeScript Pulumi program demonstrating sharing configuration | ||
via StackReference resources | ||
template: | ||
description: A minimal AWS TypeScript Pulumi program | ||
config: | ||
departmentName: | ||
description: The department name to use |
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 pulumi from "@pulumi/pulumi"; | ||
|
||
/** | ||
* company | ||
* └─ department | ||
* └─ team | ||
*/ | ||
|
||
const config = new pulumi.Config(); | ||
|
||
export const departmentName = config.require("departmentName"); |
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,10 @@ | ||
{ | ||
"name": "aws-typescript", | ||
"devDependencies": { | ||
"@types/node": "latest" | ||
}, | ||
"dependencies": { | ||
"@pulumi/pulumi": "latest", | ||
"@pulumi/aws": "latest" | ||
} | ||
} |
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,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es6", | ||
"lib": [ | ||
"es6" | ||
], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": 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,2 @@ | ||
/bin/ | ||
/node_modules/ |
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,16 @@ | ||
name: aws-ts-stackreference-team | ||
runtime: nodejs | ||
description: An AWS TypeScript Pulumi program demonstrating sharing configuration | ||
via StackReference resources | ||
template: | ||
description: A minimal AWS TypeScript Pulumi program | ||
config: | ||
aws:region: | ||
description: The AWS region to deploy into | ||
default: us-west-2 | ||
companyStack: | ||
description: The stack to reference company properties from | ||
departmentStack: | ||
description: The stack to reference department properties from | ||
teamName: | ||
description: The team name to use |
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,37 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as aws from "@pulumi/aws"; | ||
|
||
/** | ||
* company | ||
* └─ department | ||
* └─ team | ||
*/ | ||
|
||
const config = new pulumi.Config(); | ||
|
||
const companyStack = new pulumi.StackReference(config.require("companyStack")); | ||
const departmentStack = new pulumi.StackReference(config.require("departmentStack")); | ||
|
||
const combinedTags = { | ||
/* from company stack */ company: companyStack.getOutput("companyName"), | ||
/* from department stack */ department: departmentStack.getOutput("departmentName"), | ||
/* from team config */ team: config.require("teamName"), | ||
"Managed By": "Pulumi", | ||
} | ||
|
||
const amiId = aws.getAmi({ | ||
mostRecent: true, | ||
filters: [ | ||
{ name: "owner-id", values: ["099720109477"] }, // Ubuntu | ||
{ name: "name", values: ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"] }, | ||
], | ||
}).then(x => x.id); | ||
|
||
const instance = new aws.ec2.Instance("tagged", { | ||
ami: amiId, | ||
instanceType: "t2.medium", | ||
tags: combinedTags, | ||
}); | ||
|
||
export const instanceId = instance.id; | ||
export const instanceTags = instance.tags; |
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,10 @@ | ||
{ | ||
"name": "aws-typescript", | ||
"devDependencies": { | ||
"@types/node": "latest" | ||
}, | ||
"dependencies": { | ||
"@pulumi/pulumi": "latest", | ||
"@pulumi/aws": "latest" | ||
} | ||
} |
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,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es6", | ||
"lib": [ | ||
"es6" | ||
], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strictNullChecks": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |