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

fix(terraform): add module prefix to the resource ID of a module #5272

Closed
wants to merge 1 commit into from

Conversation

gruebel
Copy link
Contributor

@gruebel gruebel commented Jun 28, 2023

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

  • added module. prefix to the resoruce ID of the module resources, now they are also more aligned to the address of normal resources

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@gruebel gruebel temporarily deployed to scan-security June 28, 2023 22:20 — with GitHub Actions Inactive

if vertex.block_type == BlockType.MODULE:
# prefix modules with 'module' to properly identify them
resource_id = f"{BlockType.MODULE}.{resource_id}"
Copy link
Contributor

Choose a reason for hiding this comment

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

how come we don't need to do it for any other resource type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently none of the other non-resource blocks has a prefix, which is not so important, because they are identifiable by their block type. I did this change to align the address field to be identical to the prefix for other block types inside a module.

@@ -316,9 +316,9 @@ def test_nested_modules_address_attribute(self):
graph_manager = TerraformGraphManager(NetworkxConnector())
local_graph, _ = graph_manager.build_graph_from_source_directory(resources_dir, render_variables=True)
module_1 = self.get_vertex_by_name_and_type(local_graph, BlockType.MODULE, 'inner_s3_module')
assert module_1.attributes.get(CustomAttributes.TF_RESOURCE_ADDRESS) == 'module.s3_module.inner_s3_module'
assert module_1.attributes.get(CustomAttributes.TF_RESOURCE_ADDRESS) == 'module.s3_module.module.inner_s3_module'
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like a scary change I have to say - are we sure that we handle this correctly now that we have multiple module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume so as can be seen in the expected_local_graph.json file I adjusted. multi module looks good and also resource inside that module didn't change.

@gruebel
Copy link
Contributor Author

gruebel commented Jul 6, 2023

fixed differently 🙂

@gruebel gruebel closed this Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants