-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to specify resource options at the stack level
It has been possible to specify Pulumi resource options at the stack level, but it did not flow through to the actual resources. This PR makes sure that the inheritance works correctly. This PR also adds functionality to automatically set the Stack environment based on the App provider. Because the App creates the stacks in an async context, we can use provider functions to lookup the environment and then pass the resolved environment to the stack. This means that all Stacks have their environment provided by default. This will cut down on the number of Intrinsics used in the generated template. If the user provides a provider to the Stack we are no longer in an async context which means we can't determine the environment from the provider and fall back to an environment agnostic stack. re #61, re #219
- Loading branch information
Showing
15 changed files
with
607 additions
and
47 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
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
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: pulumi-stack-provider | ||
runtime: nodejs | ||
description: A minimal TypeScript Pulumi program |
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,70 @@ | ||
import * as logs from 'aws-cdk-lib/aws-logs'; | ||
import * as pulumi from '@pulumi/pulumi'; | ||
import * as pulumicdk from '@pulumi/cdk'; | ||
import * as native from '@pulumi/aws-native'; | ||
import { RemovalPolicy } from 'aws-cdk-lib'; | ||
|
||
const config = new pulumi.Config(); | ||
const cdkRegion = config.get('cdk-region'); | ||
const cdkAccount = config.get('cdk-account'); | ||
const defaultRegion = config.get('default-region'); | ||
|
||
export class StackProviderStack extends pulumicdk.Stack { | ||
public readonly logsRegion: pulumi.Output<string>; | ||
constructor(app: pulumicdk.App, id: string, providers?: pulumi.ProviderResource[]) { | ||
super(app, id, { | ||
providers, | ||
props: | ||
cdkRegion || cdkAccount | ||
? { | ||
env: { | ||
region: cdkRegion, | ||
account: cdkAccount, | ||
}, | ||
} | ||
: undefined, | ||
}); | ||
|
||
const group = new logs.LogGroup(this, 'group', { | ||
retention: logs.RetentionDays.ONE_DAY, | ||
removalPolicy: RemovalPolicy.DESTROY, | ||
}); | ||
|
||
this.logsRegion = this.asOutput(group.logGroupArn).apply((arn) => arn.split(':')[3]); | ||
} | ||
} | ||
|
||
const app = new pulumicdk.App( | ||
'app', | ||
(scope: pulumicdk.App) => { | ||
const stack = new StackProviderStack(scope, 'teststack', [ | ||
new native.Provider('ccapi-provider', { | ||
region: 'us-east-1', // a different region from the app provider | ||
}), | ||
]); | ||
const defaultStack = new StackProviderStack(scope, 'default-stack'); | ||
return { | ||
east1LogsRegion: stack.logsRegion, | ||
east1StackRegion: stack.asOutput(stack.region), | ||
defaultLogsRegion: defaultStack.logsRegion, | ||
defaultStackRegion: defaultStack.asOutput(defaultStack.region), | ||
}; | ||
}, | ||
{ | ||
providers: defaultRegion | ||
? [ | ||
new native.Provider('app-provider', { | ||
region: defaultRegion as native.Region, // a different region from the default env | ||
}), | ||
] | ||
: undefined, | ||
}, | ||
); | ||
|
||
// You can (we check for this though) configure a different region on the provider | ||
// that the stack uses vs the region in the CDK StackProps. This tests checks that both the | ||
// stack region and the region the resources are deployed to are the same. | ||
export const east1LogsRegion = app.outputs['east1LogsRegion']; | ||
export const defaultLogsRegion = app.outputs['defaultLogsRegion']; | ||
export const east1StackRegion = app.outputs['east1StackRegion']; | ||
export const defaultStackRegion = app.outputs['defaultStackRegion']; |
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,13 @@ | ||
{ | ||
"name": "pulumi-aws-cdk", | ||
"devDependencies": { | ||
"@types/node": "^10.0.0" | ||
}, | ||
"dependencies": { | ||
"@pulumi/aws": "^6.0.0", | ||
"@pulumi/aws-native": "^1.9.0", | ||
"@pulumi/cdk": "^0.5.0", | ||
"aws-cdk-lib": "2.156.0", | ||
"constructs": "10.3.0" | ||
} | ||
} |
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,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": 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
Oops, something went wrong.