Skip to content

feat: add ability to not create policies #55

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 8 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ module "lacework_cfg_iam_role" {
}

resource "aws_iam_role_policy_attachment" "security_audit_policy_attachment" {
count = var.use_existing_iam_role_policy ? 0 : 1
count = var.create_policies && !var.use_existing_iam_role_policy ? 1 : 0

role = local.iam_role_name
policy_arn = "arn:aws:iam::aws:policy/SecurityAudit"
depends_on = [module.lacework_cfg_iam_role]
}

# Lacework custom configuration policy
data "aws_iam_policy_document" "lacework_audit_policy" {
count = var.use_existing_iam_role_policy ? 0 : 1
count = var.use_existing_iam_role_policy ? 0 : 1

version = "2012-10-17"

statement {
Expand All @@ -48,15 +50,17 @@ data "aws_iam_policy_document" "lacework_audit_policy" {
}

resource "aws_iam_policy" "lacework_audit_policy" {
count = var.use_existing_iam_role_policy ? 0 : 1
count = var.create_policies && !var.use_existing_iam_role_policy ? 1 : 0

name = local.lacework_audit_policy_name
description = "An audit policy to allow Lacework to read configs (extends SecurityAudit)"
policy = data.aws_iam_policy_document.lacework_audit_policy[0].json
tags = var.tags
}

resource "aws_iam_role_policy_attachment" "lacework_audit_policy_attachment" {
count = var.use_existing_iam_role_policy ? 0 : 1
count = var.create_policies && !var.use_existing_iam_role_policy ? 1 : 0

role = local.iam_role_name
policy_arn = aws_iam_policy.lacework_audit_policy[0].arn
depends_on = [module.lacework_cfg_iam_role]
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
variable "create_policies" {
type = bool
default = true
description = "Set this to false when using a role who's policy is managed outside this module"
}

variable "use_existing_iam_role" {
type = bool
Expand Down