Skip to content

Commit

Permalink
Added support for ASG style tags as also explained in #243
Browse files Browse the repository at this point in the history
  • Loading branch information
eerkunt committed Mar 31, 2020
1 parent 4b51832 commit efde07c
Show file tree
Hide file tree
Showing 15 changed files with 821 additions and 7 deletions.
18 changes: 18 additions & 0 deletions terraform_compliance/common/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,21 @@ def is_key_exist(key, target_list_of_dict):
return True

return False


def transform_asg_style_tags(resource_list):
if not isinstance(resource_list, list):
return resource_list

for resource in resource_list:
tag = resource.get('values', {}).get('tag')

if not resource.get('values', {}).get('tags'):
resource['values']['tags'] = {}

if tag:
for elem in tag:
if 'key' in elem and 'value' in elem:
resource['values']['tags'][elem['key']] = elem['value']

return resource_list
12 changes: 6 additions & 6 deletions terraform_compliance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ def cli(arghandling=ArgHandling(), argparser=ArgumentParser(prog=__app_name__,

if args.exit_on_failure is True:
console_write('{} {}\t\t: Scenario executions will stop on first step {}.'.format(Defaults().info_icon,
Defaults().info_colour('INFO'),
Defaults().failure_colour('failure')))
Defaults().info_colour('INFO'),
Defaults().failure_colour('failure')))

if args.no_failure is True:
console_write('{} {}\t: {}ping all {} steps, exit code will always be {}.'.format(Defaults().warning_icon,
Defaults().warning_colour('WARNING'),
Defaults().skip_colour('SKIP'),
Defaults().failure_colour('failure'),
Defaults().info_colour(0)))
Defaults().warning_colour('WARNING'),
Defaults().skip_colour('SKIP'),
Defaults().failure_colour('failure'),
Defaults().info_colour(0)))

if Defaults().interactive_mode is False:
console_write('{} Running in non-interactive mode.'.format(Defaults().info_icon))
Expand Down
2 changes: 2 additions & 0 deletions terraform_compliance/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from terraform_compliance.common.helper import search_regex_in_list, seek_regex_key_in_dict_values, jsonify, Null, EmptyStash
from terraform_compliance.common.helper import get_resource_name_from_stash, get_resource_address_list_from_stash
from terraform_compliance.common.helper import remove_mounted_resources, search_regex_in_list, seek_value_in_dict
from terraform_compliance.common.helper import transform_asg_style_tags
from terraform_compliance.extensions.security_groups import SecurityGroup
from terraform_compliance.extensions.ext_radish_bdd import skip_step
from terraform_compliance.extensions.ext_radish_bdd import custom_type_any
Expand Down Expand Up @@ -86,6 +87,7 @@ def i_have_name_section_configured(_step_obj, name, type_name='resource', _terra
# We are removing all mounted resources here for future steps, since we don't need them for
# tags checking.
found_resources = remove_mounted_resources(_terraform_config.config.terraform.find_resources_by_type(resource_type))
found_resources = transform_asg_style_tags(found_resources)
resource_list.extend(found_resources)

if resource_list:
Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_issue-242/.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Failure: .* 3 is not equal to 2\.
Empty file.
16 changes: 16 additions & 0 deletions tests/functional/test_issue-242/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
provider "gsuite" {
oauth_scopes = [
"https://www.googleapis.com/auth/admin.directory.group",
"https://www.googleapis.com/auth/admin.directory.user"
]
}

resource "gsuite_group" "my-group-i" {
email = "my-group-i@mydomain.com"
name = "My Group I"
}

resource "gsuite_group" "my-group-ii" {
email = "my-group-ii@mydomain.com"
name = "My Group II"
}
Loading

0 comments on commit efde07c

Please sign in to comment.