Skip to content

Commit

Permalink
Fixed Liniting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
EC2 Default User committed Dec 21, 2023
1 parent dafb9ed commit f13e653
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 296 deletions.
1 change: 0 additions & 1 deletion cdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"resilience-backup-restore-aws.pattern.name": "resilience_backup_restore_aws",
"resilience-backup-restore-aws.primary.region": "us-west-1",
"resilience-backup-restore-aws.dr.region": "us-east-2",
"resilience-backup-restore-aws.kubernetes.version": "eks.KubernetesVersion.V1_27",
"resilience-backup-restore-aws.efs.fsname": "efs-test-backup",
"resilience-backup-restore-aws.backup.vaultname": "eks-vault-backup"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ cat << EOF > cdk.json
"resilience-backup-restore-aws.pattern.name": "resilience_backup_restore_aws",
"resilience-backup-restore-aws.primary.region": "us-west-1",
"resilience-backup-restore-aws.dr.region": "us-east-2",
"resilience-backup-restore-aws.kubernetes.version": "eks.KubernetesVersion.V1_27",
"resilience-backup-restore-aws.efs.fsname": "efs-test",
"resilience-backup-restore-aws.backup.vaultname": "eks-vault"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ cat << EOF > cdk.json
"resilience-backup-restore-aws.pattern.name": "resilience_backup_restore_aws",
"resilience-backup-restore-aws.primary.region": "us-west-1",
"resilience-backup-restore-aws.dr.region": "us-east-2",
"resilience-backup-restore-aws.kubernetes.version": "eks.KubernetesVersion.V1_27",
"resilience-backup-restore-aws.efs.fsname": "efs-test",
"resilience-backup-restore-aws.backup.vaultname": "eks-vault"
}
Expand Down
50 changes: 22 additions & 28 deletions lib/resilience/backup_restore/backup/aws/backupstack.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
//import { NestedStack, Stack, NestedStackProps } from 'aws-cdk-lib';
import 'source-map-support/register';
//import * as eks from 'aws-cdk-lib/aws-eks';
import * as blueprints from '@aws-quickstart/eks-blueprints';
//import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as backup from 'aws-cdk-lib/aws-backup';
import { Duration } from 'aws-cdk-lib';
import * as kms from 'aws-cdk-lib/aws-kms';
//import * as iam from 'aws-cdk-lib/aws-iam';
import * as events from 'aws-cdk-lib/aws-events';
import * as utils from "@aws-quickstart/eks-blueprints/dist/utils";
//import { drstack } from './drstack';


export interface backupStackProps extends cdk.StackProps {
Expand All @@ -29,7 +23,7 @@ export class backupstack extends cdk.Stack {
//const drregion = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.dr.region", undefined);
//const kversion = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.kubernetes.version", undefined);
const efsfsname = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.efs.fsname", "efs-file-system");
const efsfstag = 'eks-blueprint/' + efsfsname
const efsfstag = 'eks-blueprint/' + efsfsname;
const vaultname = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.backup.vaultname", "EKSBackupVault");
const primaryKeyArn = props.primaryKeyArn;
const drbackupVault = props.drbackupVault;
Expand All @@ -39,25 +33,25 @@ export class backupstack extends cdk.Stack {
const backupVault = new backup.BackupVault(backupstack, 'BackupVault', {backupVaultName: vaultname, encryptionKey: primaryKey });


// Create a AWS Backup Backup plan to backup resources based on Tags
const backupPlan = new backup.BackupPlan(backupstack, 'BackupPlan', {backupPlanName: 'EKSBackupPlan', backupVault: backupVault });
backupPlan.addRule(new backup.BackupPlanRule({
copyActions: [{
destinationBackupVault: drbackupVault,
moveToColdStorageAfter: Duration.days(30),
deleteAfter: Duration.days(120),
}],
scheduleExpression: events.Schedule.cron({ // Only cron expressions are supported
day: '*',
hour: '3',
minute: '30',
}),
}));
backupPlan.addSelection('EKSResources', {
resources: [
backup.BackupResource.fromTag('EKSPVBackup', 'true'),
backup.BackupResource.fromTag('Name', efsfstag )
]
})
}
// Create a AWS Backup Backup plan to backup resources based on Tags
const backupPlan = new backup.BackupPlan(backupstack, 'BackupPlan', {backupPlanName: 'EKSBackupPlan', backupVault: backupVault });
backupPlan.addRule(new backup.BackupPlanRule({
copyActions: [{
destinationBackupVault: drbackupVault,
moveToColdStorageAfter: Duration.days(30),
deleteAfter: Duration.days(120),
}],
scheduleExpression: events.Schedule.cron({ // Only cron expressions are supported
day: '*',
hour: '3',
minute: '30',
}),
}));
backupPlan.addSelection('EKSResources', {
resources: [
backup.BackupResource.fromTag('EKSPVBackup', 'true'),
backup.BackupResource.fromTag('Name', efsfstag )
]
});
}
}
68 changes: 29 additions & 39 deletions lib/resilience/backup_restore/backup/aws/drstack.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
//import { NestedStack, Stack, NestedStackProps } from 'aws-cdk-lib';
import 'source-map-support/register';
//import * as eks from 'aws-cdk-lib/aws-eks';
import * as blueprints from '@aws-quickstart/eks-blueprints';
//import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as backup from 'aws-cdk-lib/aws-backup';
//import { Duration } from 'aws-cdk-lib';
import * as kms from 'aws-cdk-lib/aws-kms';
import * as iam from 'aws-cdk-lib/aws-iam';
//import * as events from 'aws-cdk-lib/aws-events';
//import * as utils from "@aws-quickstart/eks-blueprints/dist/utils";
import { backupstack } from './backupstack';

/**
Expand All @@ -24,41 +18,37 @@ export interface drstackProps extends cdk.StackProps {
}

export class drstack extends cdk.Stack {
constructor(scope: Construct, id: string, props: drstackProps) {
super(scope, id, props );
constructor(scope: Construct, id: string, props: drstackProps) {
super(scope, id, props );

//const app = new cdk.App();
const account = process.env.CDK_DEFAULT_ACCOUNT!;
const region = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.primary.region", undefined);
const drregion = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.dr.region", undefined);
//const kversion = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.kubernetes.version", undefined);
const efsfsname = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.efs.fsname", "efs-file-system");
//const efsfstag = 'eks-blueprint/' + efsfsname
const vaultname = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.backup.vaultname", "EKSBackupVault");
//const keyPolicy = props.keyPolicy;
const primaryKeyArn = props.primaryKeyArn;
//const app = new cdk.App();
const account = process.env.CDK_DEFAULT_ACCOUNT!;
const region = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.primary.region", undefined);
const drregion = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.dr.region", undefined);
const vaultname = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.backup.vaultname", "EKSBackupVault");
const primaryKeyArn = props.primaryKeyArn;

const keyPolicy = new iam.PolicyDocument({
statements: [new iam.PolicyStatement({
actions: [
'kms:*',
],
principals: [new iam.AccountRootPrincipal()],
resources: ['*'],
})],
});
const keyPolicy = new iam.PolicyDocument({
statements: [new iam.PolicyStatement({
actions: [
'kms:*',
],
principals: [new iam.AccountRootPrincipal()],
resources: ['*'],
})],
});

// Create a AWS Backup Vault in Disaster Recovery Region
const drstack = new cdk.Stack(this, 'drstack', { env: { region: drregion, account: account }, crossRegionReferences: true } );
const cfnReplicaKey = new kms.CfnReplicaKey(drstack, 'KMSKey', {
keyPolicy: keyPolicy,
primaryKeyArn: primaryKeyArn
})
const replicaKey = kms.Key.fromKeyArn(drstack, 'ReplicaKey', cfnReplicaKey.attrArn);
const drbackupVault = new backup.BackupVault(drstack, 'BackupVault', {backupVaultName: vaultname , encryptionKey: replicaKey });
// Create a AWS Backup Vault in Disaster Recovery Region
const drstack = new cdk.Stack(this, 'drstack', { env: { region: drregion, account: account }, crossRegionReferences: true } );
const cfnReplicaKey = new kms.CfnReplicaKey(drstack, 'KMSKey', {
keyPolicy: keyPolicy,
primaryKeyArn: primaryKeyArn
});
const replicaKey = kms.Key.fromKeyArn(drstack, 'ReplicaKey', cfnReplicaKey.attrArn);
const drbackupVault = new backup.BackupVault(drstack, 'BackupVault', {backupVaultName: vaultname , encryptionKey: replicaKey });


const backupStackProps = {
const backupStackProps = {
primaryKeyArn: props.primaryKeyArn,
//drbackupVault: { "backupVaultArn": drbackupVault.attrArn, backupVaultName: drbackupVault.attrName, env: {"account": process.env.CDK_DEFAULT_ACCOUNT! , region: drregion}}
drbackupVault: drbackupVault,
Expand All @@ -68,10 +58,10 @@ export class drstack extends cdk.Stack {
}
};

new backupstack(this, 'backupstack', backupStackProps )
//backupstack.addDependency(drstack);
new backupstack(this, 'backupstack', backupStackProps );
//backupstack.addDependency(drstack);

}
}
}


Expand Down
156 changes: 76 additions & 80 deletions lib/resilience/backup_restore/backup/aws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,109 +10,105 @@ import { drstack } from './drstack';


export default class ResilienceBRAWSConstruct {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {

Check warning on line 13 in lib/resilience/backup_restore/backup/aws/index.ts

View workflow job for this annotation

GitHub Actions / build (18)

'id' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 13 in lib/resilience/backup_restore/backup/aws/index.ts

View workflow job for this annotation

GitHub Actions / build (18)

'props' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 13 in lib/resilience/backup_restore/backup/aws/index.ts

View workflow job for this annotation

GitHub Actions / build (18)

'id' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 13 in lib/resilience/backup_restore/backup/aws/index.ts

View workflow job for this annotation

GitHub Actions / build (18)

'props' is defined but never used. Allowed unused args must match /^_/u

const app = new cdk.App();
const account = process.env.CDK_DEFAULT_ACCOUNT!;
const region = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.primary.region", undefined);
const drregion = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.dr.region", undefined);
const kversion = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.kubernetes.version", undefined);
const efsfsname = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.efs.fsname", "efs-file-system");
const efsfstag = 'eks-blueprint/' + efsfsname
const vaultname = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.backup.vaultname", "EKSBackupVault");
const app = new cdk.App();
const account = process.env.CDK_DEFAULT_ACCOUNT!;
const region = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.primary.region", undefined);
const drregion = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.dr.region", undefined);
const efsfsname = blueprints.utils.valueFromContext(scope, "resilience-backup-restore-aws.efs.fsname", "efs-file-system");


const bootstrapRepo: blueprints.ApplicationRepository = {
repoUrl: 'https://github.com/aws-samples/eks-blueprints-workloads'
};

const bootstrapRepo: blueprints.ApplicationRepository = {
repoUrl: 'https://github.com/aws-samples/eks-blueprints-workloads'
}

const addOns: Array<blueprints.ClusterAddOn> = [
new blueprints.addons.EbsCsiDriverAddOn(),
new blueprints.addons.EfsCsiDriverAddOn(),
new blueprints.addons.VpcCniAddOn(),
new blueprints.addons.CoreDnsAddOn(),
new blueprints.addons.KubeProxyAddOn(),
new blueprints.addons.AwsLoadBalancerControllerAddOn(),
new blueprints.addons.ArgoCDAddOn({
const addOns: Array<blueprints.ClusterAddOn> = [
new blueprints.addons.EbsCsiDriverAddOn(),
new blueprints.addons.EfsCsiDriverAddOn(),
new blueprints.addons.VpcCniAddOn(),
new blueprints.addons.CoreDnsAddOn(),
new blueprints.addons.KubeProxyAddOn(),
new blueprints.addons.AwsLoadBalancerControllerAddOn(),
new blueprints.addons.ArgoCDAddOn({
bootstrapRepo: {
...bootstrapRepo,
path: './teams/team-rbraws/Primary/manifests/StorageClass',
},})
];
},})
];

const clusterProvider = new blueprints.GenericClusterProvider({
version: eks.KubernetesVersion.V1_27,
tags: {
"Name": "backup-example-cluster",
"Type": "generic-cluster"
},
managedNodeGroups: [
{
id: "mng1",
amiType: eks.NodegroupAmiType.AL2_X86_64,
instanceTypes: [new ec2.InstanceType('m5.2xlarge')],
desiredSize: 2,
enableSsmPermissions: true,
maxSize: 3,
nodeGroupSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS },
launchTemplate: {
// You can pass Custom Tags to Launch Templates which gets propagated to worker nodes.
tags: {
"EKSPVBackup": "true",
"Type": "Managed-Node-Group",
"Instance": "ONDEMAND"
const clusterProvider = new blueprints.GenericClusterProvider({
version: eks.KubernetesVersion.V1_27,
tags: {
"Name": "backup-example-cluster",
"Type": "generic-cluster"
},
managedNodeGroups: [
{
id: "mng1",
amiType: eks.NodegroupAmiType.AL2_X86_64,
instanceTypes: [new ec2.InstanceType('m5.2xlarge')],
desiredSize: 2,
enableSsmPermissions: true,
maxSize: 3,
nodeGroupSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS },
launchTemplate: {
// You can pass Custom Tags to Launch Templates which gets propagated to worker nodes.
tags: {
"EKSPVBackup": "true",
"Type": "Managed-Node-Group",
"Instance": "ONDEMAND"
}
}
}
}
}

]
});
]
});

const stack = blueprints.EksBlueprint.builder()
.resourceProvider(blueprints.GlobalResources.Vpc, new blueprints.VpcProvider())
.resourceProvider("efs-file-system", new blueprints.CreateEfsFileSystemProvider({name: efsfsname }))
.account(account)
.clusterProvider(clusterProvider)
.region(region)
.addOns(...addOns)
.build(app, 'eks-blueprint');
const stack = blueprints.EksBlueprint.builder()
.resourceProvider(blueprints.GlobalResources.Vpc, new blueprints.VpcProvider())
.resourceProvider("efs-file-system", new blueprints.CreateEfsFileSystemProvider({name: efsfsname }))
.account(account)
.clusterProvider(clusterProvider)
.region(region)
.addOns(...addOns)
.build(app, 'eks-blueprint');



// Create a Multi-region KMS key using CfnKey
const keyPolicy = new iam.PolicyDocument({
statements: [new iam.PolicyStatement({
actions: [
'kms:*',
],
principals: [new iam.AccountRootPrincipal()],
resources: ['*'],
})],
});
// Create a Multi-region KMS key using CfnKey
const keyPolicy = new iam.PolicyDocument({
statements: [new iam.PolicyStatement({
actions: [
'kms:*',
],
principals: [new iam.AccountRootPrincipal()],
resources: ['*'],
})],
});

const kmsKey = new kms.CfnKey(stack, 'KMSKey', {
keyPolicy: keyPolicy,
enableKeyRotation: true,
multiRegion: true,
enabled: true,
pendingWindowInDays: 30
});
const kmsKey = new kms.CfnKey(stack, 'KMSKey', {
keyPolicy: keyPolicy,
enableKeyRotation: true,
multiRegion: true,
enabled: true,
pendingWindowInDays: 30
});

const kmsAlias = new kms.CfnAlias(stack, 'KMSAlias', {
aliasName: 'alias/eks-blueprint',
targetKeyId: kmsKey.attrKeyId,
});
const kmsAlias = new kms.CfnAlias(stack, 'KMSAlias', {

Check warning on line 98 in lib/resilience/backup_restore/backup/aws/index.ts

View workflow job for this annotation

GitHub Actions / build (18)

'kmsAlias' is assigned a value but never used

Check warning on line 98 in lib/resilience/backup_restore/backup/aws/index.ts

View workflow job for this annotation

GitHub Actions / build (18)

'kmsAlias' is assigned a value but never used
aliasName: 'alias/eks-blueprint',
targetKeyId: kmsKey.attrKeyId,
});


const drstackProps = {
const drstackProps = {
primaryKeyArn: kmsKey.attrArn,
env: {
account: process.env.CDK_DEFAULT_ACCOUNT!,
region: drregion
}
};

new drstack(stack, 'drstack', drstackProps)
}
new drstack(stack, 'drstack', drstackProps);
}
}
Loading

0 comments on commit f13e653

Please sign in to comment.