Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pipelines): add property to specify a namespace so exported variables can be used #15964

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/yarn-upgrade.yml
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v2

- name: Set up Node
uses: actions/setup-node@v2.3.0
uses: actions/setup-node@v2.4.0
with:
node-version: 10

Expand Down
22 changes: 12 additions & 10 deletions packages/@aws-cdk/aws-glue/test/database.test.ts
@@ -1,10 +1,19 @@
import { Template } from '@aws-cdk/assertions';
import { Stack } from '@aws-cdk/core';
import { App, Stack } from '@aws-cdk/core';
import * as glue from '../lib';

test('default database does not create a bucket', () => {
const stack = new Stack();
let stack: Stack;

beforeEach( () => {
const app = new App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
stack = new Stack(app);
});

test('default database does not create a bucket', () => {
new glue.Database(stack, 'Database', {
databaseName: 'test_database',
});
Expand All @@ -28,8 +37,6 @@ test('default database does not create a bucket', () => {
});

test('explicit locationURI', () => {
const stack = new Stack();

new glue.Database(stack, 'Database', {
databaseName: 'test_database',
locationUri: 's3://my-uri/',
Expand All @@ -55,9 +62,6 @@ test('explicit locationURI', () => {
});

test('fromDatabase', () => {
// GIVEN
const stack = new Stack();

// WHEN
const database = glue.Database.fromDatabaseArn(stack, 'import', 'arn:aws:glue:us-east-1:123456789012:database/db1');

Expand All @@ -72,7 +76,6 @@ test('fromDatabase', () => {
});

test('locationUri length must be >= 1', () => {
const stack = new Stack();
expect(() =>
new glue.Database(stack, 'Database', {
databaseName: 'test_database',
Expand All @@ -82,7 +85,6 @@ test('locationUri length must be >= 1', () => {
});

test('locationUri length must be <= 1024', () => {
const stack = new Stack();
expect(() =>
new glue.Database(stack, 'Database', {
databaseName: 'test_database',
Expand Down
31 changes: 12 additions & 19 deletions packages/@aws-cdk/aws-ivs/test/ivs.test.ts
@@ -1,5 +1,5 @@
import { Template } from '@aws-cdk/assertions';
import { Stack } from '@aws-cdk/core';
import { App, Stack } from '@aws-cdk/core';
import * as ivs from '../lib';

const publicKey = `-----BEGIN PUBLIC KEY-----
Expand All @@ -8,8 +8,18 @@ Yfo83eX0GJCKxJ8fr09h9LP9HDGof8/bo66P+SGHeAARGF/O9WPAQVUgSlm/KMFX
EPtPtOm1s0GR9k1ydU5hkI++f9CoZ5lM
-----END PUBLIC KEY-----`;

let stack: Stack;

beforeEach( () => {
const app = new App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
stack = new Stack(app);
});

test('channel default properties', () => {
const stack = new Stack();
new ivs.Channel(stack, 'Channel');

Template.fromStack(stack).templateMatches({
Expand All @@ -22,7 +32,6 @@ test('channel default properties', () => {
});

test('channel name', () => {
const stack = new Stack();
new ivs.Channel(stack, 'Channel', {
name: 'CarrotsAreTasty',
});
Expand All @@ -40,7 +49,6 @@ test('channel name', () => {
});

test('channel is authorized', () => {
const stack = new Stack();
new ivs.Channel(stack, 'Channel', {
authorized: true,
});
Expand All @@ -58,7 +66,6 @@ test('channel is authorized', () => {
});

test('channel type', () => {
const stack = new Stack();
new ivs.Channel(stack, 'Channel', {
type: ivs.ChannelType.BASIC,
});
Expand All @@ -76,7 +83,6 @@ test('channel type', () => {
});

test('channel latency mode', () => {
const stack = new Stack();
new ivs.Channel(stack, 'Channel', {
latencyMode: ivs.LatencyMode.NORMAL,
});
Expand All @@ -94,22 +100,18 @@ test('channel latency mode', () => {
});

test('channel from arn', () => {
const stack = new Stack();
const channel = ivs.Channel.fromChannelArn(stack, 'Channel', 'arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh');

expect(stack.resolve(channel.channelArn)).toBe('arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh');
});

test('channel invalid name throws validation error', () => {
const stack = new Stack();

expect(() => new ivs.Channel(stack, 'Channel', {
name: 'Would you like a carrot?',
})).toThrow('name must contain only numbers, letters, hyphens and underscores, got: \'Would you like a carrot?\'');
});

test('playback key pair mandatory properties', () => {
const stack = new Stack();
new ivs.PlaybackKeyPair(stack, 'PlaybackKeyPair', {
publicKeyMaterial: publicKey,
});
Expand All @@ -127,7 +129,6 @@ test('playback key pair mandatory properties', () => {
});

test('playback key pair name', () => {
const stack = new Stack();
new ivs.PlaybackKeyPair(stack, 'PlaybackKeyPair', {
publicKeyMaterial: publicKey,
name: 'CarrotsAreNutritious',
Expand All @@ -147,16 +148,13 @@ test('playback key pair name', () => {
});

test('playback key pair invalid name throws validation error', () => {
const stack = new Stack();

expect(() => new ivs.PlaybackKeyPair(stack, 'PlaybackKeyPair', {
publicKeyMaterial: 'Carrots Are Orange',
name: 'Would you like a carrot?',
})).toThrow('name must contain only numbers, letters, hyphens and underscores, got: \'Would you like a carrot?\'');
});

test('stream key mandatory properties', () => {
const stack = new Stack();
new ivs.StreamKey(stack, 'StreamKey', {
channel: ivs.Channel.fromChannelArn(stack, 'ChannelRef', 'arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh'),
});
Expand All @@ -174,7 +172,6 @@ test('stream key mandatory properties', () => {
});

test('channel and stream key.. at the same time', () => {
const stack = new Stack();
const channel = new ivs.Channel(stack, 'Channel');
channel.addStreamKey('StreamKey');

Expand All @@ -194,7 +191,6 @@ test('channel and stream key.. at the same time', () => {
});

test('stream key from channel reference', () => {
const stack = new Stack();
const channel = ivs.Channel.fromChannelArn(stack, 'Channel', 'arn:aws:ivs:us-west-2:123456789012:channel/abcdABCDefgh');
channel.addStreamKey('StreamKey');

Expand All @@ -211,20 +207,17 @@ test('stream key from channel reference', () => {
});

test('channel from invalid channel arn throws error', () => {
const stack = new Stack();
expect(() => ivs.Channel.fromChannelArn(stack, 'ChannelRef', 'this is an invalid arn, in fact, it is a carrot 🥕'))
.toThrow('ARNs must start with \"arn:\" and have at least 6 components: this is an invalid arn, in fact, it is a carrot 🥕');
});

test('channel from invalid channel arn service throws error', () => {
const stack = new Stack();
expect(
() => ivs.Channel.fromChannelArn(stack, 'ChannelRef', 'arn:aws:ec2:us-west-2:123456789012:instance/abcdABCDefgh'))
.toThrow('Invalid service, expected \'ivs\', got \'ec2\'');
});

test('channel from invalid channel arn resource throws error', () => {
const stack = new Stack();
expect(
() => ivs.Channel.fromChannelArn(stack, 'ChannelRef', 'arn:aws:ivs:us-west-2:123456789012:stream-key/abcdABCDefgh'))
.toThrow('Invalid resource, expected \'channel\', got \'stream-key\'');
Expand Down
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-msk/test/cluster.test.ts
Expand Up @@ -13,7 +13,12 @@ describe('MSK Cluster', () => {
let vpc: ec2.IVpc;

beforeEach(() => {
stack = new core.Stack();
const app = new core.App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
stack = new core.Stack(app);
vpc = new ec2.Vpc(stack, 'Vpc');
});

Expand Down
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-sam/test/application.test.ts
Expand Up @@ -3,7 +3,12 @@ import * as cdk from '@aws-cdk/core';
import { CfnApplication } from '../lib';

test('construct an AWS::Serverless::Application', () => {
const stack = new cdk.Stack();
const app = new cdk.App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
const stack = new cdk.Stack(app);

new CfnApplication(stack, 'App', {
location: {
Expand Down
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-servicecatalog/test/portfolio.test.ts
Expand Up @@ -8,7 +8,12 @@ describe('Portfolio', () => {
let stack: cdk.Stack;

beforeEach(() => {
stack = new cdk.Stack();
const app = new cdk.App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
stack = new cdk.Stack(app);
});

describe('portfolio creation and importing', () => {
Expand Down
Expand Up @@ -6,7 +6,12 @@ describe('Application', () => {
let stack: cdk.Stack;

beforeEach(() => {
stack = new cdk.Stack();
const app = new cdk.App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
stack = new cdk.Stack(app);
});

test('default application creation', () => {
Expand Down
Expand Up @@ -6,7 +6,12 @@ describe('Attribute Group', () => {
let stack: cdk.Stack;

beforeEach(() => {
stack = new cdk.Stack();
const app = new cdk.App({
context: {
'@aws-cdk/core:newStyleStackSynthesis': false,
},
});
stack = new cdk.Stack(app);
});

test('default attribute group creation', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/pipelines/README.md
Expand Up @@ -569,6 +569,9 @@ new CodeBuildStep('Synth', {
computeType: codebuild.ComputeType.LARGE,
},

// Make any exported variables available to other actions
variableNamespace: "example",

// Control Elastic Network Interface creation
vpc: vpc,
subnetSelection: { subnetType: ec2.SubnetType.PRIVATE },
Expand Down
Expand Up @@ -110,6 +110,13 @@ export interface CodeBuildFactoryProps {
* @default false
*/
readonly isSynth?: boolean;

/**
* The name of the namespace to use for variables emitted by this action.
*
* @default - no name space will be generated
*/
readonly variablesNamespace?: string;
}

/**
Expand Down Expand Up @@ -146,6 +153,7 @@ export class CodeBuildFactory implements ICodePipelineActionFactory {
subnetSelection: step.subnetSelection,
...additional?.projectOptions,
},
variablesNamespace: step.variablesNamespace,
...additional,
});

Expand Down Expand Up @@ -300,6 +308,7 @@ export class CodeBuildFactory implements ICodePipelineActionFactory {
outputs: outputArtifacts,
project,
runOrder: options.runOrder,
variablesNamespace: this.props.variablesNamespace,

// Inclusion of the hash here will lead to the pipeline structure for any changes
// made the config of the underlying CodeBuild Project.
Expand Down
15 changes: 15 additions & 0 deletions packages/@aws-cdk/pipelines/lib/codepipeline/codebuild-step.ts
Expand Up @@ -82,6 +82,13 @@ export interface CodeBuildStepProps extends ShellStepProps {
* @default - Security group will be automatically created.
*/
readonly securityGroups?: ec2.ISecurityGroup[];

/**
* The name of the namespace to use for variables emitted by this action.
*
* @default - no namespace will be generated
*/
readonly variablesNamespace?: string;
}

/**
Expand Down Expand Up @@ -144,6 +151,13 @@ export class CodeBuildStep extends ShellStep {
*/
readonly securityGroups?: ec2.ISecurityGroup[];

/**
* The name of the namespace to use for variables emitted by this action.
*
* @default - no namespace will be generated
*/
readonly variablesNamespace?: string;

private _project?: codebuild.IProject;

constructor(id: string, props: CodeBuildStepProps) {
Expand All @@ -157,6 +171,7 @@ export class CodeBuildStep extends ShellStep {
this.role = props.role;
this.rolePolicyStatements = props.rolePolicyStatements;
this.securityGroups = props.securityGroups;
this.variablesNamespace = props.variablesNamespace;
}

/**
Expand Down