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

@exclude tag causes error if no resource of that type exists in plan #468

Closed
pontinjx opened this issue Apr 19, 2021 · 2 comments
Closed
Assignees
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation

Comments

@pontinjx
Copy link

Description :
If a test is defined with an exludes tag but no resource of that type is defined anywhere in the plan, then terraform-compliance errors with ERROR: Hook 'exclude_resources' from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/terraform_compliance/steps/terrain.py:85 raised: 'AttributeError: 'Context' object has no attribute 'stash''

To Reproduce

  1. Sample terraform main.tf
resource "aws_s3_bucket" "my_s3_bucket" {
   bucket = "my-bucket"
}
  1. terraform init && terraform plan -out plan.out && terraform-compliance -p plan.out -f features
  2. Run using pip package
  3. Error output:
Feature: Load balancer should use certain policies for HTTPS  # /Users/***/features/naughty.feature

    @exclude_aws_lb_listener.listener_to_exclude
    Scenario: Load balancer should use certain policies for HTTPS
        💡 SKIPPING: Can not find aws_lb_listener defined in target terraform plan.
        Given I have aws_lb_listener defined

1 features (0 passed, 1 skipped)
1 scenarios (0 passed, 1 skipped)
6 steps (0 passed, 1 skipped)
Run 1618825783 finished within a moment
❗ ERROR: Hook 'exclude_resources' from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/terraform_compliance/steps/terrain.py:85 raised: 'AttributeError: 'Context' object has no attribute 'stash''

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/radish/hookregistry.py", line 132, in call
    func(model, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/terraform_compliance/steps/terrain.py", line 97, in exclude_resources
    for resource in step.context.stash:
AttributeError: 'Context' object has no attribute 'stash'
  1. <Your feature/scenario/steps>
Feature: Load balancer should use certain policies for HTTPS
    @exclude_aws_lb_listener.listener_to_exclude
    Scenario: Load balancer should use certain policies for HTTPS
        Given I have aws_lb_listener defined
        When its port is 443
        When its protocol is HTTPS
        When it has ssl_policy
        Then it must have ssl_policy
        And its value must match the "ffoo-with-tls-1-2|bar-with-tls-1-2|etc-with-tls-1-2" regex

Expected behavior :
The tests should pass since no non-compliant LB listener is defined in the plan.

Tested versions :

  • <terraform-compliance version (terraform-compliance -v)> - present in 1.3.13 and 1.3.14
  • <terraform version (terraform -v)> - tested with 0.12.29 and 0.13.6
  • <python runtime version, if running as a python package (python --version)> - tested with 3.8.1

Additional context
N/A

@pontinjx pontinjx added the bug label Apr 19, 2021
@Kudbettin Kudbettin added the fixing A fix is addressed, no further data is required label Apr 20, 2021
@Kudbettin Kudbettin added waiting for confirmation Workaround/Fix applied, waiting for confirmation and removed fixing A fix is addressed, no further data is required labels Jun 4, 2021
@Kudbettin
Copy link
Member

Hi @pontinjx ,

Does the issue still persist?

@pontinjx
Copy link
Author

pontinjx commented Jun 4, 2021

Hi, this is working for me now in 1.3.15 - thanks very much!

@pontinjx pontinjx closed this as completed Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting for confirmation Workaround/Fix applied, waiting for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants