forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(servicecatalogappregistry): application-associator L2 Construct (a…
…ws#22024) new application-associator L2 Construct : This construct is responsible for following: * Create a new AppRegistry Application * Associate all stacks inside a cdk app scope * share an app registry application upon determining cross account stack. [ This only works for non environment agnostic stack] ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* Co-authored by: Santanu Ghosh
- Loading branch information
1 parent
6752b66
commit 6151904
Showing
21 changed files
with
1,349 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
packages/@aws-cdk/aws-servicecatalogappregistry/lib/application-associator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import { Construct } from 'constructs'; | ||
import { IApplication, Application } from './application'; | ||
import { CheckedStageStackAssociator } from './aspects/stack-associator'; | ||
|
||
/** | ||
* Properties for a Service Catalog AppRegistry AutoApplication | ||
*/ | ||
export interface ApplicationAssociatorProps { | ||
/** | ||
* 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 ApplicationAssociator extends Construct { | ||
/** | ||
* Created or imported application. | ||
*/ | ||
private readonly application: IApplication; | ||
private readonly associatedStages: Set<cdk.Stage> = new Set(); | ||
|
||
constructor(scope: cdk.App, id: string, props: ApplicationAssociatorProps) { | ||
super(scope, id); | ||
|
||
const applicationStack = new cdk.Stack(scope, 'ApplicationAssociatorStack', 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 CheckedStageStackAssociator(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 CheckedStageStackAssociator(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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.