From the course: DevOps Foundations: Infrastructure as Code

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Testing infrastructure

Testing infrastructure

You can test more of your code without having to use or make real infrastructure by using mocks, which is a testing term for code used to replicate the behavior of an external system so that you can safely run unit tests without affecting your real one. Terraform version 1.6 introduced a standard Terraform test framework, and then version 1.7 introduced a mocking framework. Using it, for example, you can ask Terraform to substitute a mock Amazon Cloud provider for the real provider. Then when you run Terraform test, it runs your code using the mock. So it doesn't need real AWS credentials or access to the cloud. Instead, Terraform pretends to make the requested resources and you can validate that your code, at least logically, works the way you want it to. This is faster and safer, but less comprehensive than using Terraform plan, which does need real AWS credentials and reaches out to the cloud to…

Contents