Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Adding app registry changes. #362

Merged
merged 3 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions source/bin/aws-instance-scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const SOLUTION_ID = process.env['SOLUTION_ID'] ? process.env['SOLUTION_ID'] : "S
const SOLUTION_BUCKET = process.env['DIST_OUTPUT_BUCKET'] ? process.env['DIST_OUTPUT_BUCKET'] : "";
const SOLUTION_TMN = process.env['SOLUTION_TRADEMARKEDNAME'] ? process.env['SOLUTION_TRADEMARKEDNAME'] : "aws-instance-scheduler";
const SOLUTION_PROVIDER = 'AWS Solution Development';
const APP_REG_APPLICATION_TYPE = process.env['APP_REG_APPLICATION_TYPE'] ? process.env['APP_REG_APPLICATION_TYPE'] : 'AWS-Solutions';
gockle marked this conversation as resolved.
Show resolved Hide resolved
const APP_REG_SOLUTION_NAME = process.env['APP_REG_SOLUTION_NAME'] ? process.env['APP_REG_SOLUTION_NAME'] : "instance-scheduler-on-aws";

const app = new cdk.App();

Expand All @@ -37,7 +39,9 @@ new AwsInstanceSchedulerStack(app, 'aws-instance-scheduler', {
solutionProvider: SOLUTION_PROVIDER,
solutionBucket: SOLUTION_BUCKET,
solutionName: SOLUTION_NAME,
solutionVersion: SOLUTION_VERSION
solutionVersion: SOLUTION_VERSION,
appregApplicationName: APP_REG_APPLICATION_TYPE,
appregSolutionName: APP_REG_SOLUTION_NAME
});
new AwsInstanceSchedulerRemoteStack(app, 'aws-instance-scheduler-remote', {
synthesizer: new cdk.DefaultStackSynthesizer({
Expand All @@ -49,5 +53,7 @@ new AwsInstanceSchedulerRemoteStack(app, 'aws-instance-scheduler-remote', {
solutionProvider: SOLUTION_PROVIDER,
solutionBucket: SOLUTION_BUCKET,
solutionName: SOLUTION_NAME,
solutionVersion: SOLUTION_VERSION
solutionVersion: SOLUTION_VERSION,
appregApplicationName: APP_REG_APPLICATION_TYPE,
appregSolutionName: APP_REG_SOLUTION_NAME
});
62 changes: 62 additions & 0 deletions source/lib/app-registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import * as cdk from 'aws-cdk-lib';
import { Construct } from "constructs";
import { Aws, Stack, Tags } from 'aws-cdk-lib';
import * as appreg from '@aws-cdk/aws-servicecatalogappregistry-alpha';


export interface AppRegistryForInstanceSchedulerProps extends cdk.StackProps {
readonly solutionId: string,
readonly solutionName: string,
readonly solutionVersion: string,
readonly appregAppName: string
readonly appregSolutionName: string,
}

export class AppRegistryForInstanceScheduler extends Construct {
constructor(scope: Stack, id: string, props: AppRegistryForInstanceSchedulerProps) {
super(scope, id);

const map = new cdk.CfnMapping(this, "Solution");
map.setValue("Data", "ID", props.solutionId);
map.setValue("Data", "Version", props.solutionVersion);
map.setValue("Data", "AppRegistryApplicationName", props.appregSolutionName);
map.setValue("Data", "SolutionName", props.solutionName);
map.setValue("Data", "ApplicationType", props.appregAppName);

const application = new appreg.Application(scope, "AppRegistry", {
applicationName: cdk.Fn.join("-", [
map.findInMap("Data", "AppRegistryApplicationName"),
Aws.REGION,
Aws.ACCOUNT_ID,
Aws.STACK_NAME
]),
description: `Service Catalog application to track and manage all your resources for the solution ${map.findInMap("Data", "SolutionName")}`,
});
application.associateStack(scope);
Tags.of(application).add("Solutions:SolutionID", map.findInMap("Data", "ID"));
Tags.of(application).add("Solutions:SolutionName", map.findInMap("Data", "SolutionName"));
Tags.of(application).add("Solutions:SolutionVersion", map.findInMap("Data", "Version"));
Tags.of(application).add("Solutions:ApplicationType", map.findInMap("Data", "ApplicationType"));

const attributeGroup = new appreg.AttributeGroup(
this,
"DefaultApplicationAttributes",
{
attributeGroupName: cdk.Fn.join("-", [
Aws.REGION,
Aws.STACK_NAME
]),
description: "Attribute group for solution information",
attributes: {
applicationType: map.findInMap("Data", "ApplicationType"),
version: map.findInMap("Data", "Version"),
solutionID: map.findInMap("Data", "ID"),
solutionName: map.findInMap("Data", "SolutionName"),
},
}
);

application.associateAttributeGroup(attributeGroup);

}
}
13 changes: 12 additions & 1 deletion source/lib/aws-instance-scheduler-remote-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as cdk from 'aws-cdk-lib';
import * as iam from 'aws-cdk-lib/aws-iam';
import { ArnPrincipal, CompositePrincipal, Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
import { Construct } from "constructs";
import { AppRegistryForInstanceScheduler } from './app-registry';
gockle marked this conversation as resolved.
Show resolved Hide resolved

export interface AwsInstanceSchedulerRemoteStackProps extends cdk.StackProps {
readonly description: string,
Expand All @@ -26,7 +27,9 @@ export interface AwsInstanceSchedulerRemoteStackProps extends cdk.StackProps {
readonly solutionProvider: string,
readonly solutionBucket: string,
readonly solutionName: string,
readonly solutionVersion: string
readonly solutionVersion: string,
readonly appregApplicationName: string,
readonly appregSolutionName: string,
}

export class AwsInstanceSchedulerRemoteStack extends cdk.Stack {
Expand All @@ -42,6 +45,14 @@ export class AwsInstanceSchedulerRemoteStack extends cdk.Stack {
constraintDescription: 'Account number is a 12 digit number'
});

new AppRegistryForInstanceScheduler(this, "AppRegistryForInstanceScheduler", {
solutionId: props.solutionId,
solutionName: props.solutionName,
solutionVersion: props.solutionVersion,
appregSolutionName: props.appregSolutionName,
appregAppName: props.appregApplicationName
})

let accountPrincipal = new ArnPrincipal(cdk.Fn.sub('arn:${AWS::Partition}:iam::${accountId}:root', {
accountId: instanceSchedulerAccount.valueAsString
}));
Expand Down
14 changes: 13 additions & 1 deletion source/lib/aws-instance-scheduler-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Aws, RemovalPolicy } from 'aws-cdk-lib';
import { Construct } from "constructs";
import { LambdaFunction } from "aws-cdk-lib/aws-events-targets";
import {SUPPORTED_TIME_ZONES} from "./time-zones";
import { AppRegistryForInstanceScheduler } from './app-registry';


export interface AwsInstanceSchedulerStackProps extends cdk.StackProps {
Expand All @@ -38,7 +39,9 @@ export interface AwsInstanceSchedulerStackProps extends cdk.StackProps {
readonly solutionProvider: string,
readonly solutionBucket: string,
readonly solutionName: string,
readonly solutionVersion: string
readonly solutionVersion: string,
readonly appregApplicationName: string,
readonly appregSolutionName: string,
}

/*
Expand Down Expand Up @@ -204,6 +207,15 @@ export class AwsInstanceSchedulerStack extends cdk.Stack {

//End Mappings for instance scheduler.


new AppRegistryForInstanceScheduler(this, "AppRegistryForInstanceScheduler", {
solutionId: props.solutionId,
solutionName: props.solutionName,
solutionVersion: props.solutionVersion,
appregSolutionName: props.appregSolutionName,
appregAppName: props.appregApplicationName
})

/*
* Instance Scheduler solutions bucket reference.
*/
Expand Down
19 changes: 19 additions & 0 deletions source/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions source/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"typescript": "^4.9.4"
},
"dependencies": {
"@aws-cdk/aws-servicecatalogappregistry-alpha": "^2.39.1-alpha.0",
gockle marked this conversation as resolved.
Show resolved Hide resolved
"@aws-solutions-constructs/aws-lambda-dynamodb": "2.30.0",
"aws-cdk-lib": "2.59.0",
"constructs": "^10.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ exports[`AwsInstanceSchedulerStack snapshot test 1`] = `
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "",
"Mappings": {
"AppRegistryForInstanceSchedulerSolution25A90F05": {
"Data": {
"AppRegistryApplicationName": "instance-scheduler-on-aws",
"ApplicationType": "AWS-Solutions",
"ID": "SO0030",
"SolutionName": "aws-instance-scheduler",
"Version": "v1.5.0",
},
},
},
"Metadata": {
"AWS::CloudFormation::Interface": {
"ParameterGroups": [
Expand Down Expand Up @@ -43,6 +54,160 @@ exports[`AwsInstanceSchedulerStack snapshot test 1`] = `
},
},
"Resources": {
"AppRegistry968496A3": {
"Properties": {
"Description": {
"Fn::Join": [
"",
[
"Service Catalog application to track and manage all your resources for the solution ",
{
"Fn::FindInMap": [
"AppRegistryForInstanceSchedulerSolution25A90F05",
"Data",
"SolutionName",
],
},
],
],
},
"Name": {
"Fn::Join": [
"-",
[
{
"Fn::FindInMap": [
"AppRegistryForInstanceSchedulerSolution25A90F05",
"Data",
"AppRegistryApplicationName",
],
},
{
"Ref": "AWS::Region",
},
{
"Ref": "AWS::AccountId",
},
{
"Ref": "AWS::StackName",
},
],
],
},
"Tags": {
"Solutions:ApplicationType": {
"Fn::FindInMap": [
"AppRegistryForInstanceSchedulerSolution25A90F05",
"Data",
"ApplicationType",
],
},
"Solutions:SolutionID": {
"Fn::FindInMap": [
"AppRegistryForInstanceSchedulerSolution25A90F05",
"Data",
"ID",
],
},
"Solutions:SolutionName": {
"Fn::FindInMap": [
"AppRegistryForInstanceSchedulerSolution25A90F05",
"Data",
"SolutionName",
],
},
"Solutions:SolutionVersion": {
"Fn::FindInMap": [
"AppRegistryForInstanceSchedulerSolution25A90F05",
"Data",
"Version",
],
},
},
},
"Type": "AWS::ServiceCatalogAppRegistry::Application",
},
"AppRegistryAttributeGroupAssociation2328adb27afd49C57352": {
"Properties": {
"Application": {
"Fn::GetAtt": [
"AppRegistry968496A3",
"Id",
],
},
"AttributeGroup": {
"Fn::GetAtt": [
"AppRegistryForInstanceSchedulerDefaultApplicationAttributes78274898",
"Id",
],
},
},
"Type": "AWS::ServiceCatalogAppRegistry::AttributeGroupAssociation",
},
"AppRegistryForInstanceSchedulerDefaultApplicationAttributes78274898": {
"Properties": {
"Attributes": {
"applicationType": {
"Fn::FindInMap": [
"AppRegistryForInstanceSchedulerSolution25A90F05",
"Data",
"ApplicationType",
],
},
"solutionID": {
"Fn::FindInMap": [
"AppRegistryForInstanceSchedulerSolution25A90F05",
"Data",
"ID",
],
},
"solutionName": {
"Fn::FindInMap": [
"AppRegistryForInstanceSchedulerSolution25A90F05",
"Data",
"SolutionName",
],
},
"version": {
"Fn::FindInMap": [
"AppRegistryForInstanceSchedulerSolution25A90F05",
"Data",
"Version",
],
},
},
"Description": "Attribute group for solution information",
"Name": {
"Fn::Join": [
"-",
[
{
"Ref": "AWS::Region",
},
{
"Ref": "AWS::StackName",
},
],
],
},
},
"Type": "AWS::ServiceCatalogAppRegistry::AttributeGroup",
},
"AppRegistryResourceAssociationdf1bce20c35e43B5355E": {
"Properties": {
"Application": {
"Fn::GetAtt": [
"AppRegistry968496A3",
"Id",
],
},
"Resource": {
"Ref": "AWS::StackId",
},
"ResourceType": "CFN_STACK",
},
"Type": "AWS::ServiceCatalogAppRegistry::ResourceAssociation",
},
"EC2SchedulerCrossAccountRole": {
"Metadata": {
"cfn_nag": {
Expand Down
Loading