Skip to content

Commit

Permalink
Merge branch 'master' into huijbers/empty-zip
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jan 18, 2022
2 parents a3ba43e + dcf6870 commit 1f5edb3
Show file tree
Hide file tree
Showing 29 changed files with 315 additions and 192 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert-internal": "0.0.0",
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cdk-integ-tools": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/assets/test/compat.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SymlinkFollowMode } from '@aws-cdk/core';
import '@aws-cdk/assert-internal/jest';
import { FollowMode } from '../lib';
import { toSymlinkFollow } from '../lib/compat';

Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/assets/test/staging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as path from 'path';
import { describeDeprecated } from '@aws-cdk/cdk-build-tools';
import { App, Stack } from '@aws-cdk/core';
import * as cxapi from '@aws-cdk/cx-api';
import '@aws-cdk/assert-internal/jest';
import { Staging } from '../lib';

describeDeprecated('staging', () => {
Expand Down
11 changes: 8 additions & 3 deletions packages/@aws-cdk/aws-ec2/lib/aspects/require-imdsv2-aspect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as cdk from '@aws-cdk/core';
import { FeatureFlags } from '@aws-cdk/core';
import * as cxapi from '@aws-cdk/cx-api';
import { CfnLaunchTemplate } from '../ec2.generated';
import { Instance } from '../instance';
import { LaunchTemplate } from '../launch-template';
Expand Down Expand Up @@ -83,17 +85,20 @@ export class InstanceRequireImdsv2Aspect extends RequireImdsv2Aspect {
return;
}

const name = `${node.node.id}LaunchTemplate`;
const launchTemplate = new CfnLaunchTemplate(node, 'LaunchTemplate', {
launchTemplateData: {
metadataOptions: {
httpTokens: 'required',
},
},
launchTemplateName: name,
});
if (FeatureFlags.of(node).isEnabled(cxapi.EC2_UNIQUE_IMDSV2_LAUNCH_TEMPLATE_NAME)) {
launchTemplate.launchTemplateName = cdk.Names.uniqueId(launchTemplate);
} else {
launchTemplate.launchTemplateName = `${node.node.id}LaunchTemplate`;
}
node.instance.launchTemplate = {
launchTemplateName: name,
launchTemplateName: launchTemplate.launchTemplateName,
version: launchTemplate.getAtt('LatestVersionNumber').toString(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
haveResourceLike,
} from '@aws-cdk/assert-internal';
import '@aws-cdk/assert-internal/jest';
import { testFutureBehavior, testLegacyBehavior } from '@aws-cdk/cdk-build-tools';
import * as cdk from '@aws-cdk/core';
import * as cxapi from '@aws-cdk/cx-api';
import {
CfnLaunchTemplate,
Instance,
Expand Down Expand Up @@ -135,6 +137,57 @@ describe('RequireImdsv2Aspect', () => {
trace: undefined,
});
});

testFutureBehavior('launch template name is unique with feature flag', { [cxapi.EC2_UNIQUE_IMDSV2_LAUNCH_TEMPLATE_NAME]: true }, cdk.App, (app2) => {
// GIVEN
const otherStack = new cdk.Stack(app2, 'OtherStack');
const otherVpc = new Vpc(otherStack, 'OtherVpc');
const otherInstance = new Instance(otherStack, 'OtherInstance', {
vpc: otherVpc,
instanceType: new InstanceType('t2.micro'),
machineImage: MachineImage.latestAmazonLinux(),
});
const imdsv2Stack = new cdk.Stack(app2, 'RequireImdsv2Stack');
const imdsv2Vpc = new Vpc(imdsv2Stack, 'Vpc');
const instance = new Instance(imdsv2Stack, 'Instance', {
vpc: imdsv2Vpc,
instanceType: new InstanceType('t2.micro'),
machineImage: MachineImage.latestAmazonLinux(),
});
const aspect = new InstanceRequireImdsv2Aspect();

// WHEN
cdk.Aspects.of(imdsv2Stack).add(aspect);
cdk.Aspects.of(otherStack).add(aspect);
app2.synth();

// THEN
const launchTemplate = instance.node.tryFindChild('LaunchTemplate') as LaunchTemplate;
const otherLaunchTemplate = otherInstance.node.tryFindChild('LaunchTemplate') as LaunchTemplate;
expect(launchTemplate).toBeDefined();
expect(otherLaunchTemplate).toBeDefined();
expect(launchTemplate.launchTemplateName !== otherLaunchTemplate.launchTemplateName);
});

testLegacyBehavior('launch template name uses legacy id without feature flag', cdk.App, (app2) => {
// GIVEN
const imdsv2Stack = new cdk.Stack(app2, 'RequireImdsv2Stack');
const imdsv2Vpc = new Vpc(imdsv2Stack, 'Vpc');
const instance = new Instance(imdsv2Stack, 'Instance', {
vpc: imdsv2Vpc,
instanceType: new InstanceType('t2.micro'),
machineImage: MachineImage.latestAmazonLinux(),
});
const aspect = new InstanceRequireImdsv2Aspect();

// WHEN
cdk.Aspects.of(imdsv2Stack).add(aspect);
app2.synth();

// THEN
const launchTemplate = instance.node.tryFindChild('LaunchTemplate') as LaunchTemplate;
expect(launchTemplate.launchTemplateName).toEqual(`${instance.node.id}LaunchTemplate`);
});
});

describe('LaunchTemplateRequireImdsv2Aspect', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-kinesis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert-internal": "0.0.0",
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cdk-integ-tools": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
Expand Down
Loading

0 comments on commit 1f5edb3

Please sign in to comment.