Skip to content

Commit a3b22bb

Browse files
authored
Merge pull request #29 from SPHTech-Platform/feature/deployer-permission
Deployer Lambda additional permission feature
2 parents 9b62739 + fafd62a commit a3b22bb

File tree

7 files changed

+52
-4
lines changed

7 files changed

+52
-4
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- BEGIN_TF_DOCS -->
12
## Requirements
23

34
| Name | Version |
@@ -11,7 +12,7 @@
1112
| Name | Version |
1213
|------|---------|
1314
| <a name="provider_archive"></a> [archive](#provider\_archive) | 2.3.0 |
14-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.37.0 |
15+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.36.0 |
1516

1617
## Modules
1718

@@ -33,7 +34,9 @@
3334
| [aws_iam_openid_connect_provider.github](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_openid_connect_provider) | data source |
3435
| [aws_iam_policy_document.sign_code](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
3536
| [aws_iam_policy_document.update_lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
37+
| [aws_iam_policy_document.update_lambda_combined](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
3638
| [aws_iam_policy_document.update_lambda_edge](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
39+
| [aws_iam_policy_document.update_lambda_edge_combined](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
3740
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
3841

3942
## Inputs
@@ -64,6 +67,8 @@
6467
| <a name="input_create_unqualified_alias_lambda_function_url"></a> [create\_unqualified\_alias\_lambda\_function\_url](#input\_create\_unqualified\_alias\_lambda\_function\_url) | Whether to use unqualified alias pointing to $LATEST version in Lambda Function URL | `bool` | `true` | no |
6568
| <a name="input_dead_letter_target_arn"></a> [dead\_letter\_target\_arn](#input\_dead\_letter\_target\_arn) | The ARN of an SNS topic or SQS queue to notify when an invocation fails. | `string` | `null` | no |
6669
| <a name="input_default_conditions"></a> [default\_conditions](#input\_default\_conditions) | (Optional) Default condtions to apply, at least one of the following is madatory: 'allow\_main', 'allow\_environment', 'deny\_pull\_request' and 'allow\_all'. | `list(string)` | <pre>[<br> "allow_main",<br> "allow_environment"<br>]</pre> | no |
70+
| <a name="input_deployer_lambda_additional_permission"></a> [deployer\_lambda\_additional\_permission](#input\_deployer\_lambda\_additional\_permission) | Additional permission needed by lambda deployer in json format | `string` | `null` | no |
71+
| <a name="input_deployer_lambda_edge_additional_permission"></a> [deployer\_lambda\_edge\_additional\_permission](#input\_deployer\_lambda\_edge\_additional\_permission) | Additional permission needed by lambda edge deployer in json format | `string` | `null` | no |
6772
| <a name="input_description"></a> [description](#input\_description) | Lambda Function Description | `string` | `""` | no |
6873
| <a name="input_environment_variables"></a> [environment\_variables](#input\_environment\_variables) | A map that defines environment variables for the Lambda Function. | `map(string)` | `{}` | no |
6974
| <a name="input_ephemeral_storage_size"></a> [ephemeral\_storage\_size](#input\_ephemeral\_storage\_size) | Amount of ephemeral storage (/tmp) in MB your Lambda Function can use at runtime. Valid value between 512 MB to 10,240 MB (10 GB). | `number` | `512` | no |
@@ -123,3 +128,4 @@
123128
| <a name="output_lambda_role_name"></a> [lambda\_role\_name](#output\_lambda\_role\_name) | The name of the IAM role created for the Lambda Function |
124129
| <a name="output_lambda_role_unique_id"></a> [lambda\_role\_unique\_id](#output\_lambda\_role\_unique\_id) | The unique id of the IAM role created for the Lambda Function |
125130
| <a name="output_qualified_arn"></a> [qualified\_arn](#output\_qualified\_arn) | The qualified arn of the lambda function to be associated with Cloudfront as a Lambda@Edge function |
131+
<!-- END_TF_DOCS -->

data.tf

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ data "aws_iam_policy_document" "update_lambda" {
3333
}
3434
}
3535

36+
data "aws_iam_policy_document" "update_lambda_combined" {
37+
source_policy_documents = compact([
38+
data.aws_iam_policy_document.update_lambda.json,
39+
var.deployer_lambda_additional_permission
40+
])
41+
}
42+
3643
data "aws_iam_policy_document" "update_lambda_edge" {
3744
statement {
3845
sid = "EnableCFReplication"
@@ -67,6 +74,13 @@ data "aws_iam_policy_document" "update_lambda_edge" {
6774
}
6875
}
6976

77+
data "aws_iam_policy_document" "update_lambda_edge_combined" {
78+
source_policy_documents = compact([
79+
data.aws_iam_policy_document.update_lambda_edge.json,
80+
var.deployer_lambda_edge_additional_permission
81+
])
82+
}
83+
7084
data "aws_iam_policy_document" "sign_code" {
7185
#checkov:skip=CKV_AWS_356:Ensure no IAM policies documents allow "*" as a statement's resource for restrictable actions
7286
count = var.create_github_actions_signed_code_role ? 1 : 0

examples/lambda-with-apigateway/data.tf

+14
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,17 @@ data "aws_security_groups" "lambda" {
2222
values = ["SG-EC2-Web&App"]
2323
}
2424
}
25+
26+
data "aws_iam_policy_document" "access_s3" {
27+
statement {
28+
sid = "LambdaAccessS3"
29+
actions = [
30+
"s3:ListBucket",
31+
"s3:GetObject"
32+
]
33+
resources = [
34+
"arn:aws:s3:::example-bucket-s3",
35+
"arn:aws:s3:::example-bucket-s3/*"
36+
]
37+
}
38+
}

examples/lambda-with-apigateway/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module "home_feed" {
1919
"ENV" = "dev"
2020
}
2121

22+
deployer_lambda_additional_permission = data.aws_iam_policy_document.access_s3.json
23+
2224
vpc_subnet_ids = data.aws_subnets.lambda.ids
2325
vpc_security_group_ids = data.aws_security_groups.lambda.ids
2426
attach_network_policy = true

examples/lambda-with-apigateway/versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = "~> 4.23"
7+
version = ">= 4.23"
88
}
99
}
1010
}

github_action.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ resource "aws_iam_role_policy" "update_lambda" {
3737

3838
name_prefix = "UpdateLambda"
3939
role = module.lambda_gha[0].role.name
40-
policy = data.aws_iam_policy_document.update_lambda.json
40+
policy = data.aws_iam_policy_document.update_lambda_combined.json
4141
}
4242

4343
resource "aws_iam_role_policy" "update_lambda_edge" {
4444
count = var.create_github_actions_edge_role ? 1 : 0
4545

4646
name_prefix = "UpdateLambdaEdge"
4747
role = module.lambda_gha[0].role.name
48-
policy = data.aws_iam_policy_document.update_lambda_edge.json
48+
policy = data.aws_iam_policy_document.update_lambda_edge_combined.json
4949
}
5050

5151
resource "aws_iam_role_policy" "sign_code" {

variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ variable "default_conditions" {
6868
default = ["allow_main", "allow_environment"]
6969
}
7070

71+
variable "deployer_lambda_additional_permission" {
72+
description = "Additional permission needed by lambda deployer in json format"
73+
type = string
74+
default = null
75+
}
76+
77+
variable "deployer_lambda_edge_additional_permission" {
78+
description = "Additional permission needed by lambda edge deployer in json format"
79+
type = string
80+
default = null
81+
}
82+
7183
# Refer https://github.com/terraform-aws-modules/terraform-aws-lambda/blob/master/variables.tf for additional vars
7284
##################
7385
# Lambda Function

0 commit comments

Comments
 (0)