Skip to content

Commit

Permalink
Fixed a problem where counting repetable blocks was incorrect. Also r…
Browse files Browse the repository at this point in the history
…eported in #194.
  • Loading branch information
eerkunt committed Jan 6, 2020
1 parent f3f5ad3 commit 7d171c5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion terraform_compliance/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def it_condition_contain_something(_step_obj, something):
found_key = [{something: found_key}]

if len(found_key):
found_key = found_key[0] if len(found_key) == 1 else found_key
found_key = found_key[0] if len(found_key) == 1 and something in found_key[0] else found_key

if type(found_key) is dict:
found_value = jsonify(found_key.get(something, found_key))
Expand Down
35 changes: 35 additions & 0 deletions tests/functional/test_counting_repeatable_argument_blocks/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
provider "aws" {
region = "us-west-2"
access_key = "my-access-key"
secret_key = "my-secret-key"
skip_credentials_validation = true
skip_get_ec2_platforms = true
skip_region_validation = true
skip_requesting_account_id = true
version = "~> 2.43"
}

resource "aws_instance" "one" {
ami = "ami-6d1c2007"
instance_type = "t2.micro"

network_interface {
device_index = 1
network_interface_id = "eth0"
}
}

resource "aws_instance" "two" {
ami = "ami-6d1c2007"
instance_type = "t2.micro"

network_interface {
device_index = 1
network_interface_id = "eth0"
}

network_interface {
device_index = 2
network_interface_id = "eth1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"format_version":"0.1","terraform_version":"0.12.18","planned_values":{"root_module":{"resources":[{"address":"aws_instance.one","mode":"managed","type":"aws_instance","name":"one","provider_name":"aws","schema_version":1,"values":{"ami":"ami-6d1c2007","credit_specification":[],"disable_api_termination":null,"ebs_optimized":null,"get_password_data":false,"iam_instance_profile":null,"instance_initiated_shutdown_behavior":null,"instance_type":"t2.micro","monitoring":null,"network_interface":[{"delete_on_termination":false,"device_index":1,"network_interface_id":"eth0"}],"source_dest_check":null,"tags":null,"timeouts":null,"user_data":null,"user_data_base64":null}},{"address":"aws_instance.two","mode":"managed","type":"aws_instance","name":"two","provider_name":"aws","schema_version":1,"values":{"ami":"ami-6d1c2007","credit_specification":[],"disable_api_termination":null,"ebs_optimized":null,"get_password_data":false,"iam_instance_profile":null,"instance_initiated_shutdown_behavior":null,"instance_type":"t2.micro","monitoring":null,"network_interface":[{"delete_on_termination":false,"device_index":1,"network_interface_id":"eth0"},{"delete_on_termination":false,"device_index":2,"network_interface_id":"eth1"}],"source_dest_check":null,"tags":null,"timeouts":null,"user_data":null,"user_data_base64":null}}]}},"resource_changes":[{"address":"aws_instance.one","mode":"managed","type":"aws_instance","name":"one","provider_name":"aws","change":{"actions":["create"],"before":null,"after":{"ami":"ami-6d1c2007","credit_specification":[],"disable_api_termination":null,"ebs_optimized":null,"get_password_data":false,"iam_instance_profile":null,"instance_initiated_shutdown_behavior":null,"instance_type":"t2.micro","monitoring":null,"network_interface":[{"delete_on_termination":false,"device_index":1,"network_interface_id":"eth0"}],"source_dest_check":null,"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,"network_interface":[{}],"network_interface_id":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,"security_groups":true,"subnet_id":true,"tenancy":true,"volume_tags":true,"vpc_security_group_ids":true}}},{"address":"aws_instance.two","mode":"managed","type":"aws_instance","name":"two","provider_name":"aws","change":{"actions":["create"],"before":null,"after":{"ami":"ami-6d1c2007","credit_specification":[],"disable_api_termination":null,"ebs_optimized":null,"get_password_data":false,"iam_instance_profile":null,"instance_initiated_shutdown_behavior":null,"instance_type":"t2.micro","monitoring":null,"network_interface":[{"delete_on_termination":false,"device_index":1,"network_interface_id":"eth0"},{"delete_on_termination":false,"device_index":2,"network_interface_id":"eth1"}],"source_dest_check":null,"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,"network_interface":[{},{}],"network_interface_id":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,"security_groups":true,"subnet_id":true,"tenancy":true,"volume_tags":true,"vpc_security_group_ids":true}}}],"configuration":{"provider_config":{"aws":{"name":"aws","version_constraint":"~\u003e 2.43","expressions":{"access_key":{"constant_value":"my-access-key"},"region":{"constant_value":"us-west-2"},"secret_key":{"constant_value":"my-secret-key"},"skip_credentials_validation":{"constant_value":true},"skip_get_ec2_platforms":{"constant_value":true},"skip_region_validation":{"constant_value":true},"skip_requesting_account_id":{"constant_value":true}}}},"root_module":{"resources":[{"address":"aws_instance.one","mode":"managed","type":"aws_instance","name":"one","provider_config_key":"aws","expressions":{"ami":{"constant_value":"ami-6d1c2007"},"instance_type":{"constant_value":"t2.micro"},"network_interface":[{"device_index":{"constant_value":1},"network_interface_id":{"constant_value":"eth0"}}]},"schema_version":1},{"address":"aws_instance.two","mode":"managed","type":"aws_instance","name":"two","provider_config_key":"aws","expressions":{"ami":{"constant_value":"ami-6d1c2007"},"instance_type":{"constant_value":"t2.micro"},"network_interface":[{"device_index":{"constant_value":1},"network_interface_id":{"constant_value":"eth0"}},{"device_index":{"constant_value":2},"network_interface_id":{"constant_value":"eth1"}}]},"schema_version":1}]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Count bug

Scenario: Ensure one network is attached to one
Given I have aws_instance defined
When its name is one
And it contains network_interface
And I count them
Then I expect the result is equal to 1

Scenario: Ensure two networks are attached to two
Given I have aws_instance defined
When its name is two
And it contains network_interface
And I count them
Then I expect the result is equal to 2

0 comments on commit 7d171c5

Please sign in to comment.