Skip to content

Instantly share code, notes, and snippets.

@adamenger
Created June 8, 2023 19:22
Show Gist options
  • Save adamenger/6d09e5ab5dc0491e168b59e58cdfefb4 to your computer and use it in GitHub Desktop.
Save adamenger/6d09e5ab5dc0491e168b59e58cdfefb4 to your computer and use it in GitHub Desktop.
package spacelift
# Define the forbidden roles
forbidden_roles := {"editor", "owner"}
# Deny when creating or updating a google_project_iam_binding with forbidden roles
deny[sprintf("Resource '%s' has a forbidden role.", [resource.address])] {
# Select the resource from the input
resource := input.terraform.resource_changes[_]
# Check if the resource is a google_project_iam_binding and the action is either create or update
resource.type == "google_project_iam_binding"
resource.change.actions[_] == "create"
# Check if the role_key is in the set of forbidden roles
forbidden_roles[resource.index]
}
# Deny when creating or updating a google_project_iam_binding with forbidden roles
warn[sprintf("Resource '%s' has a forbidden role.", [resource.address])] {
# Select the resource from the input
resource := input.terraform.resource_changes[_]
# Check if the resource is a google_project_iam_binding and the action is either create or update
resource.type == "google_project_iam_binding"
resource.change.actions[_] == "update"
# Check if the role_key is in the set of forbidden roles
forbidden_roles[resource.index]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment