red888
red888

Reputation: 31570

how do you test terraform modules locally without pushing to remote?

some issues with tf modules only present themselves at runtime (terraform apply)

I have my modules in git and use tags for versioning

how do you test tf modules without pushing to remote? meaning if I edit a module I want to test it first before pushing to remote and tagging.

I can pull down the tf module locally and reference it via file system path instead of git remote in source but that is clunky.

Right now I do this:

  1. clone tf module repo
  2. create another local folder for testing the module
  3. create a tf file in that other folder that references the module via source = "../my-module"
  4. terraform apply the module to test before commit and tagging the module to remote

Is there a tf feature for testing a module that im not using? ideally you would clone the tf module's repo and that repo would already have a "test" you could run that is setup to ref the module locally.

Upvotes: 5

Views: 28835

Answers (1)

Felipe
Felipe

Reputation: 7563

terraform fmt -check and terraform validate can be used as a rudimentary test tool for Terraform if you don't want to use remote service. However, I strongly suggest you to read Testing HashiCorp Terraform for a better understand why you might need test your IaC using and end-to-end testing framework. In simple words, you need to make sure that your resources are created in the remote service. So how do you test a remote service that you don't have control of it? You have to use it, do requests and expect correct responses.

Upvotes: 5

Related Questions