nhurel / terraspec

Terraform unit test framework
Mozilla Public License 2.0
79 stars 7 forks source link

question: structure for project with multiple modules #17

Closed wyardley closed 3 years ago

wyardley commented 3 years ago

For a project with multiple modules in the same project (e.g., modules/foo, modules/bar, modules/baz/qux), is there a way to have terraspec find all the specs and recurse over them, whether that's laid out like modules/foo/spec or test/spec/modules/foo? Will it take a glob pattern like

% terraspec test/spec/**/**

or similar?

Also, in the examples, it seems as if you can have multiple test cases using the same .tf files, but different tfvars. But what if you want to instantiate the module in a completely different way -- is there a suggested structure for handling that?

nhurel commented 3 years ago

Hello

terraspec has a --spec param to specify the path to a different folder but it doesn't support glob pattern.

Regarding project defining multiple modules, keep in mind terraspec doesn't manage the terraform init phase. So your options are :

Does it help ?

wyardley commented 3 years ago

Yes, I think that helps. In our existing validation step in CI, we do already run terraform init across everything, so, long term, it would still be useful to have functionality along these lines if there’s a way to do it.

wyardley commented 3 years ago

Also, in the case where you want to test instantiating a module different ways, is it possible to just set nil in the tfvars for the parameters you don’t want to set (vs having directories with different .tf files)

nhurel commented 3 years ago

In our existing validation step in CI, we do already run terraform init across everything, so, long term, it would still be useful to have functionality along these lines if there’s a way to do it.

If you already run terraform init in multiple folders, why not running terraspec the same way ?

Also, in the case where you want to test instantiating a module different ways, is it possible to just set nil in the tfvars for the parameters you don’t want to set (vs having directories with different .tf files)

Yes, you can set a variable to null in tfvars file.