Skip to content

Commit

Permalink
refactor: lookupExport into an internal concern
Browse files Browse the repository at this point in the history
fix: update broken test from rebase
  • Loading branch information
tomwwright committed Oct 1, 2023
1 parent e162bd2 commit c459a47
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/aws-cdk/lib/api/evaluate-cloudformation-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export interface EvaluateCloudFormationTemplateProps {
readonly urlSuffix: (region: string) => string;
readonly sdk: ISDK;
readonly nestedStackNames?: { [nestedStackLogicalId: string]: NestedStackNames };
readonly lookupExport: LookupExport;
}

export class EvaluateCloudFormationTemplate {
Expand All @@ -123,7 +122,6 @@ export class EvaluateCloudFormationTemplate {

constructor(props: EvaluateCloudFormationTemplateProps) {
this.stackName = props.stackName;
this.lookupExport = props.lookupExport;
this.template = props.template;
this.context = {
'AWS::AccountId': props.account,
Expand All @@ -144,6 +142,9 @@ export class EvaluateCloudFormationTemplate {
// We need them to figure out the physical name of a resource in case it wasn't specified by the user.
// We fetch it lazily, to save a service call, in case all hotswapped resources have their physical names set.
this.stackResources = new LazyListStackResources(this.sdk, this.stackName);

// CloudFormation Exports lookup to be able to resolve Fn::ImportValue intrinsics in template
this.lookupExport = new LazyLookupExport(this.sdk);
}

// clones current EvaluateCloudFormationTemplate object, but updates the stack name
Expand All @@ -163,7 +164,6 @@ export class EvaluateCloudFormationTemplate {
urlSuffix: this.urlSuffix,
sdk: this.sdk,
nestedStackNames: this.nestedStackNames,
lookupExport: this.lookupExport,
});
}

Expand Down
3 changes: 0 additions & 3 deletions packages/aws-cdk/lib/api/hotswap-deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ export async function tryHotswapDeployment(

const currentTemplate = await loadCurrentTemplateWithNestedStacks(stackArtifact, sdk);

// CloudFormation Exports lookup to be able to resolve Fn::ImportValue intrinsics in template
const lookupExport = new LazyLookupExport(sdk);
const evaluateCfnTemplate = new EvaluateCloudFormationTemplate({
stackName: stackArtifact.stackName,
template: stackArtifact.template,
Expand All @@ -71,7 +69,6 @@ export async function tryHotswapDeployment(
urlSuffix: (region) => sdk.getEndpointSuffix(region),
sdk,
nestedStackNames: currentTemplate.nestedStackNames,
lookupExport,
});

const stackChanges = cfn_diff.diffTemplate(currentTemplate.deployedTemplate, stackArtifact.template);
Expand Down
4 changes: 1 addition & 3 deletions packages/aws-cdk/lib/api/logs/find-cloudwatch-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as cxapi from '@aws-cdk/cx-api';
import { CloudFormation } from 'aws-sdk';
import { Mode, SdkProvider, ISDK } from '../aws-auth';
import { Deployments } from '../deployments';
import { EvaluateCloudFormationTemplate, LazyListStackResources, LazyLookupExport } from '../evaluate-cloudformation-template';
import { EvaluateCloudFormationTemplate, LazyListStackResources } from '../evaluate-cloudformation-template';

// resource types that have associated CloudWatch Log Groups that should _not_ be monitored
const IGNORE_LOGS_RESOURCE_TYPES = ['AWS::EC2::FlowLog', 'AWS::CloudTrail::Trail', 'AWS::CodeBuild::Project'];
Expand Down Expand Up @@ -55,7 +55,6 @@ export async function findCloudWatchLogGroups(
}

const listStackResources = new LazyListStackResources(sdk, stackArtifact.stackName);
const lookupExport = new LazyLookupExport(sdk);
const evaluateCfnTemplate = new EvaluateCloudFormationTemplate({
stackName: stackArtifact.stackName,
template: stackArtifact.template,
Expand All @@ -65,7 +64,6 @@ export async function findCloudWatchLogGroups(
partition: (await sdk.currentAccount()).partition,
urlSuffix: (region) => sdk.getEndpointSuffix(region),
sdk,
lookupExport,
});

const stackResources = await listStackResources.listStackResources();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
CfnEvaluationException,
EvaluateCloudFormationTemplate,
LazyListStackResources,
LazyLookupExport,
Template,
} from '../../lib/api/evaluate-cloudformation-template';
import { MockSdk } from '../util/mock-sdk';
Expand All @@ -22,8 +20,8 @@ const createEvaluateCloudFormationTemplate = (template: Template) => new Evaluat
region: 'ap-south-east-2',
partition: 'aws',
urlSuffix: (region) => sdk.getEndpointSuffix(region),
listStackResources: new LazyListStackResources(sdk, 'test-stack'),
lookupExport: new LazyLookupExport(sdk),
sdk,
stackName: 'test-stack',
});

describe('evaluateCfnExpression', () => {
Expand Down

0 comments on commit c459a47

Please sign in to comment.