-
Notifications
You must be signed in to change notification settings - Fork 64
VPC support for the Lambda function #10
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
VPC support for the Lambda function #10
Conversation
When your Elasticsearch is running inside your VPC, you also need to run your Lambda function inside your VPC. This is the groundwork to make it possible. We need to do the following: - Create securitygroup for Lambda + open ports both on Lambda and Elasticsearch side - Extend IAM role to allow VPC execution - Add the variables subnet_ids and the elasticsearch securitygroup
|
Hi @MattiasGees thanks again for your PR, I did a simplification on Security Group in order to avoid circular dependency between modules |
|
@giuliocalzolari Reason I like to split up security_group and security_group_rule is that it is easier to add rules afterwards from other places if needed. Circular dependency issues shouldn't be a real problem here. I also went for the security group to security group approach instead of the 0.0.0.0 is of security reasons. I always try to limit the attack vectors. IAM is indeed correct and I forgot about it. |
|
@MattiasGees understood your point about security. just added some Quick example: |
|
@giuliocalzolari the compatibility was working without the if conditions. I explicitly tested this see #10 (comment) When you don't fill in subnet_ids, the vpc_config block inside the lambda is both times an empty list and the lambda will be created outside of the VPC (same as the original behaviour from before my PR). This is also explained in https://www.terraform.io/docs/providers/aws/r/lambda_function.html#vpc_config I think there is now a lot of code duplication that is not needed. |
|
@giuliocalzolari what do you think? |
|
Hi @MattiasGees I'm testing all use case. Can you tell me which terraform version are you using and which Aws provider version are you using? |
|
Terraform v0.11.3 |
|
Hi @MattiasGees it means I use the same version of you. keep in mind with this configuration we can create a function inside or outside the vpc using the same module |
|
@giuliocalzolari This is really weird. I just tested my PR an in there it works. Steps I took main.tf You can see I took my commit of the pr + left out the subnet id and the elasticsearch security group. terraform init terraform apply I then looked at the lambda function and there it shows the lambda function without VPC I don't know which commit you tested or with which code, but with my example you should be able to reproduce it. This is all tested with this commit skyscrapers@3df5e9c |
|
Hi @MattiasGees the problem appear only on the second execution second execution this is the reason why I was forced to write more code if multiple thanks for your support |

When your Elasticsearch is running inside your VPC, you also need to run your Lambda function inside your VPC. This is the groundwork to make it possible.
We need to do the following:
When subnet_ids and elasticsearch_sg_id are empty it will create the lambda without VPC support. These changes are backwards compatible and will not break previous behaviour.
I tested this change the following ways
Without VPC
With VPC support
Plan of without shows this
After deploy I checked the Lambda function
