Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read resources raw from cache #356

Merged
merged 3 commits into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

# Unreleased
* Fixed resource_raw not getting read from the cache. ([#356](https://github.com/eerkunt/terraform-compliance/pull/356))

## 1.3.2 (2020-08-18)
* Fixed an issue where the null character in step definition break --junit-xml dump. ([#347](https://github.com/eerkunt/terraform-compliance/pull/347))
* New Terraform 0.13 support ([#351](https://github.com/eerkunt/terraform-compliance/pull/351))
Expand Down
9 changes: 6 additions & 3 deletions terraform_compliance/extensions/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,17 +377,20 @@ def parse(self):
self._parse_variables()
self._parse_configurations()

cache = self.cache.get('mounted_resources') if self.parse_it else None
cache_mounted_resources = self.cache.get('mounted_resources') if self.parse_it else None
cache_raw_resources = self.cache.get('resources_raw') if self.parse_it else None

if cache:
if cache_mounted_resources and cache_raw_resources:
# print('Read from cache, instead of re-mounting.')
self.resources = cache
self.resources = cache_mounted_resources
self.resources_raw = cache_raw_resources
else:
# print('Building cache for mounted resources at {}'.format(Defaults.cache_dir))
self._mount_references()

if self.parse_it:
self.cache.set('mounted_resources', self.resources)
self.cache.set('resources_raw', self.resources)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be self.resources_raw.


self._distribute_providers()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"format_version":"0.1","terraform_version":"0.12.25","planned_values":{"root_module":{"resources":[{"address":"aws_api_gateway_documentation_part.example","mode":"managed","type":"aws_api_gateway_documentation_part","name":"example","provider_name":"aws","schema_version":0,"values":{"location":[{"method":"GET","name":null,"path":"/example","status_code":null,"type":"METHOD"}],"properties":"{\"description\":\"Example description\"}"}},{"address":"aws_api_gateway_documentation_version.example","mode":"managed","type":"aws_api_gateway_documentation_version","name":"example","provider_name":"aws","schema_version":0,"values":{"description":"Example description","version":"example_version"}},{"address":"aws_api_gateway_rest_api.tf_example_rest_api","mode":"managed","type":"aws_api_gateway_rest_api","name":"tf_example_rest_api","provider_name":"aws","schema_version":0,"values":{"api_key_source":"HEADER","binary_media_types":null,"body":null,"description":null,"minimum_compression_size":-1,"name":"example_api","policy":null,"tags":{"Name":"tf-example-rest-api"}}},{"address":"aws_iam_role.ssm_tag_collector_role","mode":"managed","type":"aws_iam_role","name":"ssm_tag_collector_role","provider_name":"aws","schema_version":0,"values":{"assume_role_policy":"{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Action\": \"sts:AssumeRole\",\n \"Principal\": {\n \"Service\": \"ec2.amazonaws.com\"\n },\n \"Effect\": \"Allow\",\n \"Sid\": \"\"\n }\n ]\n}\n","description":null,"force_detach_policies":false,"max_session_duration":3600,"name_prefix":null,"path":"/","permissions_boundary":null,"tags":{"Name":"ssm_tag_collector_role"}}},{"address":"aws_instance.tf-example-ec2","mode":"managed","type":"aws_instance","name":"tf-example-ec2","provider_name":"aws","schema_version":1,"values":{"ami":"ami-0323c3dd2da7fb37d","credit_specification":[],"disable_api_termination":null,"ebs_optimized":null,"get_password_data":false,"hibernation":null,"iam_instance_profile":null,"instance_initiated_shutdown_behavior":null,"instance_type":"t2.micro","monitoring":null,"source_dest_check":true,"tags":null,"timeouts":null,"user_data":null,"user_data_base64":null}},{"address":"aws_lambda_function.ssm_tag_collector_lambda","mode":"managed","type":"aws_lambda_function","name":"ssm_tag_collector_lambda","provider_name":"aws","schema_version":0,"values":{"dead_letter_config":[],"description":"Send tags from the list of instances in the event context to the ssm-tag-manager lambda in master account.","environment":[],"file_system_config":[],"filename":null,"function_name":"ssm-tag-collector","handler":"ssmTagCollector.lambda_handler","kms_key_arn":null,"layers":null,"memory_size":128,"publish":false,"reserved_concurrent_executions":-1,"runtime":"python3.6","s3_bucket":null,"s3_key":null,"s3_object_version":null,"source_code_hash":"XNeyqu7DY2I6dYpccgmz+fcG5oe6U3+iiubc+RtoOzc=","tags":{"Name":"ssm_tag_collector_lambda"},"timeout":25,"timeouts":null,"vpc_config":[]}}]}},"resource_changes":[{"address":"aws_api_gateway_documentation_part.example","mode":"managed","type":"aws_api_gateway_documentation_part","name":"example","provider_name":"aws","change":{"actions":["create"],"before":null,"after":{"location":[{"method":"GET","name":null,"path":"/example","status_code":null,"type":"METHOD"}],"properties":"{\"description\":\"Example description\"}"},"after_unknown":{"id":true,"location":[{}],"rest_api_id":true}}},{"address":"aws_api_gateway_documentation_version.example","mode":"managed","type":"aws_api_gateway_documentation_version","name":"example","provider_name":"aws","change":{"actions":["create"],"before":null,"after":{"description":"Example description","version":"example_version"},"after_unknown":{"id":true,"rest_api_id":true}}},{"address":"aws_api_gateway_rest_api.tf_example_rest_api","mode":"managed","type":"aws_api_gateway_rest_api","name":"tf_example_rest_api","provider_name":"aws","change":{"actions":["create"],"before":null,"after":{"api_key_source":"HEADER","binary_media_types":null,"body":null,"description":null,"minimum_compression_size":-1,"name":"example_api","policy":null,"tags":{"Name":"tf-example-rest-api"}},"after_unknown":{"arn":true,"created_date":true,"endpoint_configuration":true,"execution_arn":true,"id":true,"root_resource_id":true,"tags":{}}}},{"address":"aws_iam_role.ssm_tag_collector_role","mode":"managed","type":"aws_iam_role","name":"ssm_tag_collector_role","provider_name":"aws","change":{"actions":["create"],"before":null,"after":{"assume_role_policy":"{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Action\": \"sts:AssumeRole\",\n \"Principal\": {\n \"Service\": \"ec2.amazonaws.com\"\n },\n \"Effect\": \"Allow\",\n \"Sid\": \"\"\n }\n ]\n}\n","description":null,"force_detach_policies":false,"max_session_duration":3600,"name_prefix":null,"path":"/","permissions_boundary":null,"tags":{"Name":"ssm_tag_collector_role"}},"after_unknown":{"arn":true,"create_date":true,"id":true,"name":true,"tags":{},"unique_id":true}}},{"address":"aws_instance.tf-example-ec2","mode":"managed","type":"aws_instance","name":"tf-example-ec2","provider_name":"aws","change":{"actions":["create"],"before":null,"after":{"ami":"ami-0323c3dd2da7fb37d","credit_specification":[],"disable_api_termination":null,"ebs_optimized":null,"get_password_data":false,"hibernation":null,"iam_instance_profile":null,"instance_initiated_shutdown_behavior":null,"instance_type":"t2.micro","monitoring":null,"source_dest_check":true,"tags":null,"timeouts":null,"user_data":null,"user_data_base64":null},"after_unknown":{"arn":true,"associate_public_ip_address":true,"availability_zone":true,"cpu_core_count":true,"cpu_threads_per_core":true,"credit_specification":[],"ebs_block_device":true,"ephemeral_block_device":true,"host_id":true,"id":true,"instance_state":true,"ipv6_address_count":true,"ipv6_addresses":true,"key_name":true,"metadata_options":true,"network_interface":true,"outpost_arn":true,"password_data":true,"placement_group":true,"primary_network_interface_id":true,"private_dns":true,"private_ip":true,"public_dns":true,"public_ip":true,"root_block_device":true,"secondary_private_ips":true,"security_groups":true,"subnet_id":true,"tenancy":true,"volume_tags":true,"vpc_security_group_ids":true}}},{"address":"aws_lambda_function.ssm_tag_collector_lambda","mode":"managed","type":"aws_lambda_function","name":"ssm_tag_collector_lambda","provider_name":"aws","change":{"actions":["create"],"before":null,"after":{"dead_letter_config":[],"description":"Send tags from the list of instances in the event context to the ssm-tag-manager lambda in master account.","environment":[],"file_system_config":[],"filename":null,"function_name":"ssm-tag-collector","handler":"ssmTagCollector.lambda_handler","kms_key_arn":null,"layers":null,"memory_size":128,"publish":false,"reserved_concurrent_executions":-1,"runtime":"python3.6","s3_bucket":null,"s3_key":null,"s3_object_version":null,"source_code_hash":"XNeyqu7DY2I6dYpccgmz+fcG5oe6U3+iiubc+RtoOzc=","tags":{"Name":"ssm_tag_collector_lambda"},"timeout":25,"timeouts":null,"vpc_config":[]},"after_unknown":{"arn":true,"dead_letter_config":[],"environment":[],"file_system_config":[],"id":true,"invoke_arn":true,"last_modified":true,"qualified_arn":true,"role":true,"source_code_size":true,"tags":{},"tracing_config":true,"version":true,"vpc_config":[]}}}],"configuration":{"provider_config":{"archive":{"name":"archive"},"aws":{"name":"aws","expressions":{"profile":{"constant_value":"default"},"region":{"constant_value":"us-east-1"}}}},"root_module":{"resources":[{"address":"aws_api_gateway_documentation_part.example","mode":"managed","type":"aws_api_gateway_documentation_part","name":"example","provider_config_key":"aws","expressions":{"location":[{"method":{"constant_value":"GET"},"path":{"constant_value":"/example"},"type":{"constant_value":"METHOD"}}],"properties":{"constant_value":"{\"description\":\"Example description\"}"},"rest_api_id":{"references":["aws_api_gateway_rest_api.tf_example_rest_api"]}},"schema_version":0},{"address":"aws_api_gateway_documentation_version.example","mode":"managed","type":"aws_api_gateway_documentation_version","name":"example","provider_config_key":"aws","expressions":{"description":{"constant_value":"Example description"},"rest_api_id":{"references":["aws_api_gateway_rest_api.tf_example_rest_api"]},"version":{"constant_value":"example_version"}},"schema_version":0,"depends_on":["aws_api_gateway_documentation_part.example"]},{"address":"aws_api_gateway_rest_api.tf_example_rest_api","mode":"managed","type":"aws_api_gateway_rest_api","name":"tf_example_rest_api","provider_config_key":"aws","expressions":{"name":{"constant_value":"example_api"},"tags":{"constant_value":{"Name":"tf-example-rest-api"}}},"schema_version":0},{"address":"aws_iam_role.ssm_tag_collector_role","mode":"managed","type":"aws_iam_role","name":"ssm_tag_collector_role","provider_config_key":"aws","expressions":{"assume_role_policy":{"constant_value":"{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Action\": \"sts:AssumeRole\",\n \"Principal\": {\n \"Service\": \"ec2.amazonaws.com\"\n },\n \"Effect\": \"Allow\",\n \"Sid\": \"\"\n }\n ]\n}\n"},"tags":{"constant_value":{"Name":"ssm_tag_collector_role"}}},"schema_version":0},{"address":"aws_instance.tf-example-ec2","mode":"managed","type":"aws_instance","name":"tf-example-ec2","provider_config_key":"aws","expressions":{"ami":{"constant_value":"ami-0323c3dd2da7fb37d"},"instance_type":{"constant_value":"t2.micro"}},"schema_version":1},{"address":"aws_lambda_function.ssm_tag_collector_lambda","mode":"managed","type":"aws_lambda_function","name":"ssm_tag_collector_lambda","provider_config_key":"aws","expressions":{"description":{"constant_value":"Send tags from the list of instances in the event context to the ssm-tag-manager lambda in master account."},"function_name":{"constant_value":"ssm-tag-collector"},"handler":{"constant_value":"ssmTagCollector.lambda_handler"},"role":{"references":["aws_iam_role.ssm_tag_collector_role"]},"runtime":{"constant_value":"python3.6"},"source_code_hash":{},"tags":{"constant_value":{"Name":"ssm_tag_collector_lambda"}},"timeout":{"constant_value":25}},"schema_version":0}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@security
Feature: Feature for issue 338


@noskip
Scenario: Tag null with security
Given I have resource that supports tags defined
Then it must contain tags


Scenario: Tag null with
Given I have resource that supports tags defined
Then it must contain tags


Scenario: Tag null with no_security
Given I have resource that supports tags defined
Then it must contain tags
17 changes: 17 additions & 0 deletions tests/functional/test_issue-338-cache_resources_raw/test.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: Feature for issue 338 no security


@noskip
Scenario: Tag null with security
Given I have resource that supports tags defined
Then it must contain tags


Scenario: Tag null with
Given I have resource that supports tags defined
Then it must contain tags


Scenario: Tag null with no_security
Given I have resource that supports tags defined
Then it must contain tags