Skip to content

Commit

Permalink
fix: fix failing Terraform integration test cases (#5218)
Browse files Browse the repository at this point in the history
* fix: fix the failing terraform integration test cases

* fix: fix the resource address while accessing the module config resources

* fix: fix checking the experimental log integration test cases
  • Loading branch information
moelasmar committed May 30, 2023
1 parent 6f137dc commit dc5562a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
10 changes: 8 additions & 2 deletions samcli/hook_packages/terraform/hooks/prepare/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,21 @@ def _check_unresolvable_values(root_module: dict, root_tf_module: TFModule) -> N
# iterate over resources for current module
for resource in curr_module.get("resources", []):
resource_type = resource.get("type")
resource_name = resource.get("name")
resource_mode = resource.get("mode")

resource_mapper = RESOURCE_TRANSLATOR_MAPPING.get(resource_type)
if not resource_mapper:
continue

resource_values = resource.get("values")
resource_full_address = resource.get("address")
resource_address = (
f"data.{resource_type}.{resource_name}"
if resource_mode == "data"
else f"{resource_type}.{resource_name}"
)

config_resource_address = get_configuration_address(resource_full_address)
config_resource_address = get_configuration_address(resource_address)
config_resource = curr_tf_module.resources[config_resource_address]

for prop_builder in resource_mapper.property_builder_mapping.values():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_invoke_function_get_experimental_prompted(self):
"You can also enable this beta feature with 'sam local invoke --beta-features'."
)
self.assertRegex(stdout.decode("utf-8"), terraform_beta_feature_prompted_text)
self.assertTrue(stderr.decode("utf-8").startswith(Colored().yellow(EXPERIMENTAL_WARNING)))
self.assertRegex(stderr.decode("utf-8"), EXPERIMENTAL_WARNING)

response = json.loads(stdout.decode("utf-8").split("\n")[2][85:].strip())
expected_response = json.loads('{"statusCode":200,"body":"{\\"message\\": \\"hello world\\"}"}')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
provider "aws" {
# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ terraform {

provider "aws" {
# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,8 +1116,12 @@ class TestUnresolvableAttributeCheck:
@patch("samcli.hook_packages.terraform.hooks.prepare.translate.RESOURCE_TRANSLATOR_MAPPING")
@patch("samcli.hook_packages.terraform.hooks.prepare.translate.LOG")
def test_module_contains_unresolvables(self, log_mock, mapping_mock):
config_addr = "addr"
module = {"resources": [{"address": config_addr, "values": Mock()}]}
config_addr = "function.func1"
module = {
"resources": [
{"address": config_addr, "values": Mock(), "type": "function", "mode": "resource", "name": "func1"}
]
}

tf_module = Mock()
tf_module_attr = Mock()
Expand Down

0 comments on commit dc5562a

Please sign in to comment.