diff --git a/package/lib/prepareDeployment.js b/package/lib/prepareDeployment.js index d116671..2287807 100644 --- a/package/lib/prepareDeployment.js +++ b/package/lib/prepareDeployment.js @@ -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); @@ -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; }; diff --git a/package/lib/prepareDeployment.test.js b/package/lib/prepareDeployment.test.js index 64e955b..bc94353 100644 --- a/package/lib/prepareDeployment.test.js +++ b/package/lib/prepareDeployment.test.js @@ -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 + ); + }); + }); }); });