Skip to content

Commit 655745c

Browse files
committed
fix: ensure depenency between connectionTarget and secret update
1 parent 63279d5 commit 655745c

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

.github/workflows/build.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818
name: Build and package
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2222

23-
- uses: actions/setup-node@v3
23+
- uses: actions/setup-node@v4
2424
with:
2525
node-version: 18
2626
cache: "npm"
@@ -37,22 +37,22 @@ jobs:
3737
- name: Generate documentation
3838
run: npm run docgen
3939

40-
- uses: actions/upload-artifact@v3
40+
- uses: actions/upload-artifact@v4
4141
with:
4242
name: docs
4343
path: docs
4444

45-
- uses: actions/upload-artifact@v3
45+
- uses: actions/upload-artifact@v4
4646
with:
4747
name: python
4848
path: dist/python/*
4949

50-
- uses: actions/upload-artifact@v3
50+
- uses: actions/upload-artifact@v4
5151
with:
5252
name: js
5353
path: dist/js/*
5454

55-
- uses: actions/upload-artifact@v3
55+
- uses: actions/upload-artifact@v4
5656
with:
5757
name: jsii
5858
path: .jsii

integration_tests/cdk/app.py

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def __init__(
8585

8686
assert pgstac_db.security_group
8787

88+
# make sure we can get the secret value!
89+
assert pgstac_db.pgstac_secret.secret_value_from_json("host").to_string()
90+
8891
pgstac_db.security_group.add_ingress_rule(
8992
aws_ec2.Peer.any_ipv4(), aws_ec2.Port.tcp(5432)
9093
)

lib/database/PgBouncer.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class PgBouncer extends Construct {
7171
public readonly instance: ec2.Instance;
7272
public readonly pgbouncerSecret: secretsmanager.Secret;
7373
public readonly securityGroup: ec2.SecurityGroup;
74+
public readonly secretUpdateComplete: CustomResource;
7475

7576
// The max_connections parameter in PgBouncer determines the maximum number of
7677
// connections to open on the actual database instance. We want that number to
@@ -208,14 +209,18 @@ export class PgBouncer extends Construct {
208209
props.database.secret.grantRead(secretUpdaterFn);
209210
this.pgbouncerSecret.grantWrite(secretUpdaterFn);
210211

211-
new CustomResource(this, "pgbouncerSecretBootstrapper", {
212-
serviceToken: secretUpdaterFn.functionArn,
213-
properties: {
214-
instanceIp: props.usePublicSubnet
215-
? this.instance.instancePublicIp
216-
: this.instance.instancePrivateIp,
217-
},
218-
});
212+
this.secretUpdateComplete = new CustomResource(
213+
this,
214+
"pgbouncerSecretBootstrapper",
215+
{
216+
serviceToken: secretUpdaterFn.functionArn,
217+
properties: {
218+
instanceIp: props.usePublicSubnet
219+
? this.instance.instancePublicIp
220+
: this.instance.instancePrivateIp,
221+
},
222+
}
223+
);
219224
}
220225

221226
private loadUserDataScript(

lib/database/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,13 @@ export class PgStacDatabase extends Construct {
171171
this._pgBouncerServer.node.addDependency(bootstrapper);
172172

173173
this.pgstacSecret = this._pgBouncerServer.pgbouncerSecret;
174+
174175
this.connectionTarget = this._pgBouncerServer.instance;
176+
// ensure the secret has been updated before releasing the connectionTarget
177+
this.connectionTarget.node.addDependency(
178+
this._pgBouncerServer.secretUpdateComplete
179+
);
180+
175181
this.securityGroup = this._pgBouncerServer.securityGroup;
176182
} else {
177183
this.connectionTarget = this.db;

0 commit comments

Comments
 (0)