elmundio87 / terraform_validate

Assists in the enforcement of user-defined standards in Terraform
GNU General Public License v3.0
257 stars 43 forks source link

Fix logic to raise error when property is missing #21

Closed pradeepbhadani closed 7 years ago

pradeepbhadani commented 7 years ago

Test Case: Validate that aws_instance have specific tags (for eg - name, team)

Current code passes for following code which is not true

resource "aws_instance" "web" { ami = "${data.aws_ami.ubuntu.id}" instance_type = "t2.micro" }

This fix will raise error if there is no declaration of a property

pradeepbhadani commented 7 years ago

@elmundio87 This failure was expected because terraform_validate/fixtures/boolean_compare/1.tf has missing property.

I have updated test and now it's working.

vagrant@vagrant-ubuntu-trusty-64:~/git/terraform_validate$ sudo ./coverage.sh 
=========================================================================================== test session starts ============================================================================================
platform linux2 -- Python 2.7.6, pytest-3.1.1, py-1.4.33, pluggy-0.4.0
rootdir: /home/vagrant/git/terraform_validate, inifile:
collected 55 items 

terraform_validate/functional_test.py .....................................
terraform_validate/unit_test.py ..................

======================================================================================== 55 passed in 1.02 seconds =========================================================================================
Name                                    Stmts   Miss  Cover   Missing
---------------------------------------------------------------------
terraform_validate/__init__                 1      0   100%   
terraform_validate/functional_test        271      2    99%   6, 382
terraform_validate/terraform_validate     339      1    99%   295
terraform_validate/unit_test               91      4    96%   15-19
---------------------------------------------------------------------
TOTAL                                     702      7    99%   
elmundio87 commented 7 years ago

Hi @pradeepbhadani,

The idea of the conditional that you've removed in this PR is that if you use the following code;

validator.error_if_property_missing() 

then an error will be raised by any subsequent tests that are missing a property.