Skip to content

Commit

Permalink
feat(servicecatalogappregistry): Cross region warning and default app…
Browse files Browse the repository at this point in the history
…lication tag (#23412)

In order to track the usage of `application-associator` L2 construct and gather metrics, we are adding a new user tag `managedBy` upon Application creation. 
In case of `cross-region` stack, we want to throw a warning during the synth time, which will let the customer know that AppRegistry do not natively supports cross region.

### All Submissions:

* [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [ X] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [X ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
santanugho authored Dec 21, 2022
1 parent 07acd18 commit 8d359ae
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 39 deletions.
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-servicecatalogappregistry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const associatedApp = new appreg.ApplicationAssociator(app, 'AssociatedApplicati
});
```

This will create an application `MyAssociatedApplication` with the `TagKey` as `managedBy` and `TagValue` as `CDK_Application_Associator`.

If you want to re-use an existing Application with ARN: `arn:aws:servicecatalog:us-east-1:123456789012:/applications/applicationId`
and want to associate all stacks in the `App` scope to your imported application, then use as shown in the example below:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ abstract class StackAssociatorBase implements IAspect {
}

if (node.region != this.application.env.region) {
this.error(node, 'AppRegistry does not support cross region associations. Application region '
this.warning(node, 'AppRegistry does not support cross region associations, deployment might fail if there is cross region stacks in the app. Application region '
+ this.application.env.region + ', stack region ' + node.region);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class CreateTargetApplication extends TargetApplication {
applicationName: this.applicationOptions.applicationName,
description: this.applicationOptions.applicationDescription || 'Application containing stacks deployed via CDK.',
});
cdk.Tags.of(appRegApplication).add('managedBy', 'CDK_Application_Associator');

return {
application: appRegApplication,
Expand All @@ -123,4 +124,4 @@ class ExistingTargetApplication extends TargetApplication {
application: appRegApplication,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ describe('Scope based Associations with Application within Same Account', () =>
});
});
test('ApplicationAssociator will associate allStacks created inside cdkApp', () => {
new appreg.ApplicationAssociator(app, 'MyApplication', {
const appAssociator = new appreg.ApplicationAssociator(app, 'MyApplication', {
applications: [appreg.TargetApplication.createApplicationStack({
applicationName: 'MyAssociatedApplication',
stackName: 'MyAssociatedApplicationStack',
})],
});

const anotherStack = new AppRegistrySampleStack(app, 'SampleStack');
Template.fromStack(appAssociator.appRegistryApplication().stack).resourceCountIs('AWS::ServiceCatalogAppRegistry::Application', 1);
Template.fromStack(appAssociator.appRegistryApplication().stack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::Application', {
Name: 'MyAssociatedApplication',
Tags: { managedBy: 'CDK_Application_Associator' },
});
Template.fromStack(anotherStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1);
Template.fromStack(anotherStack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', {
Application: 'MyAssociatedApplication',
Expand Down Expand Up @@ -103,7 +109,8 @@ describe('Scope based Associations with Application with Cross Region/Account',
const crossRegionStack = new cdk.Stack(app, 'crossRegionStack', {
env: { account: 'account', region: 'region' },
});
Annotations.fromStack(crossRegionStack).hasError('*', 'AppRegistry does not support cross region associations. Application region region2, stack region region');
Annotations.fromStack(crossRegionStack).hasWarning('*', 'AppRegistry does not support cross region associations, deployment might fail if there is cross region stacks in the app.'
+ ' Application region region2, stack region region');
});

test('Environment Agnostic ApplicationAssociator with cross region stacks inside cdkApp gives warning', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,9 @@ describe('Scope based Associations with Application with Cross Region/Account',
});
const stageStack = new cdk.Stack(stage, 'MyStack');
application.associateAllStacksInScope(stage);
Annotations.fromStack(stageStack).hasError('*',
'AppRegistry does not support cross region associations. Application region region, stack region region1');
Annotations.fromStack(stageStack).hasWarning('*',
'AppRegistry does not support cross region associations, deployment might fail if there is cross region stacks in the app.'
+ ' Application region region, stack region region1');
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "22.0.0",
"files": {
"806ae543572346400832fe865c1bdfa243ef2c1f07c3ce10aa0bd27ed4613a42": {
"225f3d7f7d17bfb53aa17ae8a44119a756f2fc51682bfd5ee27b84ea25f994eb": {
"source": {
"path": "integ-servicecatalogappregistry-application.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "806ae543572346400832fe865c1bdfa243ef2c1f07c3ce10aa0bd27ed4613a42.json",
"objectKey": "225f3d7f7d17bfb53aa17ae8a44119a756f2fc51682bfd5ee27b84ea25f994eb.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 @@ -3,7 +3,7 @@
"TestApplication2FBC585F": {
"Type": "AWS::ServiceCatalogAppRegistry::Application",
"Properties": {
"Name": "myCdkApplication",
"Name": "myApplication",
"Description": "my application description"
}
},
Expand Down Expand Up @@ -84,7 +84,7 @@
"release": "go time"
}
},
"Name": "myCdkAttributeGroup",
"Name": "myAttributeGroup",
"Description": "my attribute group description"
}
},
Expand Down Expand Up @@ -123,7 +123,7 @@
},
"Outputs": {
"TestApplicationApplicationManagerUrlE1058321": {
"Description": "Application manager url for application myCdkApplication",
"Description": "Application manager url for application myApplication",
"Value": {
"Fn::Join": [
"",
Expand All @@ -132,7 +132,7 @@
{
"Ref": "AWS::Region"
},
".console.aws.amazon.com/systems-manager/appmanager/application/AWS_AppRegistry_Application-myCdkApplication"
".console.aws.amazon.com/systems-manager/appmanager/application/AWS_AppRegistry_Application-myApplication"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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}/806ae543572346400832fe865c1bdfa243ef2c1f07c3ce10aa0bd27ed4613a42.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/225f3d7f7d17bfb53aa17ae8a44119a756f2fc51682bfd5ee27b84ea25f994eb.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"attributes": {
"aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::Application",
"aws:cdk:cloudformation:props": {
"name": "myCdkApplication",
"name": "myApplication",
"description": "my application description"
}
},
Expand Down Expand Up @@ -149,7 +149,7 @@
"release": "go time"
}
},
"name": "myCdkAttributeGroup",
"name": "myAttributeGroup",
"description": "my attribute group description"
}
},
Expand Down Expand Up @@ -249,7 +249,7 @@
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.168"
"version": "10.1.189"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const app = new cdk.App();
const stack = new cdk.Stack(app, 'integ-servicecatalogappregistry-application');

const application = new appreg.Application(stack, 'TestApplication', {
applicationName: 'myCdkApplication',
applicationName: 'myApplication',
description: 'my application description',
});

const attributeGroup = new appreg.AttributeGroup(stack, 'TestAttributeGroup', {
attributeGroupName: 'myCdkAttributeGroup',
attributeGroupName: 'myAttributeGroup',
description: 'my attribute group description',
attributes: {
stage: 'alpha',
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"21.0.0"}
{"version":"22.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "20.0.0",
"version": "22.0.0",
"files": {
"3dece22dad73361a79cb380f2880362a20ffc5c0cc75ddc6707e26b5a88cf93f": {
"source": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "20.0.0",
"version": "22.0.0",
"testCases": {
"integ.attribute-group": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"version": "20.0.0",
"version": "22.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
},
"integ-servicecatalogappregistry-attribute-group.assets": {
"type": "cdk:asset-manifest",
"properties": {
Expand Down Expand Up @@ -77,6 +71,12 @@
]
},
"displayName": "integ-servicecatalogappregistry-attribute-group"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
"id": "App",
"path": "",
"children": {
"Tree": {
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.85"
}
},
"integ-servicecatalogappregistry-attribute-group": {
"id": "integ-servicecatalogappregistry-attribute-group",
"path": "integ-servicecatalogappregistry-attribute-group",
Expand Down Expand Up @@ -97,6 +89,14 @@
"id": "MyRole",
"path": "integ-servicecatalogappregistry-attribute-group/MyRole",
"children": {
"ImportMyRole": {
"id": "ImportMyRole",
"path": "integ-servicecatalogappregistry-attribute-group/MyRole/ImportMyRole",
"constructInfo": {
"fqn": "@aws-cdk/core.Resource",
"version": "0.0.0"
}
},
"Resource": {
"id": "Resource",
"path": "integ-servicecatalogappregistry-attribute-group/MyRole/Resource",
Expand Down Expand Up @@ -147,6 +147,14 @@
"id": "MySecondRole",
"path": "integ-servicecatalogappregistry-attribute-group/MySecondRole",
"children": {
"ImportMySecondRole": {
"id": "ImportMySecondRole",
"path": "integ-servicecatalogappregistry-attribute-group/MySecondRole/ImportMySecondRole",
"constructInfo": {
"fqn": "@aws-cdk/core.Resource",
"version": "0.0.0"
}
},
"Resource": {
"id": "Resource",
"path": "integ-servicecatalogappregistry-attribute-group/MySecondRole/Resource",
Expand Down Expand Up @@ -192,17 +200,41 @@
"fqn": "@aws-cdk/aws-iam.Role",
"version": "0.0.0"
}
},
"BootstrapVersion": {
"id": "BootstrapVersion",
"path": "integ-servicecatalogappregistry-attribute-group/BootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnParameter",
"version": "0.0.0"
}
},
"CheckBootstrapVersion": {
"id": "CheckBootstrapVersion",
"path": "integ-servicecatalogappregistry-attribute-group/CheckBootstrapVersion",
"constructInfo": {
"fqn": "@aws-cdk/core.CfnRule",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/core.Stack",
"version": "0.0.0"
}
},
"Tree": {
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.85"
"version": "10.1.189"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.85"
"fqn": "@aws-cdk/core.App",
"version": "0.0.0"
}
}
}

0 comments on commit 8d359ae

Please sign in to comment.