Skip to content

Commit

Permalink
Fixed a problem where exact problem was not applied on seek_regex_key…
Browse files Browse the repository at this point in the history
…_in_dict_values(). #225
  • Loading branch information
eerkunt committed Mar 4, 2020
1 parent aa9dcf6 commit 5f00e4f
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 1.1.11 (2020-03-04)
* Fixed a problem where `Then its <key> is <value>` step was not searching for "exact" matches. ([#225](https://github.com/eerkunt/terraform-compliance/issues/221))

## 1.1.10 (2020-03-03)
* Fixed a problem where int, bool and float types was not properly filtered and matched.
* Fixed a problem where filtering functions does not work properly.
Expand Down
2 changes: 1 addition & 1 deletion terraform_compliance/common/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def seek_regex_key_in_dict_values(haystack, key_name, needle, key_matched=None):
:param key_matched: Internal use
:return: list of found keys & values
'''
regex = r'{}'.format(needle)
regex = r'^{}$'.format(needle)
found = list()
if isinstance(haystack, dict):
for key, value in haystack.items():
Expand Down
1 change: 1 addition & 0 deletions tests/functional/test_issue-225/.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Failure: Can not find demo in mesh_name property of module\.appmesh_existing\.aws_appmesh_virtual_node.vn\["ui"\]\.
Empty file.
28 changes: 28 additions & 0 deletions tests/functional/test_issue-225/appmesh/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
resource "aws_appmesh_virtual_node" "vn" {
for_each = {
"ui": "demo2",
}
name = "${each.key}-vn"
mesh_name = each.value

spec {
backend {
virtual_service {
virtual_service_name = "servicea.simpleapp.local"
}
}

listener {
port_mapping {
port = 80
protocol = "http"
}
}

service_discovery {
dns {
hostname = "serviceb.simpleapp.local"
}
}
}
}
7 changes: 7 additions & 0 deletions tests/functional/test_issue-225/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module "appmesh_existing" {
source = "./appmesh"
}

provider "aws" {
region = "eu-west-1"
}
1 change: 1 addition & 0 deletions tests/functional/test_issue-225/plan.out.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"format_version":"0.1","terraform_version":"0.12.21","planned_values":{"root_module":{"child_modules":[{"resources":[{"address":"module.appmesh_existing.aws_appmesh_virtual_node.vn[\"ui\"]","mode":"managed","type":"aws_appmesh_virtual_node","name":"vn","index":"ui","provider_name":"aws","schema_version":1,"values":{"mesh_name":"demo2","name":"ui-vn","spec":[{"backend":[{"virtual_service":[{"virtual_service_name":"servicea.simpleapp.local"}]}],"listener":[{"health_check":[],"port_mapping":[{"port":80,"protocol":"http"}]}],"logging":[],"service_discovery":[{"aws_cloud_map":[],"dns":[{"hostname":"serviceb.simpleapp.local"}]}]}],"tags":null}}],"address":"module.appmesh_existing"}]}},"resource_changes":[{"address":"module.appmesh_existing.aws_appmesh_virtual_node.vn[\"ui\"]","module_address":"module.appmesh_existing","mode":"managed","type":"aws_appmesh_virtual_node","name":"vn","index":"ui","provider_name":"aws","change":{"actions":["create"],"before":null,"after":{"mesh_name":"demo2","name":"ui-vn","spec":[{"backend":[{"virtual_service":[{"virtual_service_name":"servicea.simpleapp.local"}]}],"listener":[{"health_check":[],"port_mapping":[{"port":80,"protocol":"http"}]}],"logging":[],"service_discovery":[{"aws_cloud_map":[],"dns":[{"hostname":"serviceb.simpleapp.local"}]}]}],"tags":null},"after_unknown":{"arn":true,"created_date":true,"id":true,"last_updated_date":true,"spec":[{"backend":[{"virtual_service":[{}]}],"backends":true,"listener":[{"health_check":[],"port_mapping":[{}]}],"logging":[],"service_discovery":[{"aws_cloud_map":[],"dns":[{"service_name":true}]}]}]}}}],"configuration":{"provider_config":{"aws":{"name":"aws","expressions":{"region":{"constant_value":"eu-west-1"}}}},"root_module":{"module_calls":{"appmesh_existing":{"source":"./appmesh","module":{"resources":[{"address":"aws_appmesh_virtual_node.vn","mode":"managed","type":"aws_appmesh_virtual_node","name":"vn","provider_config_key":"appmesh_existing:aws","expressions":{"mesh_name":{"references":["each.value"]},"name":{"references":["each.key"]},"spec":[{"backend":[{"virtual_service":[{"virtual_service_name":{"constant_value":"servicea.simpleapp.local"}}]}],"listener":[{"port_mapping":[{"port":{"constant_value":80},"protocol":{"constant_value":"http"}}]}],"service_discovery":[{"dns":[{"hostname":{"constant_value":"serviceb.simpleapp.local"}}]}]}]},"schema_version":1,"for_each_expression":{"constant_value":{"ui":"demo2"}}}]}}}}}}
7 changes: 7 additions & 0 deletions tests/functional/test_issue-225/test.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: test

Scenario: Appmesh module can use existing appmesh (should fail)
Given I have aws_appmesh_virtual_node defined
When its address is module.appmesh_existing.aws_appmesh_virtual_node.vn
And its index is ui
Then its mesh_name must be demo

0 comments on commit 5f00e4f

Please sign in to comment.