Last active
April 24, 2020 18:29
-
-
Save myoung34/9674102f2443d1350761e5025e28e90e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package terraform.analysis | |
import input as tfplan | |
resource_types = {"aws_db_instance"} | |
minimum_tags = min_tags { | |
some resource_type | |
#min_created_tags := created_tags[resource_type] | |
min_modified_tags := modified_tags[resource_type] | |
min_tags:= min_modified_tags | |
} | |
contains(arr, i) { | |
arr[_] = i | |
} | |
tags_contain_proper_keys(tags) = true { | |
contains(tags, "environment") | |
contains(tags, "managed_by") | |
contains(tags, "team") | |
} else = false { true } | |
created_tags[resource_type] = num { | |
some resource_type | |
resource_types[resource_type] | |
all := resources[resource_type] | |
create_resources := [res | res:= all[_]; res.change.actions[_] == "create"] | |
tag_changeset := [res | res := [key | create_resources[_].change.after.tags[key]]] | |
num := tags_contain_proper_keys(tag_changeset[_]) | |
} | |
modified_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 | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment