From f3ad2d6a5f3547425a773576dadf8f558ee26a99 Mon Sep 17 00:00:00 2001 From: Rohit Aggarwal Date: Tue, 13 Sep 2022 11:55:00 -0700 Subject: [PATCH 1/4] feat(servicecatalogappregistry): adding capability to automatically associate allStacks inside a cdk App via new construct Automatic Application. --- .../aws-servicecatalogappregistry/README.md | 78 ++++++- .../lib/application.ts | 69 +++++- .../lib/aspects/stack-associator.ts | 173 +++++++++++++++ .../lib/automatic-application.ts | 107 +++++++++ .../lib/index.ts | 1 + .../package.json | 7 +- .../test/application.test.ts | 131 ++++++++++- .../AutomaticApplicationStack.assets.json | 19 ++ .../AutomaticApplicationStack.template.json | 60 +++++ .../cdk.out | 1 + ...catalogappregistry-application.assets.json | 19 ++ ...talogappregistry-application.template.json | 48 ++++ .../integ.json | 14 ++ ...licationresourcesStack4399A149.assets.json | 19 ++ ...cationresourcesStack4399A149.template.json | 48 ++++ .../manifest.json | 209 ++++++++++++++++++ .../tree.json | 143 ++++++++++++ .../test/automatic-application.test.ts | 200 +++++++++++++++++ ...atic-application.all-stacks-association.ts | 20 ++ 19 files changed, 1357 insertions(+), 9 deletions(-) create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/lib/automatic-application.ts create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.assets.json create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.template.json create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/cdk.out create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ.json create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/manifest.json create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/tree.json create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.test.ts create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.automatic-application.all-stacks-association.ts diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/README.md b/packages/@aws-cdk/aws-servicecatalogappregistry/README.md index e96a13bc8b2db..ac67eb59225f7 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/README.md +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/README.md @@ -21,12 +21,13 @@ -[AWS Service Catalog App Registry](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/appregistry.html) +[AWS Service Catalog App Registry](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/appregistry.html) enables organizations to create and manage repositores of applications and associated resources. ## Table Of Contents - [Application](#application) +- [Automatic-Application](#automatic-application) - [Attribute-Group](#attribute-group) - [Associations](#associations) - [Associating application with an attribute group](#attribute-group-association) @@ -44,11 +45,11 @@ import * as appreg from '@aws-cdk/aws-servicecatalogappregistry'; ## Application An AppRegistry application enables you to define your applications and associated resources. -The application name must be unique at the account level, but is mutable. +The application name must be unique at the account level and it's immutable. ```ts const application = new appreg.Application(this, 'MyFirstApplication', { - applicationName: 'MyFirstApplicationName', + applicationName: 'MyFirstApplicationName', description: 'description for my application', // the description is optional }); ``` @@ -64,6 +65,73 @@ const importedApplication = appreg.Application.fromApplicationArn( ); ``` +## Automatic-Application + +An AppRegistry L2 construct to automatically create an application with the given name and description. +The application name must be unique at the account level and it's immutable. +`AutomaticApplication` L2 construct will automatically associate all stacks in the given scope, however +in case of a `Pipeline` stack, stage underneath the pipeline will not automatically be associated and +needs to be associated separately. +If cross account stack is detected, then this construct will automatically share the application to consumer accounts. +Cross account feature will only work for non environment agnostic stacks. + +Following will create an Application named `MyAutoApplication` in account `123456789012` and region `us-east-1` +and will associate all stacks in the `App` scope to `MyAutoApplication`. + +```ts +const autoApp = new appreg.AutomaticApplication(app, 'AutoApplication', { + applicationName: 'MyAutoApplication', + description: 'Testing auto application', + stackProps: { + stackName: 'MyAutoApplicationStack', + env: {account: '123456789012', region: 'us-east-1'}, + }, +}); +``` + +In case of a Pipeline stack, you need to pass the reference of `AutomaticApplication` to pipeline stack and associate +each stage as shown below: + +```ts + +const autoApp = new appreg.AutomaticApplication(app, 'AutoApplication', { + applicationName: 'MyPipelineAutoApplication', + description: 'Testing pipeline auto app', + stackProps: { + stackName: 'MyPipelineAutoApplicationStack', + env: {account: '123456789012', region: 'us-east-1'}, + }, +}); + +const cdkPipeline = new ApplicationPipelineStack(app, 'CDKApplicationPipelineStack', { + application: autoApp, + env: {account: '123456789012', region: 'us-east-1'}, +} + +export interface ApplicationPipelineStackProps extends cdk.StackProps { + application: appreg.AutomaticApplication; +} + +export class ApplicationPipelineStack extends cdk.Stack { + constructor(scope: cdk.App, id: string, props: ApplicationPipelineStackProps) { + super(scope, id, props); + + const repo = new codecommit.Repository(this, 'PipelineRepo', { + repositoryName: "PipelineRepo", + }); + + const pipeline = new codepipeline.CodePipeline(this, 'Pipeline', { + ... //your pipeline properties + }); + + const beta = new cdk.Stage(this, 'MyBetaStage'); + // Now associate the stage to automatic application. + props.application.associateStage(beta, this.stackName); + pipeline.addStage(beta); + } +} +``` + ## Attribute Group An AppRegistry attribute group acts as a container for user-defined attributes for an application. @@ -71,7 +139,7 @@ Metadata is attached in a machine-readble format to integrate with automated wor ```ts const attributeGroup = new appreg.AttributeGroup(this, 'MyFirstAttributeGroup', { - attributeGroupName: 'MyFirstAttributeGroupName', + attributeGroupName: 'MyFirstAttributeGroupName', description: 'description for my attribute group', // the description is optional, attributes: { project: 'foo', @@ -104,7 +172,7 @@ Resources are CloudFormation stacks that you can associate with an application t stacks together to enable metadata rich insights into your applications and resources. A Cloudformation stack can only be associated with one appregistry application. If a stack is associated with multiple applications in your app or is already associated with one, -CDK will fail at deploy time. +CDK will fail at deploy time. ### Associating application with an attribute group diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts index 256de4099afd0..a213d68261f29 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts @@ -2,6 +2,7 @@ import { CfnResourceShare } from '@aws-cdk/aws-ram'; import * as cdk from '@aws-cdk/core'; import { Names } from '@aws-cdk/core'; import { Construct } from 'constructs'; +import { StageStackAssociator } from './aspects/stack-associator'; import { IAttributeGroup } from './attribute-group'; import { getPrincipalsforSharing, hashValues, ShareOptions, SharePermission } from './common'; import { InputValidator } from './private/validation'; @@ -27,7 +28,13 @@ export interface IApplication extends cdk.IResource { readonly applicationId: string; /** - * Associate thisapplication with an attribute group. + * The name of the application. + * @attribute + */ + readonly applicationName?: string; + + /** + * Associate this application with an attribute group. * * @param attributeGroup AppRegistry attribute group */ @@ -36,16 +43,34 @@ export interface IApplication extends cdk.IResource { /** * Associate this application with a CloudFormation stack. * + * @deprecated Use `associateApplicationWithResource` instead. * @param stack a CFN stack */ associateStack(stack: cdk.Stack): void; + /** + * Associate a Cloudformation statck with the application in the given stack. + * + * @param stack a CFN stack + */ + associateApplicationWithResource(stack: cdk.Stack): void; + /** * Share this application with other IAM entities, accounts, or OUs. * * @param shareOptions The options for the share. */ shareApplication(shareOptions: ShareOptions): void; + + /** + * Associate this application with all stacks under the construct node. + * NOTE: This method won't automatically register stacks under pipeline stages, + * and requires association of each pipeline stage by calling this method with stage Construct. + * + * @param construct cdk Construct + */ + associateAllStacksInScope(construct: Construct): void; + } /** @@ -67,6 +92,7 @@ export interface ApplicationProps { abstract class ApplicationBase extends cdk.Resource implements IApplication { public abstract readonly applicationArn: string; public abstract readonly applicationId: string; + public abstract readonly applicationName?: string; private readonly associatedAttributeGroups: Set = new Set(); private readonly associatedResources: Set = new Set(); @@ -89,6 +115,8 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { * Associate a stack with the application * If the resource is already associated, it will ignore duplicate request. * A stack can only be associated with one application. + * + * @deprecated Use `associateApplicationWithResource` instead. */ public associateStack(stack: cdk.Stack): void { if (!this.associatedResources.has(stack.node.addr)) { @@ -102,6 +130,27 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { } } + /** + * Associate stack with the application in the stack passed as parameter. + * + * If the stack is already associated, it will ignore duplicate request. + * A stack can only be associated with one application. + */ + public associateApplicationWithResource(stack: cdk.Stack): void { + if (!this.associatedResources.has(stack.node.addr)) { + new CfnResourceAssociation(stack, 'AppRegistryAssociation', { + application: stack === cdk.Stack.of(this) ? this.applicationId : this.applicationName ?? this.applicationId, + resource: stack.stackId, + resourceType: 'CFN_STACK', + }); + + this.associatedResources.add(stack.node.addr); + if (stack !== cdk.Stack.of(this) && this.env.account === stack.account && !this.isStageScope(stack)) { + stack.addDependency(cdk.Stack.of(this)); + } + } + } + /** * Share an application with accounts, organizations and OUs, and IAM roles and users. * The application will become available to end users within those principals. @@ -120,6 +169,17 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { }); } + /** + * Associate all stacks present in construct's aspect with application. + * + * NOTE: This method won't automatically register stacks under pipeline stages, + * and requires association of each pipeline stage by calling this method with stage Construct. + * + */ + public associateAllStacksInScope(scope: Construct): void { + cdk.Aspects.of(scope).add(new StageStackAssociator(this)); + } + /** * Create a unique id */ @@ -139,6 +199,10 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { return shareOptions.sharePermission ?? APPLICATION_READ_ONLY_RAM_PERMISSION_ARN; } } + + private isStageScope(stack : cdk.Stack): boolean { + return !(stack.node.scope instanceof cdk.App) && (stack.node.scope instanceof cdk.Stage); + } } /** @@ -163,6 +227,7 @@ export class Application extends ApplicationBase { class Import extends ApplicationBase { public readonly applicationArn = applicationArn; public readonly applicationId = applicationId!; + public readonly applicationName = undefined; protected generateUniqueHash(resourceAddress: string): string { return hashValues(this.applicationArn, resourceAddress); @@ -176,6 +241,7 @@ export class Application extends ApplicationBase { public readonly applicationArn: string; public readonly applicationId: string; + public readonly applicationName?: string; private readonly nodeAddress: string; constructor(scope: Construct, id: string, props: ApplicationProps) { @@ -190,6 +256,7 @@ export class Application extends ApplicationBase { this.applicationArn = application.attrArn; this.applicationId = application.attrId; + this.applicationName = props.applicationName; this.nodeAddress = cdk.Names.nodeUniqueId(application.node); } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts new file mode 100644 index 0000000000000..cf8d3d0ec6f21 --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts @@ -0,0 +1,173 @@ +import { Pipeline } from '@aws-cdk/aws-codepipeline'; +import { IAspect, Stack, Token, Annotations } from '@aws-cdk/core'; +import { CodePipeline } from '@aws-cdk/pipelines'; +import { IConstruct } from 'constructs'; +import { IApplication } from '../application'; +import { AutomaticApplication } from '../automatic-application'; +import { SharePermission } from '../common'; + +/** + * Aspect class, this will visit each node from the provided construct once. + * + * For every stack node visited, this class will be responsible to associate + * the stack to the application. + */ +abstract class StackAssociatorBase implements IAspect { + protected abstract readonly application: IApplication; + protected abstract readonly automaticApplication?: AutomaticApplication; + + protected readonly sharedAccounts: Set = new Set(); + protected pipelineStages: Set = new Set(); + + public visit(node: IConstruct): void { + if (node instanceof CodePipeline) { + this.pipelineStages = this.getPipelineStages(node); + } + + // verify if a stage in a particular stack is associated to Application. + if (this.automaticApplication != undefined && node instanceof Pipeline) { + this.pipelineStages.forEach(( customStage ) => { + var stageAssociated = this.automaticApplication?.isStageAssociated(customStage, node.stack.stackName); + if (!stageAssociated) { + this.error(node, 'Associate Stage: ' + customStage + ' to ensure all stacks in your cdk app are associated with AppRegistry. ' + + 'You can use AutomaticApplication.associateStage to associate any stage.'); + } + }); + } + + if (Stack.isStack(node)) { + this.handleCrossRegionStack(node); + this.handleCrossAccountStack(node); + this.associate(node); + } + } + + /** + * Associate a stage stack to the given application. + * + * @param node A Stage stack. + */ + private associate(node: Stack): void { + this.application.associateApplicationWithResource(node); + } + + /** + * Adds an error annotation to a node. + * + * @param node The scope to add the error to. + * @param message The error message. + */ + private error(node: IConstruct, message: string): void { + Annotations.of(node).addError(message); + } + + /** + * Adds a warning annotation to a node. + * + * @param node The scope to add the warning to. + * @param message The error message. + */ + private warning(node: IConstruct, message: string): void { + Annotations.of(node).addWarning(message); + } + + /** + * Handle cross-region association. AppRegistry do not support + * cross region association at this moment, + * If any stack is evaluated as cross-region than that of application, + * we will throw an error. + * + * @param node Cfn stack. + */ + private handleCrossRegionStack(node: Stack): void { + if (this.isRegionUnresolved(this.application.env.region, node.region)) { + this.warning(node, 'Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack.'); + return; + } + + if (node.region != this.application.env.region) { + this.error(node, 'AppRegistry does not support cross region associations. Application region ' + + this.application.env.region + ', stack region ' + node.region); + } + } + + /** + * Handle cross-account association. + * If any stack is evaluated as cross-account than that of application, + * then we will share the application to the stack owning account. + * + * @param node Cfn stack. + */ + private handleCrossAccountStack(node: Stack): void { + if (this.isAccountUnresolved(this.application.env.account!, node.account)) { + this.warning(node, 'Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack.'); + return; + } + + if (node.account != this.application.env.account && !this.sharedAccounts.has(node.account)) { + this.application.shareApplication({ + accounts: [node.account], + sharePermission: SharePermission.ALLOW_ACCESS, + }); + + this.sharedAccounts.add(node.account); + } + } + + /** + * Verifies if application or the visited node is region agnostic. + * + * @param applicationRegion Region of the application. + * @param nodeRegion Region of the visited node. + */ + private isRegionUnresolved(applicationRegion: string, nodeRegion: string): boolean { + return Token.isUnresolved(applicationRegion) || Token.isUnresolved(nodeRegion); + } + + /** + * Verifies if application or the visited node is account agnostic. + * + * @param applicationAccount Account of the application. + * @param nodeAccount Account of the visited node. + */ + private isAccountUnresolved(applicationAccount: string, nodeAccount: string): boolean { + return Token.isUnresolved(applicationAccount) || Token.isUnresolved(nodeAccount); + } + + /** + * Get custom defined stage names for the given pipeline. + * + * @param pipeline Code Pipeline. + */ + private getPipelineStages(pipeline: CodePipeline): Set { + const stageNames = new Set(); + pipeline.waves.forEach( ( wave ) => { + wave.stages.forEach( ( stage ) => { + stageNames.add(stage.stageName); + }); + }); + + return stageNames; + } +} + +export class AutomaticApplicationStageStackAssociator extends StackAssociatorBase { + protected readonly application: IApplication; + protected readonly automaticApplication?: AutomaticApplication; + + constructor(app: AutomaticApplication) { + super(); + this.application = app.appRegistryApplication; + this.automaticApplication = app; + } +} + +export class StageStackAssociator extends StackAssociatorBase { + protected readonly application: IApplication; + protected readonly automaticApplication?: AutomaticApplication; + + constructor(app: IApplication) { + super(); + this.application = app; + } +} diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/automatic-application.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/automatic-application.ts new file mode 100644 index 0000000000000..8913089cd5a1f --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/automatic-application.ts @@ -0,0 +1,107 @@ +import * as cdk from '@aws-cdk/core'; +import { Construct } from 'constructs'; +import { IApplication, Application } from './application'; +import { AutomaticApplicationStageStackAssociator } from './aspects/stack-associator'; + +/** + * Properties for a Service Catalog AppRegistry AutoApplication + */ +export interface AutomaticApplicationProps { + /** + * Enforces a particular physical application name. + * + * @default - No name. + */ + readonly applicationName?: string; + + /** + * Enforces a particular application arn. + * + * @default - No application arn. + */ + readonly applicationArnValue?: string; + + /** + * Application description. + * + * @default - No description. + */ + readonly description?: string; + + /** + * Stack properties. + * + */ + readonly stackProps: cdk.StackProps; +} + +/** + * Automatic application. + */ +export class AutomaticApplication extends Construct { + /** + * Created or imported application. + */ + private readonly application: IApplication; + private readonly associatedStages: Set = new Set(); + + constructor(scope: Construct, id: string, props: AutomaticApplicationProps) { + super(scope, id); + + if (!cdk.App.isApp(scope)) { + throw new Error('Scope must be a cdk App.'); + } + const applicationStack = new cdk.Stack(scope, 'AutomaticApplicationStack', props.stackProps); + + if (!!props.applicationArnValue) { + this.application = this.importApplication(props, applicationStack); + } else { + this.application = this.createAutomaticApplication(props, applicationStack); + } + + cdk.Aspects.of(scope).add(new AutomaticApplicationStageStackAssociator(this)); + } + + /** + * Associate this application with the given stage. + * + */ + public associateStage(stage: cdk.Stage, pipelineStackName: string): cdk.Stage { + this.associatedStages.add(pipelineStackName + '/' + stage.stageName); + cdk.Aspects.of(stage).add(new AutomaticApplicationStageStackAssociator(this)); + return stage; + } + + /** + * Validates if a stage is already associated to the application. + * + */ + public isStageAssociated(stageName: string, pipelineStackName: string): boolean { + return this.associatedStages.has(pipelineStackName + '/' + stageName); + } + + /** + * Get the AppRegistry application. + * + */ + get appRegistryApplication() { + return this.application; + } + + /** + * Import application from the given application ARN. + */ + private importApplication(appProps: AutomaticApplicationProps, applicationStack: cdk.Stack) { + return Application.fromApplicationArn(applicationStack, 'ImportedApplication', appProps.applicationArnValue!); + } + + /** + * Create a new application. + */ + private createAutomaticApplication(appProps: AutomaticApplicationProps, applicationStack: cdk.Stack): IApplication { + return new Application(applicationStack, 'DefaultCdkApplication', { + applicationName: appProps.applicationName!, + description: appProps.description, + }); + } +} diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts index adbf2a9febfe6..ecdcd839a2eea 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts @@ -1,5 +1,6 @@ export * from './application'; export * from './attribute-group'; +export * from './automatic-application'; export * from './common'; // AWS::ServiceCatalogAppRegistry CloudFormation Resources: diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/package.json b/packages/@aws-cdk/aws-servicecatalogappregistry/package.json index f4d1243ef7542..107cff9bc8a02 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/package.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/package.json @@ -88,19 +88,24 @@ "@aws-cdk/integ-runner": "0.0.0", "@aws-cdk/cfn2ts": "0.0.0", "@aws-cdk/pkglint": "0.0.0", + "@aws-cdk/aws-codecommit": "0.0.0", "@types/jest": "^27.5.2" }, "dependencies": { "@aws-cdk/core": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", "@aws-cdk/aws-ram": "0.0.0", + "@aws-cdk/aws-codepipeline": "0.0.0", + "@aws-cdk/pipelines": "0.0.0", "constructs": "^10.0.0" }, "peerDependencies": { "@aws-cdk/core": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", "@aws-cdk/aws-ram": "0.0.0", - "constructs": "^10.0.0" + "@aws-cdk/aws-codepipeline": "0.0.0", + "constructs": "^10.0.0", + "@aws-cdk/pipelines": "0.0.0" }, "engines": { "node": ">= 14.15.0" diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts index 33f1ca2628cdb..dce0d1147ec44 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts @@ -1,11 +1,11 @@ -import { Template } from '@aws-cdk/assertions'; +import { Annotations, Template } from '@aws-cdk/assertions'; import * as iam from '@aws-cdk/aws-iam'; import * as cdk from '@aws-cdk/core'; +import { Construct } from 'constructs'; import * as appreg from '../lib'; describe('Application', () => { let stack: cdk.Stack; - beforeEach(() => { const app = new cdk.App({ context: { @@ -207,6 +207,20 @@ describe('Application', () => { }); }), + test('associate resource on imported application', () => { + const resource = new cdk.Stack(stack, 'MyStack'); + + const importedApplication = appreg.Application.fromApplicationArn(stack, 'ImportedApplication', + 'arn:aws:servicecatalog:us-east-1:123456789012:/applications/0bqmvxvgmry0ecc4mjhwypun6i'); + + importedApplication.associateStack(resource); + + Template.fromStack(stack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', { + Application: '0bqmvxvgmry0ecc4mjhwypun6i', + Resource: { 'Fn::ImportValue': 'MyStack:ExportsOutputRefAWSStackIdB2DD5BAA' }, + }); + }), + test('duplicate resource assocations are idempotent', () => { const resource = new cdk.Stack(stack, 'MyStack'); @@ -324,3 +338,116 @@ describe('Application', () => { }); }); }); + +describe('Scope based Associations with Application within Same Account', () => { + let stack: cdk.Stack; + let app: cdk.App; + beforeEach(() => { + app = new cdk.App({ + context: { + '@aws-cdk/core:newStyleStackSynthesis': false, + }, + }); + stack = new cdk.Stack(app, 'cdkApplication'); + }); + + test('Associate Stage in same account will associate allStacks Inside it', () => { + const application = new appreg.Application(stack, 'MyApplication', { + applicationName: 'MyApplication', + }); + const stage = new cdk.Stage(stack, 'MyStage'); + const stageStack = new cdk.Stack(stage, 'MyStack'); + application.associateAllStacksInScope(stage); + expect(stageStack.stackName).toEqual('MyStage-MyStack'); + Template.fromStack(stageStack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', { + Application: 'MyApplication', + Resource: { Ref: 'AWS::StackId' }, + }); + }); + + + test('Associate Stack in same account will associate allStacks Inside it', () => { + const application = new appreg.Application(stack, 'MyApplication', { + applicationName: 'MyApplication', + }); + + const anotherStack = new AppRegistrySampleStack(app, 'SampleStack'); + application.associateAllStacksInScope(app); + Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); + Template.fromStack(anotherStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); + Template.fromStack(stack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', { + Application: { 'Fn::GetAtt': ['MyApplication5C63EC1D', 'Id'] }, + Resource: { Ref: 'AWS::StackId' }, + }); + Template.fromStack(anotherStack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', { + Application: 'MyApplication', + Resource: { Ref: 'AWS::StackId' }, + }); + }); +}); + +describe('Scope based Associations with Application with Cross Region/Account', () => { + let stack: cdk.Stack; + let app: cdk.App; + beforeEach(() => { + app = new cdk.App({ + context: { + '@aws-cdk/core:newStyleStackSynthesis': false, + }, + }); + stack = new cdk.Stack(app, 'CdkApplication', { + env: { account: 'account', region: 'region' }, + }); + }); + + test('associateAllStacksInScope in cross-account associates all stacks from the context passed', () => { + const application = new appreg.Application(stack, 'MyApplication', { + applicationName: 'MyApplication', + }); + const firstStack = new cdk.Stack(app, 'testStack', { + env: { account: 'account2', region: 'region' }, + }); + const nestedStack = new cdk.Stack(firstStack, 'MyFirstStack', { + env: { account: 'account2', region: 'region' }, + }); + application.associateAllStacksInScope(app); + Template.fromStack(stack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); + Template.fromStack(firstStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); + Template.fromStack(nestedStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); + }); + + test('Associate Stage in cross account association will associate allStacks Inside it', () => { + const application = new appreg.Application(stack, 'MyApplication', { + applicationName: 'MyApplication', + }); + const stage = new cdk.Stage(app, 'MyStage', { + env: { account: 'account2', region: 'region' }, + }); + const stageStack = new cdk.Stack(stage, 'MyStack'); + application.associateAllStacksInScope(stage); + Template.fromStack(stageStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); + Template.fromStack(stageStack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', { + Application: 'MyApplication', + Resource: { Ref: 'AWS::StackId' }, + }); + }); + + test('Associate Stage in cross region throw error', () => { + const application = new appreg.Application(stack, 'MyApplication', { + applicationName: 'MyApplication', + }); + const stage = new cdk.Stage(stack, 'MyStage', { + env: { account: 'account1', region: 'region1' }, + }); + 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'); + }); +}); + +class AppRegistrySampleStack extends cdk.Stack { + public constructor(scope: Construct, id: string, props?: cdk.StackProps) { + super(scope, id, props); + } +} diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.assets.json new file mode 100644 index 0000000000000..6f59f8f54e874 --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "fcea1428896d3e6a887556f0e982b200afff3885810d0fbb95aaa6538399e7c1": { + "source": { + "path": "AutomaticApplicationStack.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "fcea1428896d3e6a887556f0e982b200afff3885810d0fbb95aaa6538399e7c1.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.template.json new file mode 100644 index 0000000000000..f32734c03c26a --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.template.json @@ -0,0 +1,60 @@ +{ + "Resources": { + "DefaultCdkApplication4573D5A3": { + "Type": "AWS::ServiceCatalogAppRegistry::Application", + "Properties": { + "Name": "AppRegistryAutomaticApplication", + "Description": "Testing AppRegistry AutomaticApplication" + } + }, + "AppRegistryAssociation": { + "Type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", + "Properties": { + "Application": { + "Fn::GetAtt": [ + "DefaultCdkApplication4573D5A3", + "Id" + ] + }, + "Resource": { + "Ref": "AWS::StackId" + }, + "ResourceType": "CFN_STACK" + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/cdk.out b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/cdk.out new file mode 100644 index 0000000000000..8ecc185e9dbee --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"21.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json new file mode 100644 index 0000000000000..33d24bf57aa85 --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c": { + "source": { + "path": "integ-servicecatalogappregistry-application.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json new file mode 100644 index 0000000000000..f22dcd7a00a59 --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json @@ -0,0 +1,48 @@ +{ + "Resources": { + "AppRegistryAssociation": { + "Type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", + "Properties": { + "Application": "AppRegistryAutomaticApplication", + "Resource": { + "Ref": "AWS::StackId" + }, + "ResourceType": "CFN_STACK" + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ.json new file mode 100644 index 0000000000000..40e08b259108a --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ.json @@ -0,0 +1,14 @@ +{ + "version": "21.0.0", + "testCases": { + "integ.automatic-application.all-stacks-association": { + "stacks": [ + "integ-servicecatalogappregistry-application" + ], + "diffAssets": false, + "stackUpdateWorkflow": true + } + }, + "synthContext": {}, + "enableLookups": false +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json new file mode 100644 index 0000000000000..b25bcd9af0cc1 --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json @@ -0,0 +1,19 @@ +{ + "version": "21.0.0", + "files": { + "b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c": { + "source": { + "path": "integservicecatalogappregistryapplicationresourcesStack4399A149.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json new file mode 100644 index 0000000000000..f22dcd7a00a59 --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json @@ -0,0 +1,48 @@ +{ + "Resources": { + "AppRegistryAssociation": { + "Type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", + "Properties": { + "Application": "AppRegistryAutomaticApplication", + "Resource": { + "Ref": "AWS::StackId" + }, + "ResourceType": "CFN_STACK" + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/manifest.json new file mode 100644 index 0000000000000..7a34919de539f --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/manifest.json @@ -0,0 +1,209 @@ +{ + "version": "21.0.0", + "artifacts": { + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + }, + "integservicecatalogappregistryapplicationresourcesStack4399A149.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "integservicecatalogappregistryapplicationresourcesStack4399A149": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "integservicecatalogappregistryapplicationresourcesStack4399A149.template.json", + "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}/b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "integservicecatalogappregistryapplicationresourcesStack4399A149.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "AutomaticApplicationStack", + "integservicecatalogappregistryapplicationresourcesStack4399A149.assets" + ], + "metadata": { + "/integ-servicecatalogappregistry-application/resourcesStack": [ + { + "type": "aws:cdk:warning", + "data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack." + }, + { + "type": "aws:cdk:warning", + "data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack." + } + ], + "/integ-servicecatalogappregistry-application/resourcesStack/AppRegistryAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "AppRegistryAssociation" + } + ], + "/integ-servicecatalogappregistry-application/resourcesStack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/integ-servicecatalogappregistry-application/resourcesStack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "integ-servicecatalogappregistry-application/resourcesStack" + }, + "integ-servicecatalogappregistry-application.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "integ-servicecatalogappregistry-application.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "integ-servicecatalogappregistry-application": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "integ-servicecatalogappregistry-application.template.json", + "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}/b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "integ-servicecatalogappregistry-application.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "AutomaticApplicationStack", + "integ-servicecatalogappregistry-application.assets" + ], + "metadata": { + "/integ-servicecatalogappregistry-application": [ + { + "type": "aws:cdk:warning", + "data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack." + }, + { + "type": "aws:cdk:warning", + "data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack." + } + ], + "/integ-servicecatalogappregistry-application/AppRegistryAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "AppRegistryAssociation" + } + ], + "/integ-servicecatalogappregistry-application/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/integ-servicecatalogappregistry-application/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "integ-servicecatalogappregistry-application" + }, + "AutomaticApplicationStack.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "AutomaticApplicationStack.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "AutomaticApplicationStack": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "AutomaticApplicationStack.template.json", + "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}/fcea1428896d3e6a887556f0e982b200afff3885810d0fbb95aaa6538399e7c1.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "AutomaticApplicationStack.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + }, + "stackName": "AppRegistryAutoApplicationStack" + }, + "dependencies": [ + "AutomaticApplicationStack.assets" + ], + "metadata": { + "/AutomaticApplicationStack": [ + { + "type": "aws:cdk:warning", + "data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack." + }, + { + "type": "aws:cdk:warning", + "data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack." + } + ], + "/AutomaticApplicationStack/DefaultCdkApplication/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "DefaultCdkApplication4573D5A3" + } + ], + "/AutomaticApplicationStack/AppRegistryAssociation": [ + { + "type": "aws:cdk:logicalId", + "data": "AppRegistryAssociation" + } + ], + "/AutomaticApplicationStack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/AutomaticApplicationStack/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "AutomaticApplicationStack" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/tree.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/tree.json new file mode 100644 index 0000000000000..cd22f9c195a84 --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/tree.json @@ -0,0 +1,143 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.95" + } + }, + "integ-servicecatalogappregistry-application": { + "id": "integ-servicecatalogappregistry-application", + "path": "integ-servicecatalogappregistry-application", + "children": { + "resourcesStack": { + "id": "resourcesStack", + "path": "integ-servicecatalogappregistry-application/resourcesStack", + "children": { + "AppRegistryAssociation": { + "id": "AppRegistryAssociation", + "path": "integ-servicecatalogappregistry-application/resourcesStack/AppRegistryAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", + "aws:cdk:cloudformation:props": { + "application": "AppRegistryAutomaticApplication", + "resource": { + "Ref": "AWS::StackId" + }, + "resourceType": "CFN_STACK" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-servicecatalogappregistry.CfnResourceAssociation", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + }, + "AppRegistryAssociation": { + "id": "AppRegistryAssociation", + "path": "integ-servicecatalogappregistry-application/AppRegistryAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", + "aws:cdk:cloudformation:props": { + "application": "AppRegistryAutomaticApplication", + "resource": { + "Ref": "AWS::StackId" + }, + "resourceType": "CFN_STACK" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-servicecatalogappregistry.CfnResourceAssociation", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + }, + "AutoApplication": { + "id": "AutoApplication", + "path": "AutoApplication", + "constructInfo": { + "fqn": "@aws-cdk/aws-servicecatalogappregistry.AutomaticApplication", + "version": "0.0.0" + } + }, + "AutomaticApplicationStack": { + "id": "AutomaticApplicationStack", + "path": "AutomaticApplicationStack", + "children": { + "DefaultCdkApplication": { + "id": "DefaultCdkApplication", + "path": "AutomaticApplicationStack/DefaultCdkApplication", + "children": { + "Resource": { + "id": "Resource", + "path": "AutomaticApplicationStack/DefaultCdkApplication/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::Application", + "aws:cdk:cloudformation:props": { + "name": "AppRegistryAutomaticApplication", + "description": "Testing AppRegistry AutomaticApplication" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-servicecatalogappregistry.CfnApplication", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-servicecatalogappregistry.Application", + "version": "0.0.0" + } + }, + "AppRegistryAssociation": { + "id": "AppRegistryAssociation", + "path": "AutomaticApplicationStack/AppRegistryAssociation", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", + "aws:cdk:cloudformation:props": { + "application": { + "Fn::GetAtt": [ + "DefaultCdkApplication4573D5A3", + "Id" + ] + }, + "resource": { + "Ref": "AWS::StackId" + }, + "resourceType": "CFN_STACK" + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-servicecatalogappregistry.CfnResourceAssociation", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.test.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.test.ts new file mode 100644 index 0000000000000..1bf6b184ee2c0 --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.test.ts @@ -0,0 +1,200 @@ +import { Annotations, Template } from '@aws-cdk/assertions'; +import * as codecommit from '@aws-cdk/aws-codecommit'; +import * as cdk from '@aws-cdk/core'; +import * as codepipeline from '@aws-cdk/pipelines'; +import { Construct } from 'constructs'; +import * as appreg from '../lib'; + +describe('Scope based Associations with Application within Same Account', () => { + let app: cdk.App; + beforeEach(() => { + app = new cdk.App({ + context: { + '@aws-cdk/core:newStyleStackSynthesis': false, + }, + }); + }); + test('Automatic application will associate allStacks created inside cdkApp', () => { + new appreg.AutomaticApplication(app, 'MyApplication', { + applicationName: 'MyAutomaticApplication', + stackProps: { + stackName: 'MyAutomaticApplicationStack', + }, + }); + const anotherStack = new AppRegistrySampleStack(app, 'SampleStack'); + Template.fromStack(anotherStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); + Template.fromStack(anotherStack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', { + Application: 'MyAutomaticApplication', + Resource: { Ref: 'AWS::StackId' }, + }); + }); +}); +describe('Scope based Associations with Application with Cross Region/Account', () => { + let app: cdk.App; + beforeEach(() => { + app = new cdk.App({ + context: { + '@aws-cdk/core:newStyleStackSynthesis': false, + }, + }); + }); + test('Automatic Application in cross-account associates all stacks created inside cdk app', () => { + new appreg.AutomaticApplication(app, 'MyApplication', { + applicationName: 'MyAutomaticApplication', + stackProps: { + stackName: 'MyAutomaticApplicationStack', + }, + }); + const firstStack = new cdk.Stack(app, 'testStack', { + env: { account: 'account2', region: 'region' }, + }); + const nestedStack = new cdk.Stack(firstStack, 'MyFirstStack', { + env: { account: 'account2', region: 'region' }, + }); + Template.fromStack(firstStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); + Template.fromStack(nestedStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); + }); + + test('Automatic Application created in scope other than app throws error', () => { + const firstStack = new cdk.Stack(app, 'testStack', { + env: { account: 'account2', region: 'region' }, + }); + expect(() => { + new appreg.AutomaticApplication(firstStack, 'MyApplication', { + applicationName: 'MyAutomaticApplication', + stackProps: { + stackName: 'MyAutomaticApplicationStack', + }, + }); + }).toThrow(/Scope must be a cdk App/); + }); + + test('associate resource on imported application', () => { + const resource = new cdk.Stack(app, 'MyStack'); + + new appreg.AutomaticApplication(app, 'MyApplication', { + applicationArnValue: 'arn:aws:servicecatalog:us-east-1:482211128593:/applications/0a17wtxeg5vilok0sbxfozwpq9', + stackProps: { + stackName: 'MyAutomaticApplicationStack', + }, + }); + + Template.fromStack(resource).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', { + Application: '0a17wtxeg5vilok0sbxfozwpq9', + Resource: { Ref: 'AWS::StackId' }, + }); + }), + + test('Automatic Application with cross region stacks inside cdkApp throws error', () => { + new appreg.AutomaticApplication(app, 'MyApplication', { + applicationName: 'MyAutomaticApplication', + stackProps: { + stackName: 'MyAutomaticApplicationStack', + env: { account: 'account2', region: 'region2' }, + }, + }); + + 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'); + }); + + test('Environment Agnostic Automatic Application with cross region stacks inside cdkApp gives warning', () => { + new appreg.AutomaticApplication(app, 'MyApplication', { + applicationName: 'MyAutomaticApplication', + stackProps: { + stackName: 'MyAutomaticApplicationStack', + }, + }); + + const crossRegionStack = new cdk.Stack(app, 'crossRegionStack', { + env: { account: 'account', region: 'region' }, + }); + Annotations.fromStack(crossRegionStack).hasWarning('*', 'Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack.'); + }); + + test('Cdk App Containing Pipeline with stage but stage not associated throws error', () => { + const application = new appreg.AutomaticApplication(app, 'MyApplication', { + applicationName: 'MyAutomaticApplication', + stackProps: { + stackName: 'MyAutomaticApplicationStack', + }, + }); + const pipelineStack = new AppRegistrySampleCodePipelineStack(app, 'PipelineStackA', { + application: application, + associateStage: false, + }); + app.synth(); + Annotations.fromStack(pipelineStack).hasError('*', + 'Associate Stage: SampleStage to ensure all stacks in your cdk app are associated with AppRegistry. You can use AutomaticApplication.associateStage to associate any stage.'); + }); + + test('Cdk App Containing Pipeline with stage and stage associated successfully gets synthesized', () => { + const application = new appreg.AutomaticApplication(app, 'MyApplication', { + applicationName: 'MyApplication', + stackProps: { + stackName: 'MyAutomaticApplicationStack', + }, + }); + const pipelineStack = new AppRegistrySampleCodePipelineStack(app, 'PipelineStackA', { + application: application, + associateStage: true, + }); + app.synth(); + Template.fromStack(pipelineStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); + }); +}); + +interface AppRegistrySampleCodePipelineStackProps extends cdk.StackProps { + application: appreg.AutomaticApplication; + associateStage: boolean; +} + +class AppRegistrySampleCodePipelineStack extends cdk.Stack { + public constructor(scope: Construct, id: string, props: AppRegistrySampleCodePipelineStackProps ) { + super(scope, id, props); + const repo = new codecommit.Repository(this, 'Repo', { + repositoryName: 'MyRepo', + }); + + const pipeline = new codepipeline.CodePipeline(this, 'Pipeline', { + pipelineName: 'MyPipeline', + synth: new codepipeline.CodeBuildStep('SynthStep', { + input: codepipeline.CodePipelineSource.codeCommit(repo, 'main'), + installCommands: [ + 'npm install -g aws-cdk', + ], + commands: [ + 'npm ci', + 'npm run build', + 'npx cdk synth', + ], + }, + ), + }); + + const stage = new AppRegistrySampleStage( + this, + 'SampleStage', + ); + + if (props.associateStage) { + props.application.associateStage(stage, this.stackName); + } + pipeline.addStage(stage); + } +} + +class AppRegistrySampleStage extends cdk.Stage { + public constructor(scope: Construct, id: string, props?: cdk.StageProps) { + super(scope, id, props); + new AppRegistrySampleStack(this, 'SampleStack', {}); + } +} + +class AppRegistrySampleStack extends cdk.Stack { + public constructor(scope: Construct, id: string, props?: cdk.StackProps) { + super(scope, id, props); + } +} diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.automatic-application.all-stacks-association.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.automatic-application.all-stacks-association.ts new file mode 100644 index 0000000000000..a457211fee549 --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.automatic-application.all-stacks-association.ts @@ -0,0 +1,20 @@ +/// !cdk-integ integ-servicecatalogappregistry-application +import * as cdk from '@aws-cdk/core'; +import * as appreg from '../lib'; + + +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'integ-servicecatalogappregistry-application'); + + +new appreg.AutomaticApplication(app, 'AutoApplication', { + applicationName: 'AppRegistryAutomaticApplication', + description: 'Testing AppRegistry AutomaticApplication', + stackProps: { + stackName: 'AppRegistryAutoApplicationStack', + }, +}); + +new cdk.Stack(stack, 'resourcesStack'); + +app.synth(); From e180856a12cfb62de89e17198e458741786f480b Mon Sep 17 00:00:00 2001 From: Rohit Aggarwal Date: Tue, 13 Sep 2022 15:54:47 -0700 Subject: [PATCH 2/4] Updated Readme file to be in compilable format --- .../aws-servicecatalogappregistry/README.md | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/README.md b/packages/@aws-cdk/aws-servicecatalogappregistry/README.md index ac67eb59225f7..4e625ccc5add6 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/README.md +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/README.md @@ -79,6 +79,7 @@ Following will create an Application named `MyAutoApplication` in account `12345 and will associate all stacks in the `App` scope to `MyAutoApplication`. ```ts +const app = new App(); const autoApp = new appreg.AutomaticApplication(app, 'AutoApplication', { applicationName: 'MyAutoApplication', description: 'Testing auto application', @@ -93,7 +94,27 @@ In case of a Pipeline stack, you need to pass the reference of `AutomaticApplica each stage as shown below: ```ts +import * as cdk from "@aws-cdk/core"; +import * as codepipeline from "@aws-cdk/pipelines"; +import * as codecommit from "@aws-cdk/aws-codecommit"; +declare const repo: codecommit.Repository; +declare const pipeline: codepipeline.CodePipeline; +declare const beta: cdk.Stage; +class ApplicationPipelineStack extends cdk.Stack { + constructor(scope: cdk.App, id: string, props: ApplicationPipelineStackProps) { + super(scope, id, props); + + //associate the stage to automatic application. + props.application.associateStage(beta, this.stackName); + pipeline.addStage(beta); + } +}; +interface ApplicationPipelineStackProps extends cdk.StackProps { + application: appreg.AutomaticApplication; +}; + +const app = new App(); const autoApp = new appreg.AutomaticApplication(app, 'AutoApplication', { applicationName: 'MyPipelineAutoApplication', description: 'Testing pipeline auto app', @@ -106,30 +127,7 @@ const autoApp = new appreg.AutomaticApplication(app, 'AutoApplication', { const cdkPipeline = new ApplicationPipelineStack(app, 'CDKApplicationPipelineStack', { application: autoApp, env: {account: '123456789012', region: 'us-east-1'}, -} - -export interface ApplicationPipelineStackProps extends cdk.StackProps { - application: appreg.AutomaticApplication; -} - -export class ApplicationPipelineStack extends cdk.Stack { - constructor(scope: cdk.App, id: string, props: ApplicationPipelineStackProps) { - super(scope, id, props); - - const repo = new codecommit.Repository(this, 'PipelineRepo', { - repositoryName: "PipelineRepo", - }); - - const pipeline = new codepipeline.CodePipeline(this, 'Pipeline', { - ... //your pipeline properties - }); - - const beta = new cdk.Stage(this, 'MyBetaStage'); - // Now associate the stage to automatic application. - props.application.associateStage(beta, this.stackName); - pipeline.addStage(beta); - } -} +}); ``` ## Attribute Group From 6a2727e86d5c50959df885d0e7b4186a44758519 Mon Sep 17 00:00:00 2001 From: Rohit Aggarwal Date: Mon, 26 Sep 2022 13:46:56 -0700 Subject: [PATCH 3/4] Updated L2ConstructName from Automatic Application to Register Application --- .../aws-servicecatalogappregistry/README.md | 58 +++++----- .../lib/application.ts | 22 +++- .../lib/aspects/stack-associator.ts | 82 ++++---------- .../lib/attribute-group.ts | 4 +- .../lib/automatic-application.ts | 107 ------------------ .../lib/index.ts | 2 +- .../lib/private/utils.ts | 22 ++++ .../lib/register-application.ts | 100 ++++++++++++++++ .../package.json | 5 + ...ter-application.all-stacks-association.ts} | 8 +- .../RegisterApplicationStack.assets.json} | 6 +- .../RegisterApplicationStack.template.json} | 4 +- .../cdk.out | 0 ...catalogappregistry-application.assets.json | 4 +- ...talogappregistry-application.template.json | 2 +- .../integ.json | 2 +- ...licationresourcesStack4399A149.assets.json | 4 +- ...cationresourcesStack4399A149.template.json | 2 +- .../manifest.json | 36 +++--- .../tree.json | 28 ++--- ...n.test.ts => register-application.test.ts} | 58 +++++----- 21 files changed, 274 insertions(+), 282 deletions(-) delete mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/lib/automatic-application.ts create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/lib/private/utils.ts create mode 100644 packages/@aws-cdk/aws-servicecatalogappregistry/lib/register-application.ts rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{integ.automatic-application.all-stacks-association.ts => integ.register-application.all-stacks-association.ts} (58%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.assets.json => register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.assets.json} (65%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.template.json => register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.template.json} (91%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{automatic-application.all-stacks-association.integ.snapshot => register-application.all-stacks-association.integ.snapshot}/cdk.out (100%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{automatic-application.all-stacks-association.integ.snapshot => register-application.all-stacks-association.integ.snapshot}/integ-servicecatalogappregistry-application.assets.json (75%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{automatic-application.all-stacks-association.integ.snapshot => register-application.all-stacks-association.integ.snapshot}/integ-servicecatalogappregistry-application.template.json (94%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{automatic-application.all-stacks-association.integ.snapshot => register-application.all-stacks-association.integ.snapshot}/integ.json (80%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{automatic-application.all-stacks-association.integ.snapshot => register-application.all-stacks-association.integ.snapshot}/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json (75%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{automatic-application.all-stacks-association.integ.snapshot => register-application.all-stacks-association.integ.snapshot}/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json (94%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{automatic-application.all-stacks-association.integ.snapshot => register-application.all-stacks-association.integ.snapshot}/manifest.json (88%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{automatic-application.all-stacks-association.integ.snapshot => register-application.all-stacks-association.integ.snapshot}/tree.json (84%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{automatic-application.test.ts => register-application.test.ts} (76%) diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/README.md b/packages/@aws-cdk/aws-servicecatalogappregistry/README.md index 4e625ccc5add6..9d4d1592ea468 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/README.md +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/README.md @@ -27,7 +27,7 @@ enables organizations to create and manage repositores of applications and assoc ## Table Of Contents - [Application](#application) -- [Automatic-Application](#automatic-application) +- [Register-Application](#register-application) - [Attribute-Group](#attribute-group) - [Associations](#associations) - [Associating application with an attribute group](#attribute-group-association) @@ -65,33 +65,39 @@ const importedApplication = appreg.Application.fromApplicationArn( ); ``` -## Automatic-Application +## Register-Application -An AppRegistry L2 construct to automatically create an application with the given name and description. -The application name must be unique at the account level and it's immutable. -`AutomaticApplication` L2 construct will automatically associate all stacks in the given scope, however -in case of a `Pipeline` stack, stage underneath the pipeline will not automatically be associated and -needs to be associated separately. -If cross account stack is detected, then this construct will automatically share the application to consumer accounts. -Cross account feature will only work for non environment agnostic stacks. - -Following will create an Application named `MyAutoApplication` in account `123456789012` and region `us-east-1` -and will associate all stacks in the `App` scope to `MyAutoApplication`. +If you want to create an Application named `MyRegisteredApplication` in account `123456789012` and region `us-east-1` +and want to associate all stacks in the `App` scope to `MyRegisteredApplication`, then use as shown in the example below: ```ts const app = new App(); -const autoApp = new appreg.AutomaticApplication(app, 'AutoApplication', { - applicationName: 'MyAutoApplication', - description: 'Testing auto application', +const registeredApp = new appreg.RegisterApplication(app, 'RegisterApplication', { + applicationName: 'MyRegisteredApplication', + description: 'Testing registered application', stackProps: { - stackName: 'MyAutoApplicationStack', + stackName: 'MyRegisteredApplicationStack', env: {account: '123456789012', region: 'us-east-1'}, }, }); ``` -In case of a Pipeline stack, you need to pass the reference of `AutomaticApplication` to pipeline stack and associate -each stage as shown below: +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: + +```ts +const app = new App(); +const registeredApp = new appreg.RegisterApplication(app, 'RegisterApplication', { + applicationArnValue: 'arn:aws:servicecatalog:us-east-1:123456789012:/applications/applicationId', + stackProps: { + stackName: 'MyRegisteredApplicationStack', + }, +}); +``` + +If you are using CDK Pipelines to deploy your application, the application stacks will be inside Stages, and +RegisterApplication will not be able to find them. Call `associateStage` on each Stage object before adding it to the +Pipeline, as shown in the example below: ```ts import * as cdk from "@aws-cdk/core"; @@ -104,28 +110,28 @@ class ApplicationPipelineStack extends cdk.Stack { constructor(scope: cdk.App, id: string, props: ApplicationPipelineStackProps) { super(scope, id, props); - //associate the stage to automatic application. - props.application.associateStage(beta, this.stackName); + //associate the stage to register application. + props.application.associateStage(beta); pipeline.addStage(beta); } }; interface ApplicationPipelineStackProps extends cdk.StackProps { - application: appreg.AutomaticApplication; + application: appreg.RegisterApplication; }; const app = new App(); -const autoApp = new appreg.AutomaticApplication(app, 'AutoApplication', { - applicationName: 'MyPipelineAutoApplication', - description: 'Testing pipeline auto app', +const registeredApp = new appreg.RegisterApplication(app, 'RegisterApplication', { + applicationName: 'MyPipelineRegisteredApplication', + description: 'Testing pipeline registered app', stackProps: { - stackName: 'MyPipelineAutoApplicationStack', + stackName: 'MyPipelineRegisteredApplicationStack', env: {account: '123456789012', region: 'us-east-1'}, }, }); const cdkPipeline = new ApplicationPipelineStack(app, 'CDKApplicationPipelineStack', { - application: autoApp, + application: registeredApp, env: {account: '123456789012', region: 'us-east-1'}, }); ``` diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts index a213d68261f29..eb5112e45287e 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts @@ -5,6 +5,7 @@ import { Construct } from 'constructs'; import { StageStackAssociator } from './aspects/stack-associator'; import { IAttributeGroup } from './attribute-group'; import { getPrincipalsforSharing, hashValues, ShareOptions, SharePermission } from './common'; +import { isAccountUnresolved } from './private/utils'; import { InputValidator } from './private/validation'; import { CfnApplication, CfnAttributeGroupAssociation, CfnResourceAssociation } from './servicecatalogappregistry.generated'; @@ -43,7 +44,7 @@ export interface IApplication extends cdk.IResource { /** * Associate this application with a CloudFormation stack. * - * @deprecated Use `associateApplicationWithResource` instead. + * @deprecated Use `associateApplicationWithStack` instead. * @param stack a CFN stack */ associateStack(stack: cdk.Stack): void; @@ -53,7 +54,7 @@ export interface IApplication extends cdk.IResource { * * @param stack a CFN stack */ - associateApplicationWithResource(stack: cdk.Stack): void; + associateApplicationWithStack(stack: cdk.Stack): void; /** * Share this application with other IAM entities, accounts, or OUs. @@ -116,7 +117,7 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { * If the resource is already associated, it will ignore duplicate request. * A stack can only be associated with one application. * - * @deprecated Use `associateApplicationWithResource` instead. + * @deprecated Use `associateApplicationWithStack` instead. */ public associateStack(stack: cdk.Stack): void { if (!this.associatedResources.has(stack.node.addr)) { @@ -136,7 +137,7 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { * If the stack is already associated, it will ignore duplicate request. * A stack can only be associated with one application. */ - public associateApplicationWithResource(stack: cdk.Stack): void { + public associateApplicationWithStack(stack: cdk.Stack): void { if (!this.associatedResources.has(stack.node.addr)) { new CfnResourceAssociation(stack, 'AppRegistryAssociation', { application: stack === cdk.Stack.of(this) ? this.applicationId : this.applicationName ?? this.applicationId, @@ -145,7 +146,7 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { }); this.associatedResources.add(stack.node.addr); - if (stack !== cdk.Stack.of(this) && this.env.account === stack.account && !this.isStageScope(stack)) { + if (stack !== cdk.Stack.of(this) && this.isSameAccount(stack) && !this.isStageScope(stack)) { stack.addDependency(cdk.Stack.of(this)); } } @@ -200,9 +201,20 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication { } } + /** + * Checks whether a stack is defined in a Stage or not. + */ private isStageScope(stack : cdk.Stack): boolean { return !(stack.node.scope instanceof cdk.App) && (stack.node.scope instanceof cdk.Stage); } + + /** + * Verifies if application and the visited node is deployed in different account. + */ + private isSameAccount(stack: cdk.Stack): boolean { + return isAccountUnresolved(this.env.account, stack.account) || this.env.account === stack.account; + } + } /** diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts index cf8d3d0ec6f21..d8ea84e63c179 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts @@ -1,10 +1,9 @@ -import { Pipeline } from '@aws-cdk/aws-codepipeline'; -import { IAspect, Stack, Token, Annotations } from '@aws-cdk/core'; -import { CodePipeline } from '@aws-cdk/pipelines'; +import { IAspect, Stack, Stage, Annotations } from '@aws-cdk/core'; import { IConstruct } from 'constructs'; import { IApplication } from '../application'; -import { AutomaticApplication } from '../automatic-application'; import { SharePermission } from '../common'; +import { isRegionUnresolved, isAccountUnresolved } from '../private/utils'; +import { RegisterApplication } from '../register-application'; /** * Aspect class, this will visit each node from the provided construct once. @@ -14,26 +13,21 @@ import { SharePermission } from '../common'; */ abstract class StackAssociatorBase implements IAspect { protected abstract readonly application: IApplication; - protected abstract readonly automaticApplication?: AutomaticApplication; + protected abstract readonly registerApplication?: RegisterApplication; protected readonly sharedAccounts: Set = new Set(); - protected pipelineStages: Set = new Set(); public visit(node: IConstruct): void { - if (node instanceof CodePipeline) { - this.pipelineStages = this.getPipelineStages(node); - } - // verify if a stage in a particular stack is associated to Application. - if (this.automaticApplication != undefined && node instanceof Pipeline) { - this.pipelineStages.forEach(( customStage ) => { - var stageAssociated = this.automaticApplication?.isStageAssociated(customStage, node.stack.stackName); - if (!stageAssociated) { - this.error(node, 'Associate Stage: ' + customStage + ' to ensure all stacks in your cdk app are associated with AppRegistry. ' - + 'You can use AutomaticApplication.associateStage to associate any stage.'); + node.node.children.forEach((childNode) => { + if (Stage.isStage(childNode)) { + var stageAssociated = this.registerApplication?.isStageAssociated(childNode); + if (stageAssociated === false) { + this.error(childNode, 'Associate Stage: ' + childNode.stageName + ' to ensure all stacks in your cdk app are associated with AppRegistry. ' + + 'You can use RegisterApplication.associateStage to associate any stage.'); } - }); - } + } + }); if (Stack.isStack(node)) { this.handleCrossRegionStack(node); @@ -48,7 +42,7 @@ abstract class StackAssociatorBase implements IAspect { * @param node A Stage stack. */ private associate(node: Stack): void { - this.application.associateApplicationWithResource(node); + this.application.associateApplicationWithStack(node); } /** @@ -80,7 +74,7 @@ abstract class StackAssociatorBase implements IAspect { * @param node Cfn stack. */ private handleCrossRegionStack(node: Stack): void { - if (this.isRegionUnresolved(this.application.env.region, node.region)) { + if (isRegionUnresolved(this.application.env.region, node.region)) { this.warning(node, 'Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack.'); return; } @@ -99,7 +93,7 @@ abstract class StackAssociatorBase implements IAspect { * @param node Cfn stack. */ private handleCrossAccountStack(node: Stack): void { - if (this.isAccountUnresolved(this.application.env.account!, node.account)) { + if (isAccountUnresolved(this.application.env.account!, node.account)) { this.warning(node, 'Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack.'); return; } @@ -113,58 +107,22 @@ abstract class StackAssociatorBase implements IAspect { this.sharedAccounts.add(node.account); } } - - /** - * Verifies if application or the visited node is region agnostic. - * - * @param applicationRegion Region of the application. - * @param nodeRegion Region of the visited node. - */ - private isRegionUnresolved(applicationRegion: string, nodeRegion: string): boolean { - return Token.isUnresolved(applicationRegion) || Token.isUnresolved(nodeRegion); - } - - /** - * Verifies if application or the visited node is account agnostic. - * - * @param applicationAccount Account of the application. - * @param nodeAccount Account of the visited node. - */ - private isAccountUnresolved(applicationAccount: string, nodeAccount: string): boolean { - return Token.isUnresolved(applicationAccount) || Token.isUnresolved(nodeAccount); - } - - /** - * Get custom defined stage names for the given pipeline. - * - * @param pipeline Code Pipeline. - */ - private getPipelineStages(pipeline: CodePipeline): Set { - const stageNames = new Set(); - pipeline.waves.forEach( ( wave ) => { - wave.stages.forEach( ( stage ) => { - stageNames.add(stage.stageName); - }); - }); - - return stageNames; - } } -export class AutomaticApplicationStageStackAssociator extends StackAssociatorBase { +export class RegisterApplicationStageStackAssociator extends StackAssociatorBase { protected readonly application: IApplication; - protected readonly automaticApplication?: AutomaticApplication; + protected readonly registerApplication?: RegisterApplication; - constructor(app: AutomaticApplication) { + constructor(app: RegisterApplication) { super(); this.application = app.appRegistryApplication; - this.automaticApplication = app; + this.registerApplication = app; } } export class StageStackAssociator extends StackAssociatorBase { protected readonly application: IApplication; - protected readonly automaticApplication?: AutomaticApplication; + protected readonly registerApplication?: RegisterApplication; constructor(app: IApplication) { super(); diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/attribute-group.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/attribute-group.ts index ea5a893422aa5..d6dda21fe797d 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/attribute-group.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/attribute-group.ts @@ -1,10 +1,10 @@ import { CfnResourceShare } from '@aws-cdk/aws-ram'; import * as cdk from '@aws-cdk/core'; -import { getPrincipalsforSharing, hashValues, ShareOptions, SharePermission } from './common'; +import { Names } from '@aws-cdk/core'; import { Construct } from 'constructs'; +import { getPrincipalsforSharing, hashValues, ShareOptions, SharePermission } from './common'; import { InputValidator } from './private/validation'; import { CfnAttributeGroup } from './servicecatalogappregistry.generated'; -import { Names } from '@aws-cdk/core'; const ATTRIBUTE_GROUP_READ_ONLY_RAM_PERMISSION_ARN = 'arn:aws:ram::aws:permission/AWSRAMPermissionServiceCatalogAppRegistryAttributeGroupReadOnly'; const ATTRIBUTE_GROUP_ALLOW_ACCESS_RAM_PERMISSION_ARN = 'arn:aws:ram::aws:permission/AWSRAMPermissionServiceCatalogAppRegistryAttributeGroupAllowAssociation'; diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/automatic-application.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/automatic-application.ts deleted file mode 100644 index 8913089cd5a1f..0000000000000 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/automatic-application.ts +++ /dev/null @@ -1,107 +0,0 @@ -import * as cdk from '@aws-cdk/core'; -import { Construct } from 'constructs'; -import { IApplication, Application } from './application'; -import { AutomaticApplicationStageStackAssociator } from './aspects/stack-associator'; - -/** - * Properties for a Service Catalog AppRegistry AutoApplication - */ -export interface AutomaticApplicationProps { - /** - * Enforces a particular physical application name. - * - * @default - No name. - */ - readonly applicationName?: string; - - /** - * Enforces a particular application arn. - * - * @default - No application arn. - */ - readonly applicationArnValue?: string; - - /** - * Application description. - * - * @default - No description. - */ - readonly description?: string; - - /** - * Stack properties. - * - */ - readonly stackProps: cdk.StackProps; -} - -/** - * Automatic application. - */ -export class AutomaticApplication extends Construct { - /** - * Created or imported application. - */ - private readonly application: IApplication; - private readonly associatedStages: Set = new Set(); - - constructor(scope: Construct, id: string, props: AutomaticApplicationProps) { - super(scope, id); - - if (!cdk.App.isApp(scope)) { - throw new Error('Scope must be a cdk App.'); - } - const applicationStack = new cdk.Stack(scope, 'AutomaticApplicationStack', props.stackProps); - - if (!!props.applicationArnValue) { - this.application = this.importApplication(props, applicationStack); - } else { - this.application = this.createAutomaticApplication(props, applicationStack); - } - - cdk.Aspects.of(scope).add(new AutomaticApplicationStageStackAssociator(this)); - } - - /** - * Associate this application with the given stage. - * - */ - public associateStage(stage: cdk.Stage, pipelineStackName: string): cdk.Stage { - this.associatedStages.add(pipelineStackName + '/' + stage.stageName); - cdk.Aspects.of(stage).add(new AutomaticApplicationStageStackAssociator(this)); - return stage; - } - - /** - * Validates if a stage is already associated to the application. - * - */ - public isStageAssociated(stageName: string, pipelineStackName: string): boolean { - return this.associatedStages.has(pipelineStackName + '/' + stageName); - } - - /** - * Get the AppRegistry application. - * - */ - get appRegistryApplication() { - return this.application; - } - - /** - * Import application from the given application ARN. - */ - private importApplication(appProps: AutomaticApplicationProps, applicationStack: cdk.Stack) { - return Application.fromApplicationArn(applicationStack, 'ImportedApplication', appProps.applicationArnValue!); - } - - /** - * Create a new application. - */ - private createAutomaticApplication(appProps: AutomaticApplicationProps, applicationStack: cdk.Stack): IApplication { - return new Application(applicationStack, 'DefaultCdkApplication', { - applicationName: appProps.applicationName!, - description: appProps.description, - }); - } -} diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts index ecdcd839a2eea..3f480e14905a8 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts @@ -1,6 +1,6 @@ export * from './application'; export * from './attribute-group'; -export * from './automatic-application'; +export * from './register-application'; export * from './common'; // AWS::ServiceCatalogAppRegistry CloudFormation Resources: diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/private/utils.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/private/utils.ts new file mode 100644 index 0000000000000..cdbf97a0f7337 --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/private/utils.ts @@ -0,0 +1,22 @@ +import { Token } from '@aws-cdk/core'; + + +/** + * Verifies if application or the visited node is region agnostic. + * + * @param applicationRegion Region of the application. + * @param nodeRegion Region of the visited node. + */ +export function isRegionUnresolved(applicationRegion: string, nodeRegion: string): boolean { + return Token.isUnresolved(applicationRegion) || Token.isUnresolved(nodeRegion); +} + +/** + * Verifies if application or the visited node is account agnostic. + * + * @param applicationAccount Account of the application. + * @param nodeAccount Account of the visited node. + */ +export function isAccountUnresolved(applicationAccount: string, nodeAccount: string): boolean { + return Token.isUnresolved(applicationAccount) || Token.isUnresolved(nodeAccount); +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/register-application.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/register-application.ts new file mode 100644 index 0000000000000..97777e49cf832 --- /dev/null +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/register-application.ts @@ -0,0 +1,100 @@ +import * as cdk from '@aws-cdk/core'; +import { Construct } from 'constructs'; +import { IApplication, Application } from './application'; +import { RegisterApplicationStageStackAssociator } from './aspects/stack-associator'; + +/** + * Properties for a Service Catalog AppRegistry AutoApplication + */ +export interface RegisterApplicationProps { + /** + * Enforces a particular physical application name. + * + * @default - No name. + */ + readonly applicationName?: string; + + /** + * Enforces a particular application arn. + * + * @default - No application arn. + */ + readonly applicationArnValue?: string; + + /** + * Application description. + * + * @default - No description. + */ + readonly description?: string; + + /** + * Stack properties. + * + */ + readonly stackProps: cdk.StackProps; +} + +/** + * An AppRegistry construct to automatically create an application with the given name and description. + * + * The application name must be unique at the account level and it's immutable. + * This construct will automatically associate all stacks in the given scope, however + * in case of a `Pipeline` stack, stage underneath the pipeline will not automatically be associated and + * needs to be associated separately. + * + * If cross account stack is detected, then this construct will automatically share the application to consumer accounts. + * Cross account feature will only work for non environment agnostic stacks. + */ +export class RegisterApplication extends Construct { + /** + * Created or imported application. + */ + private readonly application: IApplication; + private readonly associatedStages: Set = new Set(); + + constructor(scope: cdk.App, id: string, props: RegisterApplicationProps) { + super(scope, id); + + const applicationStack = new cdk.Stack(scope, 'RegisterApplicationStack', props.stackProps); + + if (!!props.applicationArnValue) { + this.application = Application.fromApplicationArn(applicationStack, 'ImportedApplication', props.applicationArnValue); + } else if (!!props.applicationName) { + this.application = new Application(applicationStack, 'DefaultCdkApplication', { + applicationName: props.applicationName, + description: props.description, + }); + } else { + throw new Error('Please provide either ARN or application name.'); + } + + cdk.Aspects.of(scope).add(new RegisterApplicationStageStackAssociator(this)); + } + + /** + * Associate this application with the given stage. + * + */ + public associateStage(stage: cdk.Stage): cdk.Stage { + this.associatedStages.add(stage); + cdk.Aspects.of(stage).add(new RegisterApplicationStageStackAssociator(this)); + return stage; + } + + /** + * Validates if a stage is already associated to the application. + * + */ + public isStageAssociated(stage: cdk.Stage): boolean { + return this.associatedStages.has(stage); + } + + /** + * Get the AppRegistry application. + * + */ + get appRegistryApplication() { + return this.application; + } +} diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/package.json b/packages/@aws-cdk/aws-servicecatalogappregistry/package.json index 107cff9bc8a02..33031698a7ef2 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/package.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/package.json @@ -118,5 +118,10 @@ "publishConfig": { "tag": "latest" }, + "awslint": { + "exclude": [ + "construct-ctor:@aws-cdk/aws-servicecatalogappregistry.RegisterApplication..params[0]" + ] + }, "private": true } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.automatic-application.all-stacks-association.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.register-application.all-stacks-association.ts similarity index 58% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.automatic-application.all-stacks-association.ts rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.register-application.all-stacks-association.ts index a457211fee549..b9314e738fdb9 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.automatic-application.all-stacks-association.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.register-application.all-stacks-association.ts @@ -7,11 +7,11 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'integ-servicecatalogappregistry-application'); -new appreg.AutomaticApplication(app, 'AutoApplication', { - applicationName: 'AppRegistryAutomaticApplication', - description: 'Testing AppRegistry AutomaticApplication', +new appreg.RegisterApplication(app, 'RegisterCdkApplication', { + applicationName: 'AppRegistryRegisterApplication', + description: 'Testing AppRegistry RegisterApplication', stackProps: { - stackName: 'AppRegistryAutoApplicationStack', + stackName: 'AppRegistryRegisterApplicationStack', }, }); diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.assets.json similarity index 65% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.assets.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.assets.json index 6f59f8f54e874..ac38b06e41c82 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.assets.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.assets.json @@ -1,15 +1,15 @@ { "version": "21.0.0", "files": { - "fcea1428896d3e6a887556f0e982b200afff3885810d0fbb95aaa6538399e7c1": { + "8d75667ef63668a1d27f4755a9904f4d54c37343864dc9a2401254605081ec7e": { "source": { - "path": "AutomaticApplicationStack.template.json", + "path": "RegisterApplicationStack.template.json", "packaging": "file" }, "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "fcea1428896d3e6a887556f0e982b200afff3885810d0fbb95aaa6538399e7c1.json", + "objectKey": "8d75667ef63668a1d27f4755a9904f4d54c37343864dc9a2401254605081ec7e.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.template.json similarity index 91% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.template.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.template.json index f32734c03c26a..d45281ed20392 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/AutomaticApplicationStack.template.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.template.json @@ -3,8 +3,8 @@ "DefaultCdkApplication4573D5A3": { "Type": "AWS::ServiceCatalogAppRegistry::Application", "Properties": { - "Name": "AppRegistryAutomaticApplication", - "Description": "Testing AppRegistry AutomaticApplication" + "Name": "AppRegistryRegisterApplication", + "Description": "Testing AppRegistry RegisterApplication" } }, "AppRegistryAssociation": { diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/cdk.out b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/cdk.out similarity index 100% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/cdk.out rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/cdk.out diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json similarity index 75% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json index 33d24bf57aa85..948dafb6a4b90 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json @@ -1,7 +1,7 @@ { "version": "21.0.0", "files": { - "b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c": { + "9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e": { "source": { "path": "integ-servicecatalogappregistry-application.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c.json", + "objectKey": "9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json similarity index 94% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json index f22dcd7a00a59..c089fcae242b9 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json @@ -3,7 +3,7 @@ "AppRegistryAssociation": { "Type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", "Properties": { - "Application": "AppRegistryAutomaticApplication", + "Application": "AppRegistryRegisterApplication", "Resource": { "Ref": "AWS::StackId" }, diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ.json similarity index 80% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ.json index 40e08b259108a..33f9f84729301 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integ.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ.json @@ -1,7 +1,7 @@ { "version": "21.0.0", "testCases": { - "integ.automatic-application.all-stacks-association": { + "integ.register-application.all-stacks-association": { "stacks": [ "integ-servicecatalogappregistry-application" ], diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json similarity index 75% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json index b25bcd9af0cc1..4cb4e710524b3 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json @@ -1,7 +1,7 @@ { "version": "21.0.0", "files": { - "b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c": { + "9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e": { "source": { "path": "integservicecatalogappregistryapplicationresourcesStack4399A149.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c.json", + "objectKey": "9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json similarity index 94% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json index f22dcd7a00a59..c089fcae242b9 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json @@ -3,7 +3,7 @@ "AppRegistryAssociation": { "Type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", "Properties": { - "Application": "AppRegistryAutomaticApplication", + "Application": "AppRegistryRegisterApplication", "Resource": { "Ref": "AWS::StackId" }, diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/manifest.json similarity index 88% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/manifest.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/manifest.json index 7a34919de539f..95ce03328e196 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/manifest.json @@ -23,7 +23,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}/b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -36,7 +36,7 @@ } }, "dependencies": [ - "AutomaticApplicationStack", + "RegisterApplicationStack", "integservicecatalogappregistryapplicationresourcesStack4399A149.assets" ], "metadata": { @@ -87,7 +87,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}/b729ffc4cee0d203853a65cb9f8c3955e56df8ba367d04a2c1fbdb00fd947b9c.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -100,7 +100,7 @@ } }, "dependencies": [ - "AutomaticApplicationStack", + "RegisterApplicationStack", "integ-servicecatalogappregistry-application.assets" ], "metadata": { @@ -135,40 +135,40 @@ }, "displayName": "integ-servicecatalogappregistry-application" }, - "AutomaticApplicationStack.assets": { + "RegisterApplicationStack.assets": { "type": "cdk:asset-manifest", "properties": { - "file": "AutomaticApplicationStack.assets.json", + "file": "RegisterApplicationStack.assets.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" } }, - "AutomaticApplicationStack": { + "RegisterApplicationStack": { "type": "aws:cloudformation:stack", "environment": "aws://unknown-account/unknown-region", "properties": { - "templateFile": "AutomaticApplicationStack.template.json", + "templateFile": "RegisterApplicationStack.template.json", "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}/fcea1428896d3e6a887556f0e982b200afff3885810d0fbb95aaa6538399e7c1.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/8d75667ef63668a1d27f4755a9904f4d54c37343864dc9a2401254605081ec7e.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ - "AutomaticApplicationStack.assets" + "RegisterApplicationStack.assets" ], "lookupRole": { "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", "requiresBootstrapStackVersion": 8, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" }, - "stackName": "AppRegistryAutoApplicationStack" + "stackName": "AppRegistryRegisterApplicationStack" }, "dependencies": [ - "AutomaticApplicationStack.assets" + "RegisterApplicationStack.assets" ], "metadata": { - "/AutomaticApplicationStack": [ + "/RegisterApplicationStack": [ { "type": "aws:cdk:warning", "data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack." @@ -178,32 +178,32 @@ "data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack." } ], - "/AutomaticApplicationStack/DefaultCdkApplication/Resource": [ + "/RegisterApplicationStack/DefaultCdkApplication/Resource": [ { "type": "aws:cdk:logicalId", "data": "DefaultCdkApplication4573D5A3" } ], - "/AutomaticApplicationStack/AppRegistryAssociation": [ + "/RegisterApplicationStack/AppRegistryAssociation": [ { "type": "aws:cdk:logicalId", "data": "AppRegistryAssociation" } ], - "/AutomaticApplicationStack/BootstrapVersion": [ + "/RegisterApplicationStack/BootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "BootstrapVersion" } ], - "/AutomaticApplicationStack/CheckBootstrapVersion": [ + "/RegisterApplicationStack/CheckBootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } ] }, - "displayName": "AutomaticApplicationStack" + "displayName": "RegisterApplicationStack" } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/tree.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/tree.json similarity index 84% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/tree.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/tree.json index cd22f9c195a84..c4a9659a2a03c 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.all-stacks-association.integ.snapshot/tree.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/tree.json @@ -26,7 +26,7 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", "aws:cdk:cloudformation:props": { - "application": "AppRegistryAutomaticApplication", + "application": "AppRegistryRegisterApplication", "resource": { "Ref": "AWS::StackId" }, @@ -50,7 +50,7 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", "aws:cdk:cloudformation:props": { - "application": "AppRegistryAutomaticApplication", + "application": "AppRegistryRegisterApplication", "resource": { "Ref": "AWS::StackId" }, @@ -68,30 +68,30 @@ "version": "0.0.0" } }, - "AutoApplication": { - "id": "AutoApplication", - "path": "AutoApplication", + "RegisterCdkApplication": { + "id": "RegisterCdkApplication", + "path": "RegisterCdkApplication", "constructInfo": { - "fqn": "@aws-cdk/aws-servicecatalogappregistry.AutomaticApplication", + "fqn": "@aws-cdk/aws-servicecatalogappregistry.RegisterApplication", "version": "0.0.0" } }, - "AutomaticApplicationStack": { - "id": "AutomaticApplicationStack", - "path": "AutomaticApplicationStack", + "RegisterApplicationStack": { + "id": "RegisterApplicationStack", + "path": "RegisterApplicationStack", "children": { "DefaultCdkApplication": { "id": "DefaultCdkApplication", - "path": "AutomaticApplicationStack/DefaultCdkApplication", + "path": "RegisterApplicationStack/DefaultCdkApplication", "children": { "Resource": { "id": "Resource", - "path": "AutomaticApplicationStack/DefaultCdkApplication/Resource", + "path": "RegisterApplicationStack/DefaultCdkApplication/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::Application", "aws:cdk:cloudformation:props": { - "name": "AppRegistryAutomaticApplication", - "description": "Testing AppRegistry AutomaticApplication" + "name": "AppRegistryRegisterApplication", + "description": "Testing AppRegistry RegisterApplication" } }, "constructInfo": { @@ -107,7 +107,7 @@ }, "AppRegistryAssociation": { "id": "AppRegistryAssociation", - "path": "AutomaticApplicationStack/AppRegistryAssociation", + "path": "RegisterApplicationStack/AppRegistryAssociation", "attributes": { "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", "aws:cdk:cloudformation:props": { diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.test.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.test.ts similarity index 76% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.test.ts rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.test.ts index 1bf6b184ee2c0..78eef96704430 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/automatic-application.test.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.test.ts @@ -15,16 +15,16 @@ describe('Scope based Associations with Application within Same Account', () => }); }); test('Automatic application will associate allStacks created inside cdkApp', () => { - new appreg.AutomaticApplication(app, 'MyApplication', { - applicationName: 'MyAutomaticApplication', + new appreg.RegisterApplication(app, 'MyApplication', { + applicationName: 'MyRegisterApplication', stackProps: { - stackName: 'MyAutomaticApplicationStack', + stackName: 'MyRegisterApplicationStack', }, }); const anotherStack = new AppRegistrySampleStack(app, 'SampleStack'); Template.fromStack(anotherStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); Template.fromStack(anotherStack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', { - Application: 'MyAutomaticApplication', + Application: 'MyRegisterApplication', Resource: { Ref: 'AWS::StackId' }, }); }); @@ -39,10 +39,10 @@ describe('Scope based Associations with Application with Cross Region/Account', }); }); test('Automatic Application in cross-account associates all stacks created inside cdk app', () => { - new appreg.AutomaticApplication(app, 'MyApplication', { - applicationName: 'MyAutomaticApplication', + new appreg.RegisterApplication(app, 'MyApplication', { + applicationName: 'MyRegisterApplication', stackProps: { - stackName: 'MyAutomaticApplicationStack', + stackName: 'MyRegisterApplicationStack', }, }); const firstStack = new cdk.Stack(app, 'testStack', { @@ -55,27 +55,23 @@ describe('Scope based Associations with Application with Cross Region/Account', Template.fromStack(nestedStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); }); - test('Automatic Application created in scope other than app throws error', () => { - const firstStack = new cdk.Stack(app, 'testStack', { - env: { account: 'account2', region: 'region' }, - }); + test('Automatic Application creation failed when neither Application name nor ARN is provided', () => { expect(() => { - new appreg.AutomaticApplication(firstStack, 'MyApplication', { - applicationName: 'MyAutomaticApplication', + new appreg.RegisterApplication(app, 'MyApplication', { stackProps: { - stackName: 'MyAutomaticApplicationStack', + stackName: 'MyRegisterApplicationStack', }, }); - }).toThrow(/Scope must be a cdk App/); + }).toThrow(/Please provide either ARN or application name./); }); test('associate resource on imported application', () => { const resource = new cdk.Stack(app, 'MyStack'); - new appreg.AutomaticApplication(app, 'MyApplication', { + new appreg.RegisterApplication(app, 'MyApplication', { applicationArnValue: 'arn:aws:servicecatalog:us-east-1:482211128593:/applications/0a17wtxeg5vilok0sbxfozwpq9', stackProps: { - stackName: 'MyAutomaticApplicationStack', + stackName: 'MyRegisterApplicationStack', }, }); @@ -86,10 +82,10 @@ describe('Scope based Associations with Application with Cross Region/Account', }), test('Automatic Application with cross region stacks inside cdkApp throws error', () => { - new appreg.AutomaticApplication(app, 'MyApplication', { - applicationName: 'MyAutomaticApplication', + new appreg.RegisterApplication(app, 'MyApplication', { + applicationName: 'MyRegisterApplication', stackProps: { - stackName: 'MyAutomaticApplicationStack', + stackName: 'MyRegisterApplicationStack', env: { account: 'account2', region: 'region2' }, }, }); @@ -101,10 +97,10 @@ describe('Scope based Associations with Application with Cross Region/Account', }); test('Environment Agnostic Automatic Application with cross region stacks inside cdkApp gives warning', () => { - new appreg.AutomaticApplication(app, 'MyApplication', { - applicationName: 'MyAutomaticApplication', + new appreg.RegisterApplication(app, 'MyApplication', { + applicationName: 'MyRegisterApplication', stackProps: { - stackName: 'MyAutomaticApplicationStack', + stackName: 'MyRegisterApplicationStack', }, }); @@ -115,10 +111,10 @@ describe('Scope based Associations with Application with Cross Region/Account', }); test('Cdk App Containing Pipeline with stage but stage not associated throws error', () => { - const application = new appreg.AutomaticApplication(app, 'MyApplication', { - applicationName: 'MyAutomaticApplication', + const application = new appreg.RegisterApplication(app, 'MyApplication', { + applicationName: 'MyRegisterApplication', stackProps: { - stackName: 'MyAutomaticApplicationStack', + stackName: 'MyRegisterApplicationStack', }, }); const pipelineStack = new AppRegistrySampleCodePipelineStack(app, 'PipelineStackA', { @@ -127,14 +123,14 @@ describe('Scope based Associations with Application with Cross Region/Account', }); app.synth(); Annotations.fromStack(pipelineStack).hasError('*', - 'Associate Stage: SampleStage to ensure all stacks in your cdk app are associated with AppRegistry. You can use AutomaticApplication.associateStage to associate any stage.'); + 'Associate Stage: SampleStage to ensure all stacks in your cdk app are associated with AppRegistry. You can use RegisterApplication.associateStage to associate any stage.'); }); test('Cdk App Containing Pipeline with stage and stage associated successfully gets synthesized', () => { - const application = new appreg.AutomaticApplication(app, 'MyApplication', { + const application = new appreg.RegisterApplication(app, 'MyApplication', { applicationName: 'MyApplication', stackProps: { - stackName: 'MyAutomaticApplicationStack', + stackName: 'MyRegisterApplicationStack', }, }); const pipelineStack = new AppRegistrySampleCodePipelineStack(app, 'PipelineStackA', { @@ -147,7 +143,7 @@ describe('Scope based Associations with Application with Cross Region/Account', }); interface AppRegistrySampleCodePipelineStackProps extends cdk.StackProps { - application: appreg.AutomaticApplication; + application: appreg.RegisterApplication; associateStage: boolean; } @@ -180,7 +176,7 @@ class AppRegistrySampleCodePipelineStack extends cdk.Stack { ); if (props.associateStage) { - props.application.associateStage(stage, this.stackName); + props.application.associateStage(stage); } pipeline.addStage(stage); } From d8ca9686e89697539343e82dc7ca65f1a69b1cda Mon Sep 17 00:00:00 2001 From: Rohit Aggarwal Date: Thu, 29 Sep 2022 09:24:43 -0700 Subject: [PATCH 4/4] Updated New L2 ConstructName to ApplicationAssociator --- .../aws-servicecatalogappregistry/README.md | 36 +++++------ ...plication.ts => application-associator.ts} | 14 ++--- .../lib/aspects/stack-associator.ts | 18 +++--- .../lib/index.ts | 2 +- .../package.json | 2 +- .../ApplicationAssociatorStack.assets.json} | 6 +- .../ApplicationAssociatorStack.template.json} | 4 +- .../cdk.out | 0 ...catalogappregistry-application.assets.json | 4 +- ...talogappregistry-application.template.json | 2 +- .../integ.json | 2 +- ...licationresourcesStack4399A149.assets.json | 4 +- ...cationresourcesStack4399A149.template.json | 2 +- .../manifest.json | 36 +++++------ .../tree.json | 22 +++---- ...test.ts => application-associator.test.ts} | 60 +++++++++---------- ...tion-associator.all-stacks-association.ts} | 8 +-- 17 files changed, 111 insertions(+), 111 deletions(-) rename packages/@aws-cdk/aws-servicecatalogappregistry/lib/{register-application.ts => application-associator.ts} (82%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.assets.json => application-associator.all-stacks-association.integ.snapshot/ApplicationAssociatorStack.assets.json} (65%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.template.json => application-associator.all-stacks-association.integ.snapshot/ApplicationAssociatorStack.template.json} (91%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{register-application.all-stacks-association.integ.snapshot => application-associator.all-stacks-association.integ.snapshot}/cdk.out (100%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{register-application.all-stacks-association.integ.snapshot => application-associator.all-stacks-association.integ.snapshot}/integ-servicecatalogappregistry-application.assets.json (75%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{register-application.all-stacks-association.integ.snapshot => application-associator.all-stacks-association.integ.snapshot}/integ-servicecatalogappregistry-application.template.json (94%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{register-application.all-stacks-association.integ.snapshot => application-associator.all-stacks-association.integ.snapshot}/integ.json (79%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{register-application.all-stacks-association.integ.snapshot => application-associator.all-stacks-association.integ.snapshot}/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json (75%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{register-application.all-stacks-association.integ.snapshot => application-associator.all-stacks-association.integ.snapshot}/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json (94%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{register-application.all-stacks-association.integ.snapshot => application-associator.all-stacks-association.integ.snapshot}/manifest.json (88%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{register-application.all-stacks-association.integ.snapshot => application-associator.all-stacks-association.integ.snapshot}/tree.json (85%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{register-application.test.ts => application-associator.test.ts} (75%) rename packages/@aws-cdk/aws-servicecatalogappregistry/test/{integ.register-application.all-stacks-association.ts => integ.application-associator.all-stacks-association.ts} (57%) diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/README.md b/packages/@aws-cdk/aws-servicecatalogappregistry/README.md index 9d4d1592ea468..c65fd7a66b2a6 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/README.md +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/README.md @@ -27,7 +27,7 @@ enables organizations to create and manage repositores of applications and assoc ## Table Of Contents - [Application](#application) -- [Register-Application](#register-application) +- [Application-Associator](#application-associator) - [Attribute-Group](#attribute-group) - [Associations](#associations) - [Associating application with an attribute group](#attribute-group-association) @@ -65,18 +65,18 @@ const importedApplication = appreg.Application.fromApplicationArn( ); ``` -## Register-Application +## Application-Associator -If you want to create an Application named `MyRegisteredApplication` in account `123456789012` and region `us-east-1` -and want to associate all stacks in the `App` scope to `MyRegisteredApplication`, then use as shown in the example below: +If you want to create an Application named `MyAssociatedApplication` in account `123456789012` and region `us-east-1` +and want to associate all stacks in the `App` scope to `MyAssociatedApplication`, then use as shown in the example below: ```ts const app = new App(); -const registeredApp = new appreg.RegisterApplication(app, 'RegisterApplication', { - applicationName: 'MyRegisteredApplication', - description: 'Testing registered application', +const associatedApp = new appreg.ApplicationAssociator(app, 'AssociatedApplication', { + applicationName: 'MyAssociatedApplication', + description: 'Testing associated application', stackProps: { - stackName: 'MyRegisteredApplicationStack', + stackName: 'MyAssociatedApplicationStack', env: {account: '123456789012', region: 'us-east-1'}, }, }); @@ -87,16 +87,16 @@ and want to associate all stacks in the `App` scope to your imported application ```ts const app = new App(); -const registeredApp = new appreg.RegisterApplication(app, 'RegisterApplication', { +const associatedApp = new appreg.ApplicationAssociator(app, 'AssociatedApplication', { applicationArnValue: 'arn:aws:servicecatalog:us-east-1:123456789012:/applications/applicationId', stackProps: { - stackName: 'MyRegisteredApplicationStack', + stackName: 'MyAssociatedApplicationStack', }, }); ``` If you are using CDK Pipelines to deploy your application, the application stacks will be inside Stages, and -RegisterApplication will not be able to find them. Call `associateStage` on each Stage object before adding it to the +ApplicationAssociator will not be able to find them. Call `associateStage` on each Stage object before adding it to the Pipeline, as shown in the example below: ```ts @@ -110,28 +110,28 @@ class ApplicationPipelineStack extends cdk.Stack { constructor(scope: cdk.App, id: string, props: ApplicationPipelineStackProps) { super(scope, id, props); - //associate the stage to register application. + //associate the stage to application associator. props.application.associateStage(beta); pipeline.addStage(beta); } }; interface ApplicationPipelineStackProps extends cdk.StackProps { - application: appreg.RegisterApplication; + application: appreg.ApplicationAssociator; }; const app = new App(); -const registeredApp = new appreg.RegisterApplication(app, 'RegisterApplication', { - applicationName: 'MyPipelineRegisteredApplication', - description: 'Testing pipeline registered app', +const associatedApp = new appreg.ApplicationAssociator(app, 'AssociatedApplication', { + applicationName: 'MyPipelineAssociatedApplication', + description: 'Testing pipeline associated app', stackProps: { - stackName: 'MyPipelineRegisteredApplicationStack', + stackName: 'MyPipelineAssociatedApplicationStack', env: {account: '123456789012', region: 'us-east-1'}, }, }); const cdkPipeline = new ApplicationPipelineStack(app, 'CDKApplicationPipelineStack', { - application: registeredApp, + application: associatedApp, env: {account: '123456789012', region: 'us-east-1'}, }); ``` diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/register-application.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application-associator.ts similarity index 82% rename from packages/@aws-cdk/aws-servicecatalogappregistry/lib/register-application.ts rename to packages/@aws-cdk/aws-servicecatalogappregistry/lib/application-associator.ts index 97777e49cf832..226e9d6c452ec 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/register-application.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/application-associator.ts @@ -1,12 +1,12 @@ import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; import { IApplication, Application } from './application'; -import { RegisterApplicationStageStackAssociator } from './aspects/stack-associator'; +import { CheckedStageStackAssociator } from './aspects/stack-associator'; /** * Properties for a Service Catalog AppRegistry AutoApplication */ -export interface RegisterApplicationProps { +export interface ApplicationAssociatorProps { /** * Enforces a particular physical application name. * @@ -46,17 +46,17 @@ export interface RegisterApplicationProps { * If cross account stack is detected, then this construct will automatically share the application to consumer accounts. * Cross account feature will only work for non environment agnostic stacks. */ -export class RegisterApplication extends Construct { +export class ApplicationAssociator extends Construct { /** * Created or imported application. */ private readonly application: IApplication; private readonly associatedStages: Set = new Set(); - constructor(scope: cdk.App, id: string, props: RegisterApplicationProps) { + constructor(scope: cdk.App, id: string, props: ApplicationAssociatorProps) { super(scope, id); - const applicationStack = new cdk.Stack(scope, 'RegisterApplicationStack', props.stackProps); + const applicationStack = new cdk.Stack(scope, 'ApplicationAssociatorStack', props.stackProps); if (!!props.applicationArnValue) { this.application = Application.fromApplicationArn(applicationStack, 'ImportedApplication', props.applicationArnValue); @@ -69,7 +69,7 @@ export class RegisterApplication extends Construct { throw new Error('Please provide either ARN or application name.'); } - cdk.Aspects.of(scope).add(new RegisterApplicationStageStackAssociator(this)); + cdk.Aspects.of(scope).add(new CheckedStageStackAssociator(this)); } /** @@ -78,7 +78,7 @@ export class RegisterApplication extends Construct { */ public associateStage(stage: cdk.Stage): cdk.Stage { this.associatedStages.add(stage); - cdk.Aspects.of(stage).add(new RegisterApplicationStageStackAssociator(this)); + cdk.Aspects.of(stage).add(new CheckedStageStackAssociator(this)); return stage; } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts index d8ea84e63c179..593bf8a8265d6 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/aspects/stack-associator.ts @@ -1,9 +1,9 @@ import { IAspect, Stack, Stage, Annotations } from '@aws-cdk/core'; import { IConstruct } from 'constructs'; import { IApplication } from '../application'; +import { ApplicationAssociator } from '../application-associator'; import { SharePermission } from '../common'; import { isRegionUnresolved, isAccountUnresolved } from '../private/utils'; -import { RegisterApplication } from '../register-application'; /** * Aspect class, this will visit each node from the provided construct once. @@ -13,7 +13,7 @@ import { RegisterApplication } from '../register-application'; */ abstract class StackAssociatorBase implements IAspect { protected abstract readonly application: IApplication; - protected abstract readonly registerApplication?: RegisterApplication; + protected abstract readonly applicationAssociator?: ApplicationAssociator; protected readonly sharedAccounts: Set = new Set(); @@ -21,10 +21,10 @@ abstract class StackAssociatorBase implements IAspect { // verify if a stage in a particular stack is associated to Application. node.node.children.forEach((childNode) => { if (Stage.isStage(childNode)) { - var stageAssociated = this.registerApplication?.isStageAssociated(childNode); + var stageAssociated = this.applicationAssociator?.isStageAssociated(childNode); if (stageAssociated === false) { this.error(childNode, 'Associate Stage: ' + childNode.stageName + ' to ensure all stacks in your cdk app are associated with AppRegistry. ' - + 'You can use RegisterApplication.associateStage to associate any stage.'); + + 'You can use ApplicationAssociator.associateStage to associate any stage.'); } } }); @@ -109,20 +109,20 @@ abstract class StackAssociatorBase implements IAspect { } } -export class RegisterApplicationStageStackAssociator extends StackAssociatorBase { +export class CheckedStageStackAssociator extends StackAssociatorBase { protected readonly application: IApplication; - protected readonly registerApplication?: RegisterApplication; + protected readonly applicationAssociator?: ApplicationAssociator; - constructor(app: RegisterApplication) { + constructor(app: ApplicationAssociator) { super(); this.application = app.appRegistryApplication; - this.registerApplication = app; + this.applicationAssociator = app; } } export class StageStackAssociator extends StackAssociatorBase { protected readonly application: IApplication; - protected readonly registerApplication?: RegisterApplication; + protected readonly applicationAssociator?: ApplicationAssociator; constructor(app: IApplication) { super(); diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts index 3f480e14905a8..72239c4a1d110 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/lib/index.ts @@ -1,6 +1,6 @@ export * from './application'; export * from './attribute-group'; -export * from './register-application'; +export * from './application-associator'; export * from './common'; // AWS::ServiceCatalogAppRegistry CloudFormation Resources: diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/package.json b/packages/@aws-cdk/aws-servicecatalogappregistry/package.json index 33031698a7ef2..aa5401b6ac812 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/package.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/package.json @@ -120,7 +120,7 @@ }, "awslint": { "exclude": [ - "construct-ctor:@aws-cdk/aws-servicecatalogappregistry.RegisterApplication..params[0]" + "construct-ctor:@aws-cdk/aws-servicecatalogappregistry.ApplicationAssociator..params[0]" ] }, "private": true diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/ApplicationAssociatorStack.assets.json similarity index 65% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.assets.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/ApplicationAssociatorStack.assets.json index ac38b06e41c82..2f99ef79e2174 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.assets.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/ApplicationAssociatorStack.assets.json @@ -1,15 +1,15 @@ { "version": "21.0.0", "files": { - "8d75667ef63668a1d27f4755a9904f4d54c37343864dc9a2401254605081ec7e": { + "4285054f947789e255e76c75b889b3b216adabb0b3f990c8966c18459cdf7b35": { "source": { - "path": "RegisterApplicationStack.template.json", + "path": "ApplicationAssociatorStack.template.json", "packaging": "file" }, "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "8d75667ef63668a1d27f4755a9904f4d54c37343864dc9a2401254605081ec7e.json", + "objectKey": "4285054f947789e255e76c75b889b3b216adabb0b3f990c8966c18459cdf7b35.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/ApplicationAssociatorStack.template.json similarity index 91% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.template.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/ApplicationAssociatorStack.template.json index d45281ed20392..79c9dec209b9e 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/RegisterApplicationStack.template.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/ApplicationAssociatorStack.template.json @@ -3,8 +3,8 @@ "DefaultCdkApplication4573D5A3": { "Type": "AWS::ServiceCatalogAppRegistry::Application", "Properties": { - "Name": "AppRegistryRegisterApplication", - "Description": "Testing AppRegistry RegisterApplication" + "Name": "AppRegistryAssociatedApplication", + "Description": "Testing AppRegistry ApplicationAssociator" } }, "AppRegistryAssociation": { diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/cdk.out b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/cdk.out similarity index 100% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/cdk.out rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/cdk.out diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json similarity index 75% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json index 948dafb6a4b90..5dec59ac54517 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.assets.json @@ -1,7 +1,7 @@ { "version": "21.0.0", "files": { - "9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e": { + "19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc": { "source": { "path": "integ-servicecatalogappregistry-application.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e.json", + "objectKey": "19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json similarity index 94% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json index c089fcae242b9..ecc817b74774a 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integ-servicecatalogappregistry-application.template.json @@ -3,7 +3,7 @@ "AppRegistryAssociation": { "Type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", "Properties": { - "Application": "AppRegistryRegisterApplication", + "Application": "AppRegistryAssociatedApplication", "Resource": { "Ref": "AWS::StackId" }, diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integ.json similarity index 79% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integ.json index 33f9f84729301..1f1a144803dcd 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integ.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integ.json @@ -1,7 +1,7 @@ { "version": "21.0.0", "testCases": { - "integ.register-application.all-stacks-association": { + "integ.application-associator.all-stacks-association": { "stacks": [ "integ-servicecatalogappregistry-application" ], diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json similarity index 75% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json index 4cb4e710524b3..65c6d2c1ecf64 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.assets.json @@ -1,7 +1,7 @@ { "version": "21.0.0", "files": { - "9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e": { + "19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc": { "source": { "path": "integservicecatalogappregistryapplicationresourcesStack4399A149.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e.json", + "objectKey": "19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json similarity index 94% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json index c089fcae242b9..ecc817b74774a 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/integservicecatalogappregistryapplicationresourcesStack4399A149.template.json @@ -3,7 +3,7 @@ "AppRegistryAssociation": { "Type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", "Properties": { - "Application": "AppRegistryRegisterApplication", + "Application": "AppRegistryAssociatedApplication", "Resource": { "Ref": "AWS::StackId" }, diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/manifest.json similarity index 88% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/manifest.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/manifest.json index 95ce03328e196..65db06b047d68 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/manifest.json @@ -23,7 +23,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}/9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -36,7 +36,7 @@ } }, "dependencies": [ - "RegisterApplicationStack", + "ApplicationAssociatorStack", "integservicecatalogappregistryapplicationresourcesStack4399A149.assets" ], "metadata": { @@ -87,7 +87,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}/9e04f80022c72b360d422a8775b90407d2e2092478c00e65e1db6eed7d941e5e.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/19dd33f3c17e59cafd22b9459b0a8d9bedbd42252737fedb06b2bcdbcf7809cc.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -100,7 +100,7 @@ } }, "dependencies": [ - "RegisterApplicationStack", + "ApplicationAssociatorStack", "integ-servicecatalogappregistry-application.assets" ], "metadata": { @@ -135,40 +135,40 @@ }, "displayName": "integ-servicecatalogappregistry-application" }, - "RegisterApplicationStack.assets": { + "ApplicationAssociatorStack.assets": { "type": "cdk:asset-manifest", "properties": { - "file": "RegisterApplicationStack.assets.json", + "file": "ApplicationAssociatorStack.assets.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" } }, - "RegisterApplicationStack": { + "ApplicationAssociatorStack": { "type": "aws:cloudformation:stack", "environment": "aws://unknown-account/unknown-region", "properties": { - "templateFile": "RegisterApplicationStack.template.json", + "templateFile": "ApplicationAssociatorStack.template.json", "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}/8d75667ef63668a1d27f4755a9904f4d54c37343864dc9a2401254605081ec7e.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/4285054f947789e255e76c75b889b3b216adabb0b3f990c8966c18459cdf7b35.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ - "RegisterApplicationStack.assets" + "ApplicationAssociatorStack.assets" ], "lookupRole": { "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", "requiresBootstrapStackVersion": 8, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" }, - "stackName": "AppRegistryRegisterApplicationStack" + "stackName": "AppRegistryApplicationAssociatorStack" }, "dependencies": [ - "RegisterApplicationStack.assets" + "ApplicationAssociatorStack.assets" ], "metadata": { - "/RegisterApplicationStack": [ + "/ApplicationAssociatorStack": [ { "type": "aws:cdk:warning", "data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack." @@ -178,32 +178,32 @@ "data": "Environment agnostic stack determined, AppRegistry association might not work as expected in case you deploy cross-region or cross-account stack." } ], - "/RegisterApplicationStack/DefaultCdkApplication/Resource": [ + "/ApplicationAssociatorStack/DefaultCdkApplication/Resource": [ { "type": "aws:cdk:logicalId", "data": "DefaultCdkApplication4573D5A3" } ], - "/RegisterApplicationStack/AppRegistryAssociation": [ + "/ApplicationAssociatorStack/AppRegistryAssociation": [ { "type": "aws:cdk:logicalId", "data": "AppRegistryAssociation" } ], - "/RegisterApplicationStack/BootstrapVersion": [ + "/ApplicationAssociatorStack/BootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "BootstrapVersion" } ], - "/RegisterApplicationStack/CheckBootstrapVersion": [ + "/ApplicationAssociatorStack/CheckBootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } ] }, - "displayName": "RegisterApplicationStack" + "displayName": "ApplicationAssociatorStack" } } } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/tree.json b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/tree.json similarity index 85% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/tree.json rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/tree.json index c4a9659a2a03c..078cc92093b86 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.all-stacks-association.integ.snapshot/tree.json +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.all-stacks-association.integ.snapshot/tree.json @@ -26,7 +26,7 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", "aws:cdk:cloudformation:props": { - "application": "AppRegistryRegisterApplication", + "application": "AppRegistryAssociatedApplication", "resource": { "Ref": "AWS::StackId" }, @@ -50,7 +50,7 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", "aws:cdk:cloudformation:props": { - "application": "AppRegistryRegisterApplication", + "application": "AppRegistryAssociatedApplication", "resource": { "Ref": "AWS::StackId" }, @@ -72,26 +72,26 @@ "id": "RegisterCdkApplication", "path": "RegisterCdkApplication", "constructInfo": { - "fqn": "@aws-cdk/aws-servicecatalogappregistry.RegisterApplication", + "fqn": "@aws-cdk/aws-servicecatalogappregistry.ApplicationAssociator", "version": "0.0.0" } }, - "RegisterApplicationStack": { - "id": "RegisterApplicationStack", - "path": "RegisterApplicationStack", + "ApplicationAssociatorStack": { + "id": "ApplicationAssociatorStack", + "path": "ApplicationAssociatorStack", "children": { "DefaultCdkApplication": { "id": "DefaultCdkApplication", - "path": "RegisterApplicationStack/DefaultCdkApplication", + "path": "ApplicationAssociatorStack/DefaultCdkApplication", "children": { "Resource": { "id": "Resource", - "path": "RegisterApplicationStack/DefaultCdkApplication/Resource", + "path": "ApplicationAssociatorStack/DefaultCdkApplication/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::Application", "aws:cdk:cloudformation:props": { - "name": "AppRegistryRegisterApplication", - "description": "Testing AppRegistry RegisterApplication" + "name": "AppRegistryAssociatedApplication", + "description": "Testing AppRegistry ApplicationAssociator" } }, "constructInfo": { @@ -107,7 +107,7 @@ }, "AppRegistryAssociation": { "id": "AppRegistryAssociation", - "path": "RegisterApplicationStack/AppRegistryAssociation", + "path": "ApplicationAssociatorStack/AppRegistryAssociation", "attributes": { "aws:cdk:cloudformation:type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation", "aws:cdk:cloudformation:props": { diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.test.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.test.ts similarity index 75% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.test.ts rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.test.ts index 78eef96704430..de64c0c35b68b 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/register-application.test.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/application-associator.test.ts @@ -14,17 +14,17 @@ describe('Scope based Associations with Application within Same Account', () => }, }); }); - test('Automatic application will associate allStacks created inside cdkApp', () => { - new appreg.RegisterApplication(app, 'MyApplication', { - applicationName: 'MyRegisterApplication', + test('ApplicationAssociator will associate allStacks created inside cdkApp', () => { + new appreg.ApplicationAssociator(app, 'MyApplication', { + applicationName: 'MyAssociatedApplication', stackProps: { - stackName: 'MyRegisterApplicationStack', + stackName: 'MyAssociatedApplicationStack', }, }); const anotherStack = new AppRegistrySampleStack(app, 'SampleStack'); Template.fromStack(anotherStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); Template.fromStack(anotherStack).hasResourceProperties('AWS::ServiceCatalogAppRegistry::ResourceAssociation', { - Application: 'MyRegisterApplication', + Application: 'MyAssociatedApplication', Resource: { Ref: 'AWS::StackId' }, }); }); @@ -38,11 +38,11 @@ describe('Scope based Associations with Application with Cross Region/Account', }, }); }); - test('Automatic Application in cross-account associates all stacks created inside cdk app', () => { - new appreg.RegisterApplication(app, 'MyApplication', { - applicationName: 'MyRegisterApplication', + test('ApplicationAssociator in cross-account associates all stacks created inside cdk app', () => { + new appreg.ApplicationAssociator(app, 'MyApplication', { + applicationName: 'MyAssociatedApplication', stackProps: { - stackName: 'MyRegisterApplicationStack', + stackName: 'MyAssociatedApplicationStack', }, }); const firstStack = new cdk.Stack(app, 'testStack', { @@ -55,11 +55,11 @@ describe('Scope based Associations with Application with Cross Region/Account', Template.fromStack(nestedStack).resourceCountIs('AWS::ServiceCatalogAppRegistry::ResourceAssociation', 1); }); - test('Automatic Application creation failed when neither Application name nor ARN is provided', () => { + test('ApplicationAssociator creation failed when neither Application name nor ARN is provided', () => { expect(() => { - new appreg.RegisterApplication(app, 'MyApplication', { + new appreg.ApplicationAssociator(app, 'MyApplication', { stackProps: { - stackName: 'MyRegisterApplicationStack', + stackName: 'MyAssociatedApplicationStack', }, }); }).toThrow(/Please provide either ARN or application name./); @@ -68,10 +68,10 @@ describe('Scope based Associations with Application with Cross Region/Account', test('associate resource on imported application', () => { const resource = new cdk.Stack(app, 'MyStack'); - new appreg.RegisterApplication(app, 'MyApplication', { + new appreg.ApplicationAssociator(app, 'MyApplication', { applicationArnValue: 'arn:aws:servicecatalog:us-east-1:482211128593:/applications/0a17wtxeg5vilok0sbxfozwpq9', stackProps: { - stackName: 'MyRegisterApplicationStack', + stackName: 'MyAssociatedApplicationStack', }, }); @@ -81,11 +81,11 @@ describe('Scope based Associations with Application with Cross Region/Account', }); }), - test('Automatic Application with cross region stacks inside cdkApp throws error', () => { - new appreg.RegisterApplication(app, 'MyApplication', { - applicationName: 'MyRegisterApplication', + test('ApplicationAssociator with cross region stacks inside cdkApp throws error', () => { + new appreg.ApplicationAssociator(app, 'MyApplication', { + applicationName: 'MyAssociatedApplication', stackProps: { - stackName: 'MyRegisterApplicationStack', + stackName: 'MyAssociatedApplicationStack', env: { account: 'account2', region: 'region2' }, }, }); @@ -96,11 +96,11 @@ describe('Scope based Associations with Application with Cross Region/Account', Annotations.fromStack(crossRegionStack).hasError('*', 'AppRegistry does not support cross region associations. Application region region2, stack region region'); }); - test('Environment Agnostic Automatic Application with cross region stacks inside cdkApp gives warning', () => { - new appreg.RegisterApplication(app, 'MyApplication', { - applicationName: 'MyRegisterApplication', + test('Environment Agnostic ApplicationAssociator with cross region stacks inside cdkApp gives warning', () => { + new appreg.ApplicationAssociator(app, 'MyApplication', { + applicationName: 'MyAssociatedApplication', stackProps: { - stackName: 'MyRegisterApplicationStack', + stackName: 'MyAssociatedApplicationStack', }, }); @@ -111,10 +111,10 @@ describe('Scope based Associations with Application with Cross Region/Account', }); test('Cdk App Containing Pipeline with stage but stage not associated throws error', () => { - const application = new appreg.RegisterApplication(app, 'MyApplication', { - applicationName: 'MyRegisterApplication', + const application = new appreg.ApplicationAssociator(app, 'MyApplication', { + applicationName: 'MyAssociatedApplication', stackProps: { - stackName: 'MyRegisterApplicationStack', + stackName: 'MyAssociatedApplicationStack', }, }); const pipelineStack = new AppRegistrySampleCodePipelineStack(app, 'PipelineStackA', { @@ -123,14 +123,14 @@ describe('Scope based Associations with Application with Cross Region/Account', }); app.synth(); Annotations.fromStack(pipelineStack).hasError('*', - 'Associate Stage: SampleStage to ensure all stacks in your cdk app are associated with AppRegistry. You can use RegisterApplication.associateStage to associate any stage.'); + 'Associate Stage: SampleStage to ensure all stacks in your cdk app are associated with AppRegistry. You can use ApplicationAssociator.associateStage to associate any stage.'); }); test('Cdk App Containing Pipeline with stage and stage associated successfully gets synthesized', () => { - const application = new appreg.RegisterApplication(app, 'MyApplication', { - applicationName: 'MyApplication', + const application = new appreg.ApplicationAssociator(app, 'MyApplication', { + applicationName: 'MyAssociatedApplication', stackProps: { - stackName: 'MyRegisterApplicationStack', + stackName: 'MyAssociatedApplicationStack', }, }); const pipelineStack = new AppRegistrySampleCodePipelineStack(app, 'PipelineStackA', { @@ -143,7 +143,7 @@ describe('Scope based Associations with Application with Cross Region/Account', }); interface AppRegistrySampleCodePipelineStackProps extends cdk.StackProps { - application: appreg.RegisterApplication; + application: appreg.ApplicationAssociator; associateStage: boolean; } diff --git a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.register-application.all-stacks-association.ts b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application-associator.all-stacks-association.ts similarity index 57% rename from packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.register-application.all-stacks-association.ts rename to packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application-associator.all-stacks-association.ts index b9314e738fdb9..afd822dc6dc16 100644 --- a/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.register-application.all-stacks-association.ts +++ b/packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application-associator.all-stacks-association.ts @@ -7,11 +7,11 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'integ-servicecatalogappregistry-application'); -new appreg.RegisterApplication(app, 'RegisterCdkApplication', { - applicationName: 'AppRegistryRegisterApplication', - description: 'Testing AppRegistry RegisterApplication', +new appreg.ApplicationAssociator(app, 'RegisterCdkApplication', { + applicationName: 'AppRegistryAssociatedApplication', + description: 'Testing AppRegistry ApplicationAssociator', stackProps: { - stackName: 'AppRegistryRegisterApplicationStack', + stackName: 'AppRegistryApplicationAssociatorStack', }, });