terraform-compliance / cli

a lightweight, security focused, BDD test framework against terraform.
https://terraform-compliance.com
MIT License
1.36k stars 150 forks source link

Error generating Junit XML #508

Open mattburgess opened 3 years ago

mattburgess commented 3 years ago

On some runs of terraform-compliance, we see the following stack trace:

! ERROR: Hook 'generate_junit_xml' from /usr/local/lib/python3.7/site-packages/radish/extensions/junit_xml_writer.py:74 raised: 'RadishError: Cannot get duration of Feature 'Embedded Credentials' because either starttime or endtime is not set'
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/radish/hookregistry.py", line 132, in call
    func(model, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/terraform_compliance/steps/terrain.py", line 11, in load_terraform_data
    world.config.terraform = TerraformParser(world.config.user_data['plan_file'])
  File "/usr/local/lib/python3.7/site-packages/terraform_compliance/extensions/terraform.py", line 48, in __init__
    self.parse()
  File "/usr/local/lib/python3.7/site-packages/terraform_compliance/extensions/terraform.py", line 500, in parse
    self._expand_resource_tags(resource)
  File "/usr/local/lib/python3.7/site-packages/terraform_compliance/extensions/terraform.py", line 559, in _expand_resource_tags
    if isinstance(resource.get('values', {}).get('tags'), list):
AttributeError: 'NoneType' object has no attribute 'get'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/radish/runner.py", line 56, in _wrapper
    return func(self, model_instance, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/radish/runner.py", line 89, in start
    returncode |= self.run_feature(feature)
  File "/usr/local/lib/python3.7/site-packages/radish/runner.py", line 34, in _decorator
    return func(self, *args, **kwargs)  # pylint: disable=not-callable
  File "/usr/local/lib/python3.7/site-packages/radish/runner.py", line 53, in _wrapper
    "before", model, True, model_instance, *args, **kwargs
  File "/usr/local/lib/python3.7/site-packages/radish/hookregistry.py", line 134, in call
    raise HookError(func, utils.Failure(e))
radish.exceptions.HookError: Hook 'load_terraform_data' from /usr/local/lib/python3.7/site-packages/terraform_compliance/steps/terrain.py:9 raised: 'AttributeError: 'NoneType' object has no attribute 'get''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/radish/hookregistry.py", line 132, in call
    func(model, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/radish/extensions/junit_xml_writer.py", line 124, in generate_junit_xml
    time="%.3f" % feature.duration.total_seconds(),
  File "/usr/local/lib/python3.7/site-packages/radish/model.py", line 81, in duration
    self.keyword, self.sentence
radish.exceptions.RadishError: Cannot get duration of Feature 'Embedded Credentials' because either starttime or endtime is not set

I'm hoping the above might be enough to work out what the issue is. I'd love to provide the plan but it's 3.5M in size, consisting of 89000 lines of JSON so I don't much fancy trawling through that to see what needs to be anonymised!

To Reproduce:

Run the following command on the latest docker container: terraform-compliance --junit-xml=${CI_JOB_NAME}-junitreport.xml -f $CI_PROJECT_DIR/$SECURITY_COMPLIANCE_TEST_DIR -p $CI_PROJECT_DIR/terraform-plan-${WORKSPACE}.tfplan.json.

The step that triggers the above stack trace is:

Feature: Embedded Credentials  # /builds/dwp/wauc-leeds/new-style-jobseekers-allowance/infrastructure/environment/security_tests/awscred.feature
In order to secure our environments
As engineers
We'll not embed AWS credentials into our code
Kudbettin commented 3 years ago

Hmm a very benign line is failing in radish. Are you able to run the same command outside of docker?