diff --git a/api-docs/README.md b/api-docs/README.md index 0ad89de..aabade5 100644 --- a/api-docs/README.md +++ b/api-docs/README.md @@ -83,6 +83,37 @@ export const bucket = app.outputs['bucket']; | `name` | `readonly` | `string` | `undefined` | The name of the component | [stack.ts:57](https://github.com/pulumi/pulumi-cdk/blob/main/src/stack.ts#L57) | | `outputs` | `public` | `object` | `{}` | The collection of outputs from the AWS CDK Stack represented as Pulumi Outputs. Each CfnOutput defined in the AWS CDK Stack will populate a value in the outputs. | [stack.ts:63](https://github.com/pulumi/pulumi-cdk/blob/main/src/stack.ts#L63) | +#### Accessors + +##### env + +###### Get Signature + +> **get** **env**(): `Environment` + +This can be used to get the CDK Environment based on the Pulumi Provider used for the App. +You can then use this to configure an explicit environment on Stacks. + +###### Example + +```ts +const app = new pulumicdk.App('app', (scope: pulumicdk.App) => { + const stack = new pulumicdk.Stack(scope, 'pulumi-stack', { + props: { env: app.env }, + }); +}); +``` + +###### Returns + +`Environment` + +the CDK Environment configured for the App + +###### Defined in + +[stack.ts:155](https://github.com/pulumi/pulumi-cdk/blob/main/src/stack.ts#L155) + *** ### Stack @@ -121,7 +152,7 @@ Create and register an AWS CDK stack deployed with Pulumi. ###### Defined in -[stack.ts:330](https://github.com/pulumi/pulumi-cdk/blob/main/src/stack.ts#L330) +[stack.ts:336](https://github.com/pulumi/pulumi-cdk/blob/main/src/stack.ts#L336) #### Methods @@ -151,7 +182,7 @@ A Pulumi Output value. ###### Defined in -[stack.ts:432](https://github.com/pulumi/pulumi-cdk/blob/main/src/stack.ts#L432) +[stack.ts:418](https://github.com/pulumi/pulumi-cdk/blob/main/src/stack.ts#L418) ## Interfaces @@ -266,7 +297,7 @@ new App('testapp', (scope: App) => { | Property | Type | Description | Defined in | | ------ | ------ | ------ | ------ | -| `props?` | `StackProps` | The CDK Stack props | [stack.ts:289](https://github.com/pulumi/pulumi-cdk/blob/main/src/stack.ts#L289) | +| `props?` | `StackProps` | The CDK Stack props | [stack.ts:295](https://github.com/pulumi/pulumi-cdk/blob/main/src/stack.ts#L295) | ## Type Aliases diff --git a/examples/lookups-enabled/index.ts b/examples/lookups-enabled/index.ts index d4fffea..1a9c402 100644 --- a/examples/lookups-enabled/index.ts +++ b/examples/lookups-enabled/index.ts @@ -1,4 +1,3 @@ -import * as aws from '@pulumi/aws'; import * as pulumi from '@pulumi/pulumi'; import * as pulumicdk from '@pulumi/cdk'; import * as ec2 from 'aws-cdk-lib/aws-ec2'; @@ -12,14 +11,12 @@ import { const config = new pulumi.Config(); const zoneName = config.require('zoneName'); -const accountId = config.require('accountId'); -const region = aws.config.requireRegion(); export class Ec2CdkStack extends pulumicdk.Stack { constructor(app: pulumicdk.App, id: string) { super(app, id, { props: { - env: { region, account: accountId }, + env: app.env, }, }); diff --git a/src/stack.ts b/src/stack.ts index 3bacf67..ad1a1ac 100644 --- a/src/stack.ts +++ b/src/stack.ts @@ -140,11 +140,17 @@ export class App } /** - * Because the app creates CDK Stacks in an async function, we can grab the - * environment from the AWS CCAPI provider used by the App and make that available - * as the CDK Environment for the Stacks. + * This can be used to get the CDK Environment based on the Pulumi Provider used for the App. + * You can then use this to configure an explicit environment on Stacks. * - * @internal + * @example + * const app = new pulumicdk.App('app', (scope: pulumicdk.App) => { + * const stack = new pulumicdk.Stack(scope, 'pulumi-stack', { + * props: { env: app.env }, + * }); + * }); + * + * @returns the CDK Environment configured for the App */ public get env(): cdk.Environment { if (!this._env) { @@ -328,27 +334,7 @@ export class Stack extends cdk.Stack { * @param options A bag of options that control this resource's behavior. */ constructor(private readonly app: App, name: string, options?: StackOptions) { - const env: Writeable = options?.props?.env ?? {}; - const hasNativeProvider = hasProvider(options?.providers, (p) => native.Provider.isInstance(p)); - - if (!env.account && !hasNativeProvider) { - env.account = app.env.account; - } - - // if the user has provided a separate native provider to the stack - // then we don't want to set the region from the app provider. The stack will - // be an environment agnostic (and determine the region from the provider) unless - // they provide a region to the stack props. - if (!env.region && !hasNativeProvider) { - env.region = app.env.region; - } - - super(app.app, name, { - // set the env based on the credentials of the App - // but allow the user to override it - ...options?.props, - env: env, - }); + super(app.app, name, options?.props); Object.defineProperty(this, STACK_SYMBOL, { value: true }); this.options = options;