Skip to content

Instantly share code, notes, and snippets.

@myoung34
Last active April 24, 2020 18:29
Show Gist options
  • Save myoung34/9674102f2443d1350761e5025e28e90e to your computer and use it in GitHub Desktop.
Save myoung34/9674102f2443d1350761e5025e28e90e to your computer and use it in GitHub Desktop.
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