Skip to content

Instantly share code, notes, and snippets.

@myoung34
Created April 24, 2020 19:05
Show Gist options
  • Save myoung34/b268b80ea221eb82de438009e63eef6b to your computer and use it in GitHub Desktop.
Save myoung34/b268b80ea221eb82de438009e63eef6b to your computer and use it in GitHub Desktop.
package main
import input as tfplan
resource_types = {"aws_db_instance"}
minimum_tags = min_updated_tags {
some resource_type
min_updated_tags := updated_tags[resource_type]
}
contains(arr, i) {
arr[_] = i
}
tags_contain_proper_keys(tags) = true {
contains(tags, "environment")
contains(tags, "managed_by")
contains(tags, "team")
} else = false { true }
updated_tags[resource_type] = num {
some resource_type
resource_types[resource_type]
all := resources[resource_type]
update_resources := [res | res:= all[_]; res.change.actions[_] == "update"]
tag_changeset := [res | res := [key | update_resources[_].change.after.tags[key]]]
num := tags_contain_proper_keys(tag_changeset[_])
}
resources[resource_type] = all {
some resource_type
resource_types[resource_type]
all := [name |
name:= tfplan.resource_changes[_]
name.type == resource_type
]
}
deny["(policy/rds_update.rego) Minimum RDS Tags not set. Must include: [\"managed_by\", \"environment\", \"team\"]"] {
minimum_tags == false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment