Skip to content

Commit e6775e9

Browse files
authored
Merge pull request #148 from proactiveops/iam-improvements
Add IAM options
2 parents 2a3470d + 673a121 commit e6775e9

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ The configuration file has the following structure:
2424

2525
```toml
2626
bundle="/path/containing/code/to/bundle/into/build" # default is none
27+
iam_role_prefix="my-prefix-" # default is "pf-" for PicoFun
2728
layers="arn:aws:lambda:us-east-1:012345678910:layer:example:1,arn:aws:lambda:us-east-1:012345678910:layer:another-example:123" # default is none
2829
output_dir="/path/to/write/output-files" # default is current-working-directory/output
2930
postprocessor="fully.qualified.reference.to.postprocessor" # default is none
3031
preprocessor="fully.qualified.reference.to.preprocessor" # default is none
32+
role_permissions_boundary="arn:aws:iam::012345678910:policy/..." # default is none
3133
subnets="subnet-1234567890abcdef0,subnet-234567890abcdef01" # default is none and VPC networking is no enabled
3234
tags=... # default is none
3335
template_path="/path/to/templates" # default is current-working-directory/templates

picofun/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ class Config:
1515
_attrs: typing.ClassVar[dict[str : typing.Any]] = {
1616
"_config_file": str,
1717
"bundle": str,
18+
"iam_role_prefix": str,
1819
"layers": list,
1920
"output_dir": str,
2021
"postprocessor": str,
2122
"preprocessor": str,
23+
"role_permissions_boundary": str,
2224
"subnets": list,
2325
"tags": dict,
2426
"template_path": str,
@@ -147,10 +149,12 @@ def set_defaults(self) -> None:
147149
defaults = {
148150
"_config_file": "",
149151
"bundle": None,
152+
"iam_role_prefix": "pf-",
150153
"layers": [],
151154
"output_dir": os.path.realpath(os.path.join(os.getcwd(), "output")),
152155
"postprocessor": "",
153156
"preprocessor": "",
157+
"role_permissions_boundary": None,
154158
"subnets": [],
155159
"tags": {},
156160
"template_path": os.path.join(files("picofun"), "templates"),

picofun/templates/main.tf.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ resource "aws_lambda_function" "this" {
122122
}
123123

124124
resource "aws_iam_role" "lambda" {
125-
name = "pf-{{ namespace }}"
125+
name = "{{ iam_role_prefix }}{{ namespace }}"
126126

127127
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json
128+
permissions_boundary = {{ '"{}"'.format(role_permissions_boundary) if role_permissions_boundary else "null" }}
128129

129130
tags = local.tags
130131
}

picofun/terraform_generator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ def generate(
3333
template = self._template.get("main.tf.j2")
3434

3535
terraform_content = template.render(
36-
namespace=self._namespace,
36+
bundle=self._config.bundle,
37+
iam_role_prefix=self._config.iam_role_prefix,
3738
lambdas=lambdas,
3839
layers=self._config.layers,
39-
bundle=self._config.bundle,
40+
namespace=self._namespace,
41+
role_permissions_boundary=self._config.role_permissions_boundary,
4042
subnets=self._config.subnets,
4143
tags=self._config.tags,
4244
)

0 commit comments

Comments
 (0)