Skip to content

Commit

Permalink
fix!: applying consistent naming convention for L1 and L2 constructs (#…
Browse files Browse the repository at this point in the history
…393)

Fixes #392 

- Adds default name generation according to [the CFN requirements for CustomerProfile](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appflow-connectorprofile.html#cfn-appflow-connectorprofile-connectorprofilename)
- changes the L1 construct's name of `ConnectorProfileBase` to `'Resource'` following the AWS CDK standard approach
- changes the L1 construct's name of `FlowBase` to `'Resource'` following the AWS CDK standard approach
  • Loading branch information
rpawlaszek authored Nov 5, 2024
1 parent ee4f721 commit 176885f
Show file tree
Hide file tree
Showing 55 changed files with 211 additions and 194 deletions.
31 changes: 24 additions & 7 deletions src/core/connectors/connector-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
import { Arn, ArnFormat, IResource, Resource, Stack } from "aws-cdk-lib";
import {
Arn,
ArnFormat,
IResource,
Lazy,
Names,
Resource,
Stack,
} from "aws-cdk-lib";
import { CfnConnectorProfile } from "aws-cdk-lib/aws-appflow";
import { IKey } from "aws-cdk-lib/aws-kms";
import { ISecret, Secret } from "aws-cdk-lib/aws-secretsmanager";
Expand Down Expand Up @@ -81,14 +89,22 @@ export abstract class ConnectorProfileBase
props: ConnectorProfileProps,
connectorType: ConnectorType,
) {
super(scope, id);
super(scope, id, {
physicalName:
props.name ||
Lazy.string({
produce: () =>
Names.uniqueResourceName(this, {
maxLength: 256,
}),
}),
});

this.name = props.name ?? id;
this.tryAddNodeDependency(this, props.key);
AppFlowPermissionsManager.instance().grantKeyEncryptDecrypt(props.key);

const resource = new CfnConnectorProfile(this, id, {
connectorProfileName: this.name,
const resource = new CfnConnectorProfile(this, "Resource", {
connectorProfileName: this.physicalName,
connectorLabel: connectorType.asProfileConnectorLabel,
connectorType: connectorType.asProfileConnectorType,
connectionMode: ConnectionMode.PUBLIC,
Expand All @@ -101,9 +117,10 @@ export abstract class ConnectorProfileBase
});

this.arn = resource.attrConnectorProfileArn;
this.name = this.physicalName;
this.credentials = Secret.fromSecretCompleteArn(
scope,
`${id}Credentials`,
this,
`Credentials`,
resource.attrCredentialsArn,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/flows/flow-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export abstract class FlowBase extends Resource implements IFlow {
props.source.connectorType,
);

const resource = new CfnFlow(this, id, {
const resource = new CfnFlow(this, "Resource", {
flowName: this.physicalName,
flowStatus: props.status,
triggerConfig: {
Expand Down
2 changes: 1 addition & 1 deletion test/asana/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("AsanaConnectorProfileProps", () => {
{
ConnectionMode: "Public",
ConnectorLabel: "Asana",
ConnectorProfileName: "TestProfile",
ConnectorProfileName: "TestStackTestProfile18724107",
ConnectorType: "CustomConnector",
ConnectorProfileConfig: {
ConnectorProfileCredentials: {
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 @@ -138,7 +138,7 @@ describe("OnEventFlow", () => {
source: ["aws.appflow"],
resources: [
{
"Fn::GetAtt": ["OnEventFlowBAB74E7A", "FlowArn"],
"Fn::GetAtt": ["OnEventFlowF92CD86B", "FlowArn"],
},
],
"detail-type": ["AppFlow Event Flow Report"],
Expand All @@ -151,7 +151,7 @@ describe("OnEventFlow", () => {
source: ["aws.appflow"],
resources: [
{
"Fn::GetAtt": ["OnEventFlowBAB74E7A", "FlowArn"],
"Fn::GetAtt": ["OnEventFlowF92CD86B", "FlowArn"],
},
],
"detail-type": ["AppFlow Event Flow Deactivated"],
Expand Down
2 changes: 1 addition & 1 deletion test/googleads/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("GoogleAdsConnectorProfile", () => {
{
ConnectionMode: "Public",
ConnectorLabel: "GoogleAds",
ConnectorProfileName: "TestProfile",
ConnectorProfileName: "TestStackTestProfile18724107",
ConnectorType: "CustomConnector",
ConnectorProfileConfig: {
ConnectorProfileCredentials: {
Expand Down
6 changes: 3 additions & 3 deletions test/googleads/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe("GoogleAdsSource", () => {

template.hasResourceProperties("AWS::AppFlow::ConnectorProfile", {
ConnectionMode: "Public",
ConnectorProfileName: "TestProfile",
ConnectorProfileName: "TestStackTestProfile18724107",
ConnectorType: "CustomConnector",
ConnectorLabel: "GoogleAds",
ConnectorProfileConfig: {
Expand Down Expand Up @@ -196,7 +196,7 @@ describe("GoogleAdsSource", () => {
FlowName: "TestStackTestFlow32CDAF42",
SourceFlowConfig: {
ApiVersion: "v16",
ConnectorProfileName: "TestProfile",
ConnectorProfileName: "TestStackTestProfile18724107",
ConnectorType: "CustomConnector",
SourceConnectorProperties: {
CustomConnector: {
Expand Down Expand Up @@ -226,7 +226,7 @@ describe("GoogleAdsSource", () => {
DependsOn: [
"TestBucketPolicyBA12ED38",
"TestBucket560B80BC",
"TestProfile45C36389",
"TestProfileBC0F4812",
],
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/googlebigquery/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("GoogleBigQueryConnectorProfile", () => {
"AWS::AppFlow::ConnectorProfile",
{
ConnectionMode: "Public",
ConnectorProfileName: "TestProfile",
ConnectorProfileName: "TestStackTestProfile18724107",
ConnectorType: "CustomConnector",
ConnectorLabel: "GoogleBigQuery",
ConnectorProfileConfig: {
Expand Down Expand Up @@ -87,7 +87,7 @@ describe("GoogleBigQueryConnectorProfile", () => {
"AWS::AppFlow::ConnectorProfile",
{
ConnectionMode: "Public",
ConnectorProfileName: "TestProfile",
ConnectorProfileName: "TestStackTestProfile18724107",
ConnectorType: "CustomConnector",
ConnectorLabel: "GoogleBigQuery",
ConnectorProfileConfig: {
Expand Down Expand Up @@ -199,7 +199,7 @@ describe("GoogleBigQueryConnectorProfile", () => {
Template.fromStack(stack).hasResource("AWS::AppFlow::ConnectorProfile", {
Properties: {
ConnectionMode: "Public",
ConnectorProfileName: "TestProfile",
ConnectorProfileName: "TestStackTestProfile18724107",
ConnectorType: "CustomConnector",
ConnectorLabel: "GoogleBigQuery",
ConnectorProfileConfig: {
Expand Down
6 changes: 3 additions & 3 deletions test/googlebigquery/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe("GoogleBigQuerySource", () => {

template.hasResourceProperties("AWS::AppFlow::ConnectorProfile", {
ConnectionMode: "Public",
ConnectorProfileName: "TestProfile",
ConnectorProfileName: "TestStackTestProfile18724107",
ConnectorType: "CustomConnector",
ConnectorLabel: "GoogleBigQuery",
ConnectorProfileConfig: {
Expand Down Expand Up @@ -202,7 +202,7 @@ describe("GoogleBigQuerySource", () => {
FlowName: "TestStackTestFlow32CDAF42",
SourceFlowConfig: {
ApiVersion: "v2",
ConnectorProfileName: "TestProfile",
ConnectorProfileName: "TestStackTestProfile18724107",
ConnectorType: "CustomConnector",
SourceConnectorProperties: {
CustomConnector: {
Expand Down Expand Up @@ -232,7 +232,7 @@ describe("GoogleBigQuerySource", () => {
DependsOn: [
"TestBucketPolicyBA12ED38",
"TestBucket560B80BC",
"TestProfile45C36389",
"TestProfileBC0F4812",
],
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
}
}
},
"3b6b794667e363c9dd6a3fb162f4933fdaae19bdf8e484778b11e342d9e7cd2a": {
"9cce408075f59c2146a2f2f55df048ba6820342a0969c337383c6b308faac634": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "3b6b794667e363c9dd6a3fb162f4933fdaae19bdf8e484778b11e342d9e7cd2a.json",
"objectKey": "9cce408075f59c2146a2f2f55df048ba6820342a0969c337383c6b308faac634.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
@@ -1,6 +1,6 @@
{
"Resources": {
"TestConnectorProfileD7470107": {
"TestConnectorProfile61825F3E": {
"Type": "AWS::AppFlow::ConnectorProfile",
"Properties": {
"ConnectionMode": "Public",
Expand Down Expand Up @@ -42,7 +42,7 @@
}
}
},
"ConnectorProfileName": "TestConnectorProfile",
"ConnectorProfileName": "TestStackTestConnectorProfileD7C70DA6",
"ConnectorType": "CustomConnector"
}
},
Expand Down Expand Up @@ -239,7 +239,7 @@
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092"
]
},
"OnDemandFlow4ECA54C5": {
"OnDemandFlow00CE33FE": {
"Type": "AWS::AppFlow::Flow",
"Properties": {
"DestinationFlowConfigList": [
Expand All @@ -257,7 +257,7 @@
"FlowName": "TestStackOnDemandFlow53F97EB9",
"SourceFlowConfig": {
"ApiVersion": "1.0",
"ConnectorProfileName": "TestConnectorProfile",
"ConnectorProfileName": "TestStackTestConnectorProfileD7C70DA6",
"ConnectorType": "CustomConnector",
"SourceConnectorProperties": {
"CustomConnector": {
Expand Down Expand Up @@ -307,7 +307,7 @@
"TestBucketAutoDeleteObjectsCustomResource8FEAABD5",
"TestBucketPolicyBA12ED38",
"TestBucket560B80BC",
"TestConnectorProfileD7470107"
"TestConnectorProfile61825F3E"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
}
}
},
"001d1c556f3980c516f91714a7bd71e01f87a79d1eb71439fe70619be725acb8": {
"3e766f62241e624040d7f72adc0d4e7438e19f3e765ee790b1db990354eaf76c": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "001d1c556f3980c516f91714a7bd71e01f87a79d1eb71439fe70619be725acb8.json",
"objectKey": "3e766f62241e624040d7f72adc0d4e7438e19f3e765ee790b1db990354eaf76c.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
@@ -1,6 +1,6 @@
{
"Resources": {
"TestConnectorEE9F0A13": {
"TestConnectorF96C459B": {
"Type": "AWS::AppFlow::ConnectorProfile",
"Properties": {
"ConnectionMode": "Public",
Expand Down Expand Up @@ -83,7 +83,7 @@
}
}
},
"ConnectorProfileName": "TestConnector",
"ConnectorProfileName": "TestStackTestConnector553270CD",
"ConnectorType": "CustomConnector"
}
},
Expand Down Expand Up @@ -280,7 +280,7 @@
"CustomS3AutoDeleteObjectsCustomResourceProviderRole3B1BD092"
]
},
"OnDemandFlow4ECA54C5": {
"OnDemandFlow00CE33FE": {
"Type": "AWS::AppFlow::Flow",
"Properties": {
"DestinationFlowConfigList": [
Expand All @@ -298,7 +298,7 @@
"FlowName": "TestStackOnDemandFlow53F97EB9",
"SourceFlowConfig": {
"ApiVersion": "v1beta",
"ConnectorProfileName": "TestConnector",
"ConnectorProfileName": "TestStackTestConnector553270CD",
"ConnectorType": "CustomConnector",
"SourceConnectorProperties": {
"CustomConnector": {
Expand Down Expand Up @@ -406,7 +406,7 @@
"TestBucketAutoDeleteObjectsCustomResource8FEAABD5",
"TestBucketPolicyBA12ED38",
"TestBucket560B80BC",
"TestConnectorEE9F0A13"
"TestConnectorF96C459B"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "36.3.0",
"files": {
"feb047041840df9a2e4ae9e6f32343cdf78d2973fd7cd5cac8eb3e96b2f35126": {
"9dd52abf0489ce71ca2300e218bd47d2fc5454dfecdf034daf6229b6823feec4": {
"source": {
"path": "TestStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "feb047041840df9a2e4ae9e6f32343cdf78d2973fd7cd5cac8eb3e96b2f35126.json",
"objectKey": "9dd52abf0489ce71ca2300e218bd47d2fc5454dfecdf034daf6229b6823feec4.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
@@ -1,6 +1,6 @@
{
"Resources": {
"JdbcSmallTestConnectorProfileD137BC4A": {
"JdbcSmallTestConnectorProfile4B32988D": {
"Type": "AWS::AppFlow::ConnectorProfile",
"Properties": {
"ConnectionMode": "Public",
Expand Down Expand Up @@ -142,11 +142,11 @@
}
}
},
"ConnectorProfileName": "JdbcSmallTestConnectorProfile",
"ConnectorProfileName": "TestStackJdbcSmallTestConnectorProfileCEFC6AC7",
"ConnectorType": "CustomConnector"
}
},
"AmazonRdsTestConnectorProfileDA7BF797": {
"AmazonRdsTestConnectorProfile5A37DC65": {
"Type": "AWS::AppFlow::ConnectorProfile",
"Properties": {
"ConnectionMode": "Public",
Expand Down Expand Up @@ -269,17 +269,17 @@
}
}
},
"ConnectorProfileName": "AmazonRdsTestConnectorProfile",
"ConnectorProfileName": "TestStackAmazonRdsTestConnectorProfileAD9F9A54",
"ConnectorType": "CustomConnector"
}
},
"OnDemandFlow4ECA54C5": {
"OnDemandFlow00CE33FE": {
"Type": "AWS::AppFlow::Flow",
"Properties": {
"DestinationFlowConfigList": [
{
"ApiVersion": "1.0",
"ConnectorProfileName": "AmazonRdsTestConnectorProfile",
"ConnectorProfileName": "TestStackAmazonRdsTestConnectorProfileAD9F9A54",
"ConnectorType": "CustomConnector",
"DestinationConnectorProperties": {
"CustomConnector": {
Expand Down Expand Up @@ -323,7 +323,7 @@
"FlowName": "TestStackOnDemandFlow53F97EB9",
"SourceFlowConfig": {
"ApiVersion": "V1",
"ConnectorProfileName": "JdbcSmallTestConnectorProfile",
"ConnectorProfileName": "TestStackJdbcSmallTestConnectorProfileCEFC6AC7",
"ConnectorType": "CustomConnector",
"SourceConnectorProperties": {
"CustomConnector": {
Expand Down Expand Up @@ -425,8 +425,8 @@
}
},
"DependsOn": [
"AmazonRdsTestConnectorProfileDA7BF797",
"JdbcSmallTestConnectorProfileD137BC4A"
"AmazonRdsTestConnectorProfile5A37DC65",
"JdbcSmallTestConnectorProfile4B32988D"
]
}
},
Expand Down
Loading

0 comments on commit 176885f

Please sign in to comment.