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

Use CDKv2 for example #105

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions example/run_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ setup() {
keyIds="$(aws kms list-keys | jq -r '.Keys[].KeyId')"
keyArn=
while IFS= read -r keyId; do
keyDesc="$(aws kms describe-key --key-id "$keyId")"
keyManager="$(echo "$keyDesc" | jq -r .KeyMetadata.KeyManager)"
keyArn="$(echo "$keyDesc" | jq -r .KeyMetadata.Arn)"
if [[ $keyManager == "CUSTOMER" ]]; then
candidateKeyDesc="$(aws kms describe-key --key-id "$keyId")"
candidateKeyManager="$(echo "$candidateKeyDesc" | jq -r .KeyMetadata.KeyManager)"
candidateKeyArn="$(echo "$candidateKeyDesc" | jq -r .KeyMetadata.Arn)"
if [[ $candidateKeyManager == "CUSTOMER" ]]; then
keyArn="$candidateKeyArn"
break
fi
done <<< "$keyIds"
Expand Down
2 changes: 1 addition & 1 deletion example/sops-example/bin/sops-example.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import * as cdk from 'aws-cdk-lib';
import { SopsExampleStack } from '../lib/sops-example-stack';

const app = new cdk.App();
Expand Down
12 changes: 6 additions & 6 deletions example/sops-example/cdk.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"app": "npx ts-node --prefer-ts-exts bin/sops-example.ts",
"context": {
"@aws-cdk/core:enableStackNameDuplicates": "true",
"aws-cdk-lib:enableStackNameDuplicates": "true",
"aws-cdk:enableDiffNoFail": "true",
"@aws-cdk/core:stackRelativeExports": "true",
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true,
"@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true,
"@aws-cdk/aws-kms:defaultKeyPolicies": true,
"@aws-cdk/aws-s3:grantWriteWithoutAcl": true
"aws-cdk-lib:stackRelativeExports": "true",
"aws-cdk-lib/aws-ecr-assets:dockerIgnoreSupport": true,
"aws-cdk-lib/aws-secretsmanager:parseOwnedSecretName": true,
"aws-cdk-lib/aws-kms:defaultKeyPolicies": true,
"aws-cdk-lib/aws-s3:grantWriteWithoutAcl": true
}
}
21 changes: 5 additions & 16 deletions example/sops-example/lib/sops-example-stack.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as cdk from '@aws-cdk/core';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
import * as lambda from '@aws-cdk/aws-lambda';
import * as customResource from '@aws-cdk/custom-resources';
import { Construct } from 'constructs';
import * as cdk from 'aws-cdk-lib';
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';

import { SopsSecretsManager } from './sops-secretsmanager-cdk-dev/cdkv1';
import { SopsSecretsManager } from './sops-secretsmanager-cdk-dev';

export class SopsExampleStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const secret = new secretsmanager.Secret(this, 'TestSecret');
Expand All @@ -24,16 +23,6 @@ export class SopsExampleStack extends cdk.Stack {
},
});

// This section hacks the CDK's utility lambda to use Node 12,
// which uses Node 10 in cdk <1.94.0. This is no longer
// deployable as of July 30, 2021.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const providerWrapper = cdk.Stack.of(this).node.findChild('com.isotoma.cdk.custom-resources.sops-secrets-manager') as any;
const provider = providerWrapper.provider as customResource.Provider;
const lambdaFn = (provider.node.findChild('framework-onEvent') as unknown) as lambda.Function;
const cfnLambdaFn = lambdaFn.node.defaultChild as lambda.CfnFunction;
cfnLambdaFn.addPropertyOverride('Runtime', lambda.Runtime.NODEJS_12_X.toString());

new cdk.CfnOutput(this, 'TestSecretArn', {
value: secret.secretArn,
});
Expand Down
Loading