11// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33import * as cdk from "aws-cdk-lib" ;
4- import * as appreg from "@aws-cdk/aws-servicecatalogappregistry-alpha" ;
5- import { Aws , CfnCondition , Fn , Tags } from "aws-cdk-lib" ;
6- import { CfnApplication } from "aws-cdk-lib/aws-applicationinsights" ;
7- import {
8- CfnAttributeGroup ,
9- CfnAttributeGroupAssociation ,
10- CfnResourceAssociation ,
11- } from "aws-cdk-lib/aws-servicecatalogappregistry" ;
12- import { CfnResourceShare } from "aws-cdk-lib/aws-ram" ;
4+ import * as servicecatalogappregistry from "aws-cdk-lib/aws-servicecatalogappregistry" ;
5+ import { Aws , Fn , Tags } from "aws-cdk-lib" ;
136import { Construct } from "constructs" ;
14- import overrideLogicalId from "../cdk-helper/override-logical-id" ;
15- import setCondition from "../cdk-helper/set-condition" ;
167
178export interface AppRegistryHubResourcesProps extends cdk . StackProps {
189 solutionId : string ;
@@ -21,104 +12,26 @@ export interface AppRegistryHubResourcesProps extends cdk.StackProps {
2112 solutionVersion : string ;
2213 appRegistryApplicationName : string ;
2314 applicationType : string ;
24- managementAccountId : string ;
25- orgId : string ;
26- multiAccountDeploymentCondition : CfnCondition ;
2715}
2816
2917export class AppRegistryHubResources extends Construct {
18+ public readonly applicationTagValue : string ;
3019 constructor ( scope : Construct , id : string , props : AppRegistryHubResourcesProps ) {
3120 super ( scope , id ) ;
32- const application = new appreg . Application ( this , "AppRegistry" , {
33- applicationName : Fn . join ( "-" , [ props . appRegistryApplicationName , Aws . REGION , Aws . ACCOUNT_ID ] ) ,
21+ const application = new servicecatalogappregistry . CfnApplication ( this , "AppRegistry" , {
22+ name : Fn . join ( "-" , [ props . appRegistryApplicationName , Aws . REGION , Aws . ACCOUNT_ID ] ) ,
3423 description : `Service Catalog application to track and manage all your resources for the solution ${ props . solutionName } ` ,
3524 } ) ;
36- const cfnApplication = application . node . defaultChild as CfnApplication ;
37- overrideLogicalId ( cfnApplication , "Application" ) ;
38-
39- const cfnresourceAssociation = new CfnResourceAssociation ( this , "CfnResourceAssociation" , {
40- application : application . applicationId ,
41- resource : Aws . STACK_ID ,
42- resourceType : "CFN_STACK" ,
43- } ) ;
44- overrideLogicalId ( cfnresourceAssociation , "AppRegistryApplicationStackAssociation" ) ;
45-
46- const attributeGroup = new appreg . AttributeGroup ( this , "DefaultApplicationAttributeGroup" , {
47- attributeGroupName : Fn . join ( "-" , [ props . appRegistryApplicationName , Aws . REGION , Aws . ACCOUNT_ID ] ) ,
48- description : "Attribute group for solution information" ,
49- attributes : {
50- applicationType : props . applicationType ,
51- version : props . solutionVersion ,
52- solutionID : props . solutionId ,
53- solutionName : props . solutionName ,
54- } ,
55- } ) ;
56-
57- const cfnAttributeGroup = attributeGroup . node . defaultChild as CfnAttributeGroup ;
58- overrideLogicalId ( cfnAttributeGroup , "DefaultApplicationAttributeGroup" ) ;
59-
60- const cfnAttributeGroupAssociation = new CfnAttributeGroupAssociation ( this , "AttributeGroupAssociation" , {
61- application : application . applicationId ,
62- attributeGroup : attributeGroup . attributeGroupId ,
63- } ) ;
64- overrideLogicalId ( cfnAttributeGroupAssociation , "AppRegistryApplicationAttributeAssociation" ) ;
65-
66- const appInsights = new CfnApplication ( this , "ApplicationInsightsConfiguration" , {
67- resourceGroupName : Fn . join ( "-" , [
68- "AWS_AppRegistry_Application" ,
69- props . appRegistryApplicationName ,
70- Aws . REGION ,
71- Aws . ACCOUNT_ID ,
72- ] ) ,
73- autoConfigurationEnabled : true ,
74- cweMonitorEnabled : true ,
75- opsCenterEnabled : true ,
76- } ) ;
77- appInsights . addDependency ( cfnApplication ) ;
78- overrideLogicalId ( appInsights , "ApplicationInsightsConfiguration" ) ;
79-
80- const resourceShare = new CfnResourceShare ( this , "ApplicationShare" , {
81- name : Aws . STACK_NAME ,
82- allowExternalPrincipals : false ,
83- permissionArns : [
84- cdk . Arn . format (
85- {
86- service : "ram" ,
87- resource : "permission" ,
88- resourceName : "AWSRAMPermissionServiceCatalogAppRegistryApplicationAllowAssociation" ,
89- partition : Aws . PARTITION ,
90- region : "" ,
91- account : "aws" ,
92- } ,
93- cdk . Stack . of ( this ) ,
94- ) ,
95- ] ,
96- principals : [
97- cdk . Arn . format (
98- {
99- service : "organizations" ,
100- resource : "organization" ,
101- resourceName : `${ props . orgId } ` ,
102- partition : Aws . PARTITION ,
103- region : "" ,
104- account : props . managementAccountId ,
105- } ,
106- cdk . Stack . of ( this ) ,
107- ) ,
108- ] ,
109- resourceArns : [ application . applicationArn ] ,
110- } ) ;
111-
112- overrideLogicalId ( resourceShare , "ApplicationShare" ) ;
113- setCondition ( resourceShare , props . multiAccountDeploymentCondition ) ;
25+ application . overrideLogicalId ( "Application" ) ;
26+ this . applicationTagValue = application . attrApplicationTagValue ;
11427
11528 // Tags for application
11629
117- Tags . of ( application ) . add ( "SolutionID" , props . solutionId ) ;
118- Tags . of ( application ) . add ( "SolutionName" , props . solutionName ) ;
119- Tags . of ( application ) . add ( "SolutionVersion" , props . solutionVersion ) ;
120- Tags . of ( application ) . add ( "ApplicationType" , props . applicationType ) ;
121- Tags . of ( application ) . add ( "SolutionDomain" , props . solutionDomain ) ;
30+ Tags . of ( application ) . add ( "Solutions: SolutionID" , props . solutionId ) ;
31+ Tags . of ( application ) . add ( "Solutions: SolutionName" , props . solutionName ) ;
32+ Tags . of ( application ) . add ( "Solutions: SolutionVersion" , props . solutionVersion ) ;
33+ Tags . of ( application ) . add ( "Solutions: ApplicationType" , props . applicationType ) ;
34+ Tags . of ( application ) . add ( "Solutions: SolutionDomain" , props . solutionDomain ) ;
12235 Tags . of ( application ) . add ( "CloudFoundations:CostOptimizerForWorkspaces" , Aws . STACK_NAME ) ;
12336 }
12437}
0 commit comments