Skip to content
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: 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) {
if (!newBucket.properties) newBucket.properties = {};
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
);
});
});
});
});