Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
corymhall committed Nov 22, 2024
1 parent 08be058 commit 4d93a76
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 32 deletions.
37 changes: 34 additions & 3 deletions api-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions examples/lookups-enabled/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
},
});

Expand Down
36 changes: 11 additions & 25 deletions src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<cdk.Environment> = 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;
Expand Down

0 comments on commit 4d93a76

Please sign in to comment.