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

Handle SecretsManager dynamic references #202

Merged
merged 5 commits into from
Nov 11, 2024
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
9 changes: 9 additions & 0 deletions integration/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ func TestApiGatewayDomain(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestSecretsManager(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "secretsmanager"),
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been gofmt'd? We might be missing some liner setup in the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may have happened when I manually resolved merge conflicts in the github ui, but you are correct that we don't have any checks on this in CI.


integration.ProgramTest(t, &test)
}

func TestEc2(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Expand Down
3 changes: 3 additions & 0 deletions integration/secretsmanager/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: pulumi-aws-secretsmanager
runtime: nodejs
description: secretsmanager integration test
84 changes: 84 additions & 0 deletions integration/secretsmanager/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import * as aws from '@pulumi/aws';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as rds from 'aws-cdk-lib/aws-rds';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as secrets from 'aws-cdk-lib/aws-secretsmanager';
import * as pulumicdk from '@pulumi/cdk';
import { CfnOutput, SecretValue } from 'aws-cdk-lib';

class SecretsManagerStack extends pulumicdk.Stack {
constructor(app: pulumicdk.App, id: string, options?: pulumicdk.StackOptions) {
super(app, id, options);

const vpc = new ec2.Vpc(this, 'Vpc', {
maxAzs: 2,
ipAddresses: ec2.IpAddresses.cidr('10.0.0.0/16'),
natGateways: 0,
subnetConfiguration: [
{
name: 'Isolated',
subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
},
],
});
new rds.DatabaseInstance(this, 'Instance', {
vpc,
engine: rds.DatabaseInstanceEngine.mysql({
version: rds.MysqlEngineVersion.VER_8_0_37,
}),
vpcSubnets: vpc.selectSubnets({ subnetType: ec2.SubnetType.PRIVATE_ISOLATED }),
credentials: rds.Credentials.fromGeneratedSecret('admin'),
});

const role = new iam.Role(this, 'Role', {
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
});
const secret = new secrets.Secret(this, 'Secret', {
description: 'A test secret',
});
secret.grantRead(role);

const rotationLambda = new lambda.Function(this, 'RotationLambda', {
code: lambda.Code.fromInline('exports.handler = async function(event) { return event; }'),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_LATEST,
});
secret.addRotationSchedule('rotation', {
rotationLambda,
});
}
}

new pulumicdk.App(
'app',
(scope: pulumicdk.App) => {
new SecretsManagerStack(scope, 'teststack');
},
{
appOptions: {
remapCloudControlResource: (logicalId, typeName, props, options) => {
if (typeName === 'AWS::SecretsManager::RotationSchedule') {
if (props.HostedRotationLambda) {
throw new Error('Hosted Rotation is not supported');
}
return new aws.secretsmanager.SecretRotation(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't we add this mapping directly to pu-cdk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I forgot about this. It actually should be available as a CCAPI type, but I was getting errors so I added this and forgot to go back and investigate. I'll update it.

logicalId,
{
secretId: props.SecretId,
rotationRules: {
duration: props.RotationRules.Duration,
scheduleExpression: props.RotationRules.ScheduleExpression,
automaticallyAfterDays: props.RotationRules.AutomaticallyAfterDays,
},
rotateImmediately: props.RotateImmediatelyOnUpdate,
rotationLambdaArn: props.RotationLambdaARN,
},
options,
);
}
return undefined;
},
},
},
);
15 changes: 15 additions & 0 deletions integration/secretsmanager/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "pulumi-aws-cdk",
"devDependencies": {
"@types/node": "^10.0.0"
},
"dependencies": {
"@pulumi/aws": "^6.56.0",
"@pulumi/aws-native": "^1.5.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.149.0",
"constructs": "10.3.0",
"esbuild": "^0.24.0"
}
}
18 changes: 18 additions & 0 deletions integration/secretsmanager/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"strict": true,
"outDir": "bin",
"target": "es2019",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"./*.ts"
]
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
}
},
"resolutions": {
"@pulumi/pulumi": "3.121.0",
"@pulumi/pulumi": "3.136.0",
"wrap-ansi": "7.0.0",
"string-width": "4.1.0"
},
"devDependencies": {
"@aws-cdk/aws-apprunner-alpha": "2.20.0-alpha.0",
"@pulumi/aws": "^6.32.0",
"@pulumi/aws": "^6.56.0",
"@pulumi/aws-native": "^1.6.0",
"@pulumi/docker": "^4.5.0",
"@pulumi/pulumi": "3.121.0",
"@pulumi/pulumi": "3.136.0",
"@types/archiver": "^6.0.2",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.2",
Expand All @@ -50,10 +50,10 @@
"typescript-eslint": "^7.16.1"
},
"peerDependencies": {
"@pulumi/aws": "^6.32.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws": "^6.56.0",
"@pulumi/aws-native": "^1.6.0",
"@pulumi/docker": "^4.5.0",
"@pulumi/pulumi": "^3.117.0",
"@pulumi/pulumi": "^3.136.0",
"aws-cdk-lib": "^2.20.0",
"constructs": "^10.0.111"
},
Expand Down
Loading
Loading