Skip to content

fix: Deploy bucket in configured location #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2020
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
);
});
});
});
});