Skip to content

Commit

Permalink
fix: Deploy bucket in configured location (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnucki authored Jul 7, 2020
1 parent 0bb6cae commit 86494b4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
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
);
});
});
});
});

0 comments on commit 86494b4

Please sign in to comment.