fix(AWS Deploy): Ensure vpc configuration on custom resources (#11985)

This commit is contained in:
Lokesh Jawale 2023-05-30 12:21:57 +05:30 committed by GitHub
parent 3afb71e39d
commit f2d1e23f59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -179,6 +179,13 @@ async function addCustomResourceToService(awsProvider, resourceName, iamRoleStat
};
Resources[customResourceFunctionLogicalId] = customResourceFunction;
if (providerConfig.vpc && providerConfig.vpc.securityGroupIds && providerConfig.vpc.subnetIds) {
customResourceFunction.Properties.VpcConfig = {
SecurityGroupIds: providerConfig.vpc.securityGroupIds,
SubnetIds: providerConfig.vpc.subnetIds,
};
}
if (customDeploymentRole) {
customResourceFunction.Properties.Role = customDeploymentRole;
} else {

View File

@ -347,6 +347,33 @@ describe('#addCustomResourceToService()', () => {
Resources.CustomDashresourceDashexistingDashs3LambdaFunction.Properties.FunctionName.length
).to.be.below(65);
});
it('should configure vpc configs for the custom resource lambda function if vpc is configured', async () => {
const vpcConfig = {
securityGroupIds: ['sg-0a0a0a0a'],
subnetIds: ['subnet-01010101'],
};
const { cfTemplate } = await runServerless({
fixture: 'api-gateway',
command: 'package',
configExt: {
provider: {
logs: {
restApi: true,
},
vpc: vpcConfig,
},
},
});
const properties =
cfTemplate.Resources.CustomDashresourceDashapigwDashcwDashroleLambdaFunction.Properties;
expect(properties.VpcConfig).to.deep.equal({
SecurityGroupIds: ['sg-0a0a0a0a'],
SubnetIds: ['subnet-01010101'],
});
});
});
describe('test/unit/lib/plugins/aws/customResources/index.test.js', () => {