I am currently working on setting up an S3 bucket and a corresponding S3 policy using Pulumi with TypeScript. However, during the pipeline execution, I encountered the following error in the test stage:
expect(received).toEqual(expected) // deep equality
- Expected - 2
+ Received + 2
@@ -8,12 +8,12 @@
},
},
"Effect": "Deny",
"Principal": "*",
"Resource": Array [
- "app-testsupun-buyapp-bucket-arn",
- "app-testsupun-buyapp-bucket-arn/*",
+ null,
+ "undefined/*",
],
},
],
"Version": "2012-10-17",
}
137 | Statement: [
138 | {
> 139 | Effect: 'Deny',
| ^
140 | Principal: '*',
141 | Action: 's3:*',
142 | Resource: ['app-testsupun-buyapp-bucket-arn', 'app-testsupun-buyapp-bucket-arn/*'],
at infra/resource.unit.ts:139:32
at node_modules/@pulumi/output.ts:440:31
at node_modules/@pulumi/pulumi/output.js:21:71
at Object.<anonymous>.__awaiter (node_modules/@pulumi/pulumi/output.js:17:12)
at applyHelperAsync (node_modules/@pulumi/pulumi/output.js:257:12)
at node_modules/@pulumi/output.ts:352:13
This indicates that null and undefined values are being received for the Resource argument. Below is the code snippet I used to create the S3 bucket and the S3 policy:
const appS3 = new s3Bucket.S3Resource('app-testsupun-buyapp-bucket', {
bucketArgOpts: {
args: {
bucket: 'app-testsupun-buyapp-bucket',
tags: {
application: 'app',
},
},
},
});
const appS3Policy = new aws.s3.BucketPolicy(
'default-testsupun-policy',
{
bucket: appS3.bucket.bucket,
policy: {
Version: '2012-10-17',
Statement: [
{
Effect: 'Deny',
Principal: '*',
Action: 's3:*',
Resource: [
/* pulumi.output(appS3.bucket.bucket).apply(() => `arn:aws:s3:::${bucketname}/*`), */
appS3.bucket.arn,
pulumi.interpolate`${appS3.bucket.arn}/*`,
],
Condition: {
Bool: {
'aws:SecureTransport': 'false',
},
},
},
],
},
},
{
dependsOn: [appS3],
},
);