Skip to content

Commit 7932bfa

Browse files
committed
Rip out non-AMI/SSM additionalCacheKey
1 parent fe68e7b commit 7932bfa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+973
-6445
lines changed

packages/aws-cdk-lib/aws-ec2/README.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,6 @@ called `cdk.context.json`. You must commit this file to source control so
626626
that the lookup values are available in non-privileged environments such
627627
as CI build steps, and to ensure your template builds are repeatable.
628628

629-
To customize the cache key, use the `additionalCacheKey` parameter.
630-
This allows you to have multiple lookups with the same parameters
631-
cache their values separately. This can be useful if you want to
632-
scope the context variable to a construct (ie, using `additionalCacheKey: this.node.path`),
633-
so that if the value in the cache needs to be updated, it does not need to be updated
634-
for all constructs at the same time.
635-
636629
Here's how `Vpc.fromLookup()` can be used:
637630

638631
[importing existing VPCs](test/integ.import-default-vpc.lit.ts)
@@ -878,13 +871,6 @@ written to a file called `cdk.context.json`.
878871
You must commit this file to source control so that the lookup values are available in non-privileged
879872
environments such as CI build steps, and to ensure your template builds are repeatable.
880873

881-
To customize the cache key, use the `additionalCacheKey` property of the `options` parameter.
882-
This allows you to have multiple lookups with the same parameters
883-
cache their values separately. This can be useful if you want to
884-
scope the context variable to a construct (ie, using `additionalCacheKey: this.node.path`),
885-
so that if the value in the cache needs to be updated, it does not need to be updated
886-
for all constructs at the same time.
887-
888874
### Cross Stack Connections
889875

890876
If you are attempting to add a connection from a peer in one stack to a peer in a different stack, sometimes it is necessary to ensure that you are making the connection in

packages/aws-cdk-lib/aws-ec2/lib/security-group.ts

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { IPeer, Peer } from './peer';
55
import { Port } from './port';
66
import { IVpc } from './vpc';
77
import * as cxschema from '../../cloud-assembly-schema';
8-
import { Annotations, ContextProvider, IResource, Lazy, Names, Resource, ResourceProps, Stack, Token, ValidationError } from '../../core';
9-
import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource';
8+
import { Annotations, ContextProvider, IResource, Lazy, Names, Resource, ResourceProps, Stack, Token } from '../../core';
109
import * as cxapi from '../../cx-api';
1110

1211
const SECURITY_GROUP_SYMBOL = Symbol.for('@aws-cdk/iam.SecurityGroup');
@@ -180,6 +179,7 @@ abstract class SecurityGroupBase extends Resource implements ISecurityGroup {
180179
connection: Port,
181180
fromTo: 'from' | 'to',
182181
remoteRule?: boolean): RuleScope {
182+
183183
if (remoteRule && SecurityGroupBase.isSecurityGroup(peer) && differentStacks(this, peer)) {
184184
// Reversed
185185
const reversedFromTo = fromTo === 'from' ? 'to' : 'from';
@@ -280,7 +280,7 @@ export interface SecurityGroupProps {
280280
* Inlining rules is an optimization for producing smaller stack templates. Sometimes
281281
* this is not desirable, for example when security group access is managed via tags.
282282
*
283-
* The default value can be overridden globally by setting the context variable
283+
* The default value can be overriden globally by setting the context variable
284284
* '@aws-cdk/aws-ec2.securityGroupDisableInlineRules'.
285285
*
286286
* @default false
@@ -369,22 +369,22 @@ export class SecurityGroup extends SecurityGroupBase {
369369
*
370370
* @deprecated Use `fromLookupById()` instead
371371
*/
372-
public static fromLookup(scope: Construct, id: string, securityGroupId: string, options?: BaseSecurityGroupLookupOptions) {
373-
return this.fromLookupAttributes(scope, id, { securityGroupId, ...options });
372+
public static fromLookup(scope: Construct, id: string, securityGroupId: string) {
373+
return this.fromLookupAttributes(scope, id, { securityGroupId });
374374
}
375375

376376
/**
377377
* Look up a security group by id.
378378
*/
379-
public static fromLookupById(scope: Construct, id: string, securityGroupId: string, options?: BaseSecurityGroupLookupOptions) {
380-
return this.fromLookupAttributes(scope, id, { securityGroupId, ...options });
379+
public static fromLookupById(scope: Construct, id: string, securityGroupId: string) {
380+
return this.fromLookupAttributes(scope, id, { securityGroupId });
381381
}
382382

383383
/**
384384
* Look up a security group by name.
385385
*/
386-
public static fromLookupByName(scope: Construct, id: string, securityGroupName: string, vpc: IVpc, options?: BaseSecurityGroupLookupOptions) {
387-
return this.fromLookupAttributes(scope, id, { securityGroupName, vpc, ...options });
386+
public static fromLookupByName(scope: Construct, id: string, securityGroupName: string, vpc: IVpc) {
387+
return this.fromLookupAttributes(scope, id, { securityGroupName, vpc });
388388
}
389389

390390
/**
@@ -434,8 +434,8 @@ export class SecurityGroup extends SecurityGroupBase {
434434
* Look up a security group.
435435
*/
436436
private static fromLookupAttributes(scope: Construct, id: string, options: SecurityGroupLookupOptions) {
437-
if (Token.isUnresolved(options.securityGroupId) || Token.isUnresolved(options.securityGroupName) || Token.isUnresolved(options.vpc?.vpcId)) {
438-
throw new ValidationError('All arguments to look up a security group must be concrete (no Tokens)', scope);
437+
if (Token.isUnresolved(options.securityGroupId) || Token.isUnresolved(options.securityGroupName) || Token.isUnresolved(options.vpc?.vpcId)) {
438+
throw new Error('All arguments to look up a security group must be concrete (no Tokens)');
439439
}
440440

441441
const attributes: cxapi.SecurityGroupContextResponse = ContextProvider.getValue(scope, {
@@ -449,7 +449,6 @@ export class SecurityGroup extends SecurityGroupBase {
449449
securityGroupId: 'sg-12345678',
450450
allowAllOutbound: true,
451451
} as cxapi.SecurityGroupContextResponse,
452-
additionalCacheKey: options.additionalCacheKey,
453452
}).value;
454453

455454
return SecurityGroup.fromSecurityGroupId(scope, id, attributes.securityGroupId, {
@@ -503,8 +502,6 @@ export class SecurityGroup extends SecurityGroupBase {
503502
super(scope, id, {
504503
physicalName: props.securityGroupName,
505504
});
506-
// Enhanced CDK Analytics Telemetry
507-
addConstructMetadata(this, props);
508505

509506
const groupDescription = props.description || this.node.path;
510507

@@ -518,8 +515,8 @@ export class SecurityGroup extends SecurityGroupBase {
518515
this.securityGroup = new CfnSecurityGroup(this, 'Resource', {
519516
groupName: this.physicalName,
520517
groupDescription,
521-
securityGroupIngress: Lazy.any({ produce: () => this.directIngressRules }, { omitEmptyArray: true }),
522-
securityGroupEgress: Lazy.any({ produce: () => this.directEgressRules }, { omitEmptyArray: true }),
518+
securityGroupIngress: Lazy.any({ produce: () => this.directIngressRules }, { omitEmptyArray: true } ),
519+
securityGroupEgress: Lazy.any({ produce: () => this.directEgressRules }, { omitEmptyArray: true } ),
523520
vpcId: props.vpc.vpcId,
524521
});
525522

@@ -531,7 +528,6 @@ export class SecurityGroup extends SecurityGroupBase {
531528
this.addDefaultIpv6EgressRule();
532529
}
533530

534-
@MethodMetadata()
535531
public addIngressRule(peer: IPeer, connection: Port, description?: string, remoteRule?: boolean) {
536532
if (!peer.canInlineRule || !connection.canInlineRule || this.disableInlineRules) {
537533
super.addIngressRule(peer, connection, description, remoteRule);
@@ -549,15 +545,14 @@ export class SecurityGroup extends SecurityGroupBase {
549545
});
550546
}
551547

552-
@MethodMetadata()
553548
public addEgressRule(peer: IPeer, connection: Port, description?: string, remoteRule?: boolean) {
554549
const isIpv6 = peer.toEgressRuleConfig().hasOwnProperty('cidrIpv6');
555550

556551
if (!isIpv6 && this.allowAllOutbound) {
557552
// In the case of "allowAllOutbound", we don't add any more rules. There
558553
// is only one rule which allows all traffic and that subsumes any other
559554
// rule.
560-
if (!remoteRule) { // Warn only if addEgressRule() was explicitly called
555+
if (!remoteRule) { // Warn only if addEgressRule() was explicitely called
561556
Annotations.of(this).addWarningV2('@aws-cdk/aws-ec2:ipv4IgnoreEgressRule', 'Ignoring Egress rule since \'allowAllOutbound\' is set to true; To add customized rules, set allowAllOutbound=false on the SecurityGroup');
562557
}
563558
return;
@@ -572,7 +567,7 @@ export class SecurityGroup extends SecurityGroupBase {
572567
// In the case of "allowAllIpv6Outbound", we don't add any more rules. There
573568
// is only one rule which allows all traffic and that subsumes any other
574569
// rule.
575-
if (!remoteRule) { // Warn only if addEgressRule() was explicitly called
570+
if (!remoteRule) { // Warn only if addEgressRule() was explicitely called
576571
Annotations.of(this).addWarningV2('@aws-cdk/aws-ec2:ipv6IgnoreEgressRule', 'Ignoring Egress rule since \'allowAllIpv6Outbound\' is set to true; To add customized rules, set allowAllIpv6Outbound=false on the SecurityGroup');
577572
}
578573
return;
@@ -599,7 +594,7 @@ export class SecurityGroup extends SecurityGroupBase {
599594
// to "allOutbound=true" mode, because we might have already emitted
600595
// EgressRule objects (which count as rules added later) and there's no way
601596
// to recall those. Better to prevent this for now.
602-
throw new ValidationError('Cannot add an "all traffic" egress rule in this way; set allowAllOutbound=true (for ipv6) or allowAllIpv6Outbound=true (for ipv6) on the SecurityGroup instead.', this);
597+
throw new Error('Cannot add an "all traffic" egress rule in this way; set allowAllOutbound=true (for ipv6) or allowAllIpv6Outbound=true (for ipv6) on the SecurityGroup instead.');
603598
}
604599

605600
this.addDirectEgressRule(rule);
@@ -658,7 +653,7 @@ export class SecurityGroup extends SecurityGroupBase {
658653
const description = this.allowAllOutbound ? ALLOW_ALL_RULE.description : MATCH_NO_TRAFFIC.description;
659654
super.addEgressRule(peer, port, description, false);
660655
} else {
661-
const rule = this.allowAllOutbound ? ALLOW_ALL_RULE : MATCH_NO_TRAFFIC;
656+
const rule = this.allowAllOutbound? ALLOW_ALL_RULE : MATCH_NO_TRAFFIC;
662657
this.directEgressRules.push(rule);
663658
}
664659
}
@@ -816,24 +811,12 @@ function isAllTrafficRule(rule: any) {
816811
return (rule.cidrIp === '0.0.0.0/0' || rule.cidrIpv6 === '::/0') && rule.ipProtocol === '-1';
817812
}
818813

819-
/**
820-
* Base properties for looking up an existing SecurityGroup.
821-
*/
822-
export interface BaseSecurityGroupLookupOptions {
823-
/**
824-
* Adds an additional discriminator to the `cdk.context.json` cache key.
825-
*
826-
* @default - no additional cache key
827-
*/
828-
readonly additionalCacheKey?: string;
829-
}
830-
831814
/**
832815
* Properties for looking up an existing SecurityGroup.
833816
*
834817
* Either `securityGroupName` or `securityGroupId` has to be specified.
835818
*/
836-
interface SecurityGroupLookupOptions extends BaseSecurityGroupLookupOptions {
819+
interface SecurityGroupLookupOptions {
837820
/**
838821
* The name of the security group
839822
*
@@ -859,12 +842,5 @@ interface SecurityGroupLookupOptions extends BaseSecurityGroupLookupOptions {
859842
*
860843
* @default Don't filter on VPC
861844
*/
862-
readonly vpc?: IVpc;
863-
864-
/**
865-
* Adds an additional discriminator to the `cdk.context.json` cache key.
866-
*
867-
* @default - no additional cache key
868-
*/
869-
readonly additionalCacheKey?: string;
845+
readonly vpc?: IVpc,
870846
}

packages/aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,4 @@ export interface VpcLookupOptions {
7575
* @default the account id of the parent stack
7676
*/
7777
readonly ownerAccountId?: string;
78-
79-
/**
80-
* Adds an additional discriminator to the `cdk.context.json` cache key.
81-
*
82-
* @default - no additional cache key
83-
*/
84-
readonly additionalCacheKey?: string;
8578
}

0 commit comments

Comments
 (0)