Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(servicecatalogappregistry): Cross region warning and default application tag #23412

Merged
merged 3 commits into from Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-servicecatalogappregistry/README.md
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
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
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,
};
}
}
}
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
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
@@ -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
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
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
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
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
@@ -1 +1 @@
{"version":"21.0.0"}
{"version":"22.0.0"}
@@ -1,5 +1,5 @@
{
"version": "20.0.0",
"version": "22.0.0",
"files": {
"3dece22dad73361a79cb380f2880362a20ffc5c0cc75ddc6707e26b5a88cf93f": {
"source": {
Expand Down
@@ -1,5 +1,5 @@
{
"version": "20.0.0",
"version": "22.0.0",
"testCases": {
"integ.attribute-group": {
"stacks": [
Expand Down
@@ -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"
}
}
}
}
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"
}
}
}