Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 7 additions & 2 deletions package/lib/prepareDeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = {
const bucket = deploymentTemplate.resources.find(findDeploymentBucket);

const name = this.serverless.service.provider.deploymentBucketName;
const updatedBucket = updateBucketName(bucket, name);
const location = this.serverless.service.provider.region;
const updatedBucket = updateBucket(bucket, name, location);

const bucketIndex = deploymentTemplate.resources.findIndex(findDeploymentBucket);

Expand All @@ -30,9 +31,13 @@ module.exports = {
},
};

const updateBucketName = (bucket, name) => {
const updateBucket = (bucket, name, location) => {
const newBucket = _.cloneDeep(bucket);
newBucket.name = name;
if (location) {
newBucket.properties = newBucket.properties || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's write it as if (!newBucket.properties) newBucket.properties = {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improvement done.

Of course, I tested it ;)

newBucket.properties.location = location;
}
return newBucket;
};

Expand Down
23 changes: 23 additions & 0 deletions package/lib/prepareDeployment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,28 @@ describe('PrepareDeployment', () => {
);
});
});

it('should use the configured location', () => {
serverless.service.provider.region = 'europe-west1';

const expectedCompiledConfiguration = {
resources: [
{
type: 'storage.v1.bucket',
name: 'sls-my-service-dev-12345678',
properties: {
location: 'europe-west1',
},
},
],
};

return googlePackage.prepareDeployment().then(() => {
expect(readFileSyncStub.calledOnce).toEqual(true);
expect(serverless.service.provider.compiledConfigurationTemplate).toEqual(
expectedCompiledConfiguration
);
});
});
});
});