Skip to content

Commit

Permalink
feat!: changing physical resource naming convention (#361)
Browse files Browse the repository at this point in the history
Fixes #360 

Implements a default naming strategy for `Flow` resources. Now, when no `name` property is passed to a construct the name is autogenerated with a hash suffix. Additionally, automated naming adheres to the [FlowName CFN specification](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appflow-flow.html#cfn-appflow-flow-flowname).
  • Loading branch information
rpawlaszek authored Oct 11, 2024
1 parent 88f7a83 commit ae10356
Show file tree
Hide file tree
Showing 43 changed files with 80 additions and 70 deletions.
18 changes: 14 additions & 4 deletions src/core/flows/flow-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
import { Duration, IResource, Lazy, Resource } from 'aws-cdk-lib';
import { Duration, IResource, Lazy, Names, Resource } from 'aws-cdk-lib';
import { CfnFlow } from 'aws-cdk-lib/aws-appflow';

import { Metric, MetricOptions } from 'aws-cdk-lib/aws-cloudwatch';
Expand Down Expand Up @@ -187,15 +187,24 @@ export abstract class FlowBase extends Resource implements IFlow {
private _projectionFilter: CfnFlow.TaskProperty;

constructor(scope: Construct, id: string, props: FlowBaseProps) {
super(scope, id);
super(scope, id, {
physicalName:
props.name ||
Lazy.string({
produce: () =>
Names.uniqueResourceName(this, {
maxLength: 256,
allowedSpecialCharacters: '-_',
}),
}),
});

this.type = props.type;

this._projectionFilter = this.initProjectionFilter(props.source.connectorType);

this.name = props.name || id;
const resource = new CfnFlow(this, id, {
flowName: this.name,
flowName: this.physicalName,
flowStatus: props.status,
triggerConfig: {
triggerType: props.type,
Expand Down Expand Up @@ -233,6 +242,7 @@ export abstract class FlowBase extends Resource implements IFlow {
});

this.arn = resource.attrFlowArn;
this.name = this.physicalName;
this.source = props.source;

props.mappings.forEach(m => this._addMapping(m));
Expand Down
2 changes: 1 addition & 1 deletion test/core/flows/on-demand-flow-metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '../../../src';

describe('OnDemandFlow metrics', () => {
test('', () => {
test('default', () => {

const stack = new Stack(undefined, 'TestStack');

Expand Down
4 changes: 2 additions & 2 deletions test/core/flows/on-demand-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '../../../src';

describe('OnDemandFlow', () => {
test('', () => {
test('default', () => {

const stack = new Stack(undefined, 'TestStack');

Expand Down Expand Up @@ -53,7 +53,7 @@ describe('OnDemandFlow', () => {
},
},
],
FlowName: 'OnDemandFlow',
FlowName: 'TestStackOnDemandFlow53F97EB9',
SourceFlowConfig: {
ConnectorType: 'S3',
SourceConnectorProperties: {
Expand Down
4 changes: 2 additions & 2 deletions test/core/flows/on-event-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('OnEventFlow', () => {
},
},
],
FlowName: 'OnEventFlow',
FlowName: 'TestStackOnEventFlow4BA4B0C6',
FlowStatus: 'Active',
SourceFlowConfig: {
ConnectorProfileName: 'appflow-tester',
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('OnEventFlow', () => {
},
},
],
FlowName: 'OnEventFlow',
FlowName: 'TestStackOnEventFlow4BA4B0C6',
SourceFlowConfig: {
ConnectorProfileName: 'appflow-tester',
ConnectorType: 'Salesforce',
Expand Down
6 changes: 3 additions & 3 deletions test/core/flows/on-schedule-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../../../src';

describe('OnScheduleFlow', () => {
test('', () => {
test('default', () => {
const stack = new Stack(undefined, 'TestStack');

const bucket = new Bucket(stack, 'TestBucket');
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('OnScheduleFlow', () => {
},
},
],
FlowName: 'OnScheduleFlow',
FlowName: 'TestStackOnScheduleFlow1BB655FE',
SourceFlowConfig: {
ConnectorType: 'S3',
SourceConnectorProperties: {
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('OnScheduleFlow', () => {
const template = Template.fromStack(stack);

template.hasResourceProperties('AWS::AppFlow::Flow', {
FlowName: 'OnScheduleFlow',
FlowName: 'TestStackOnScheduleFlow1BB655FE',
TriggerConfig: {
TriggerType: 'Scheduled',
TriggerProperties: {
Expand Down
4 changes: 2 additions & 2 deletions test/googleads/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('GoogleAdsSource', () => {
},
},
],
FlowName: 'TestFlow',
FlowName: 'TestStackTestFlow32CDAF42',
SourceFlowConfig: {
ApiVersion: 'v16',
ConnectorProfileName: 'dummy-profile',
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('GoogleAdsSource', () => {
},
},
],
FlowName: 'TestFlow',
FlowName: 'TestStackTestFlow32CDAF42',
SourceFlowConfig: {
ApiVersion: 'v16',
ConnectorProfileName: 'TestProfile',
Expand Down
4 changes: 2 additions & 2 deletions test/googlebigquery/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('GoogleBigQuerySource', () => {
},
},
],
FlowName: 'TestFlow',
FlowName: 'TestStackTestFlow32CDAF42',
SourceFlowConfig: {
ApiVersion: 'v2',
ConnectorProfileName: 'dummy-profile',
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('GoogleBigQuerySource', () => {
},
},
],
FlowName: 'TestFlow',
FlowName: 'TestStackTestFlow32CDAF42',
SourceFlowConfig: {
ApiVersion: 'v2',
ConnectorProfileName: 'TestProfile',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
}
}
},
"99b90d8d72bc84463ed65323f4e755875ece33ca0ffa2826f29e21ca8ecbca4b": {
"3b6b794667e363c9dd6a3fb162f4933fdaae19bdf8e484778b11e342d9e7cd2a": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "99b90d8d72bc84463ed65323f4e755875ece33ca0ffa2826f29e21ca8ecbca4b.json",
"objectKey": "3b6b794667e363c9dd6a3fb162f4933fdaae19bdf8e484778b11e342d9e7cd2a.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
}
}
],
"FlowName": "OnDemandFlow",
"FlowName": "TestStackOnDemandFlow53F97EB9",
"SourceFlowConfig": {
"ApiVersion": "1.0",
"ConnectorProfileName": "TestConnectorProfile",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
}
}
},
"2ea312c67e9de1ffc6cc7a7242d9c0dc8a2f13f03308d829b5334435120fa7f0": {
"001d1c556f3980c516f91714a7bd71e01f87a79d1eb71439fe70619be725acb8": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "2ea312c67e9de1ffc6cc7a7242d9c0dc8a2f13f03308d829b5334435120fa7f0.json",
"objectKey": "001d1c556f3980c516f91714a7bd71e01f87a79d1eb71439fe70619be725acb8.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
}
}
],
"FlowName": "OnDemandFlow",
"FlowName": "TestStackOnDemandFlow53F97EB9",
"SourceFlowConfig": {
"ApiVersion": "v1beta",
"ConnectorProfileName": "TestConnector",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "36.3.0",
"files": {
"6861d545ce03a23ba70eed7607eb9d7591a85a706ff66d03d5aad22687d28078": {
"feb047041840df9a2e4ae9e6f32343cdf78d2973fd7cd5cac8eb3e96b2f35126": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "6861d545ce03a23ba70eed7607eb9d7591a85a706ff66d03d5aad22687d28078.json",
"objectKey": "feb047041840df9a2e4ae9e6f32343cdf78d2973fd7cd5cac8eb3e96b2f35126.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
}
}
],
"FlowName": "OnDemandFlow",
"FlowName": "TestStackOnDemandFlow53F97EB9",
"SourceFlowConfig": {
"ApiVersion": "V1",
"ConnectorProfileName": "JdbcSmallTestConnectorProfile",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/6861d545ce03a23ba70eed7607eb9d7591a85a706ff66d03d5aad22687d28078.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/feb047041840df9a2e4ae9e6f32343cdf78d2973fd7cd5cac8eb3e96b2f35126.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
}
}
},
"532819537ceb30d89ceb283dc40f262ad262d89482a0756490279fea67d480e2": {
"8a7db1c69546c959e3b9002c2d22ef29554ff680c4522c612bcf7797123fb506": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "532819537ceb30d89ceb283dc40f262ad262d89482a0756490279fea67d480e2.json",
"objectKey": "8a7db1c69546c959e3b9002c2d22ef29554ff680c4522c612bcf7797123fb506.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
}
}
],
"FlowName": "OnDemandFlow",
"FlowName": "TestStackOnDemandFlow53F97EB9",
"SourceFlowConfig": {
"ApiVersion": "V1",
"ConnectorProfileName": "TestConnectorProfile",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/532819537ceb30d89ceb283dc40f262ad262d89482a0756490279fea67d480e2.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/8a7db1c69546c959e3b9002c2d22ef29554ff680c4522c612bcf7797123fb506.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
}
}
},
"d221bc6829242f33fb824716a6a9e09db02f0c425682ea8ff164aaf6eeabe707": {
"455f141c1e1aea44d999861bc52928465467e06520d4314331358441968cf01f": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "d221bc6829242f33fb824716a6a9e09db02f0c425682ea8ff164aaf6eeabe707.json",
"objectKey": "455f141c1e1aea44d999861bc52928465467e06520d4314331358441968cf01f.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
}
}
],
"FlowName": "OnDemandFlow",
"FlowName": "TestStackOnDemandFlow53F97EB9",
"SourceFlowConfig": {
"ApiVersion": "3.0",
"ConnectorProfileName": "TestConnectorProfile",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
}
}
},
"71a287a54e5f2c6d27d3c67dbaa6a5a45bdb20ff32f2cb3f63bed9b1bb964956": {
"f4e64e738430d59f23243a6e72f8f2b5e544cd0cd195f0ff209af03236bfada4": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-us-east-1": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1",
"objectKey": "71a287a54e5f2c6d27d3c67dbaa6a5a45bdb20ff32f2cb3f63bed9b1bb964956.json",
"objectKey": "f4e64e738430d59f23243a6e72f8f2b5e544cd0cd195f0ff209af03236bfada4.json",
"region": "us-east-1",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-us-east-1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
}
}
],
"FlowName": "OnDemandFlow",
"FlowName": "TestStackOnDemandFlow53F97EB9",
"SourceFlowConfig": {
"ApiVersion": "v9.2",
"ConnectorProfileName": "TestConnector",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-us-east-1",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-us-east-1",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1/71a287a54e5f2c6d27d3c67dbaa6a5a45bdb20ff32f2cb3f63bed9b1bb964956.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-us-east-1/f4e64e738430d59f23243a6e72f8f2b5e544cd0cd195f0ff209af03236bfada4.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
}
}
},
"8eede5efa341871e439a6c48121a592749d86283fce3c03cab0b12d3c4580a9f": {
"ab4cd98a95f1b6112b78755dffeb8829a58eae4f39e17680c6c19dc56873c69a": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "8eede5efa341871e439a6c48121a592749d86283fce3c03cab0b12d3c4580a9f.json",
"objectKey": "ab4cd98a95f1b6112b78755dffeb8829a58eae4f39e17680c6c19dc56873c69a.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
}
}
],
"FlowName": "OnDemandFlow",
"FlowName": "TestStackOnDemandFlow53F97EB9",
"SourceFlowConfig": {
"ApiVersion": "v1.0",
"ConnectorProfileName": "TestConnector",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@
}
}
},
"a22659df99cd0c562377a5afa6737f29d21021cabbad01dce9dd1fc3b1df4a62": {
"69344cdc441a5e8630ce224e32856c51537bb5e09d5f9356f09633b8ee89b71c": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "a22659df99cd0c562377a5afa6737f29d21021cabbad01dce9dd1fc3b1df4a62.json",
"objectKey": "69344cdc441a5e8630ce224e32856c51537bb5e09d5f9356f09633b8ee89b71c.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@
}
}
],
"FlowName": "OnDemandFlow",
"FlowName": "TestStackOnDemandFlow53F97EB9",
"SourceFlowConfig": {
"ConnectorType": "S3",
"SourceConnectorProperties": {
Expand Down
Loading

0 comments on commit ae10356

Please sign in to comment.