Skip to content

Commit 86494b4

Browse files
authored
fix: Deploy bucket in configured location (#227)
1 parent 0bb6cae commit 86494b4

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

package/lib/prepareDeployment.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ module.exports = {
1818
const bucket = deploymentTemplate.resources.find(findDeploymentBucket);
1919

2020
const name = this.serverless.service.provider.deploymentBucketName;
21-
const updatedBucket = updateBucketName(bucket, name);
21+
const location = this.serverless.service.provider.region;
22+
const updatedBucket = updateBucket(bucket, name, location);
2223

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

@@ -30,9 +31,13 @@ module.exports = {
3031
},
3132
};
3233

33-
const updateBucketName = (bucket, name) => {
34+
const updateBucket = (bucket, name, location) => {
3435
const newBucket = _.cloneDeep(bucket);
3536
newBucket.name = name;
37+
if (location) {
38+
if (!newBucket.properties) newBucket.properties = {};
39+
newBucket.properties.location = location;
40+
}
3641
return newBucket;
3742
};
3843

package/lib/prepareDeployment.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,28 @@ describe('PrepareDeployment', () => {
6262
);
6363
});
6464
});
65+
66+
it('should use the configured location', () => {
67+
serverless.service.provider.region = 'europe-west1';
68+
69+
const expectedCompiledConfiguration = {
70+
resources: [
71+
{
72+
type: 'storage.v1.bucket',
73+
name: 'sls-my-service-dev-12345678',
74+
properties: {
75+
location: 'europe-west1',
76+
},
77+
},
78+
],
79+
};
80+
81+
return googlePackage.prepareDeployment().then(() => {
82+
expect(readFileSyncStub.calledOnce).toEqual(true);
83+
expect(serverless.service.provider.compiledConfigurationTemplate).toEqual(
84+
expectedCompiledConfiguration
85+
);
86+
});
87+
});
6588
});
6689
});

0 commit comments

Comments
 (0)