5 Testing
This chapter covers
- Identifying which type of tests to write for infrastructure systems
- Writing tests to verify infrastructure configuration or modules
- Understanding the cost of different types of tests
Recall from Chapter 1 that infrastructure as code involves an entire process to push a change to a system. You update scripts or configurations with infrastructure changes, push them to a version control system, and apply the changes in an automated way. How do you know that the change worked? You can use all of the patterns for modules and dependency management from the last two chapters, but they won’t guarantee that every change you make will succeed! This chapter reviews some considerations and concepts related to testing infrastructure as code to reduce the rate of change failure and build confidence in infrastructure changes.
The most straightforward form of infrastructure testing involves manually checking configuration. Imagine you configure a network switch with a new network segment. How do you know you didn’t break existing networks and the new network connects successfully? You can test existing networks by pinging each server on each network and verifying their connectivity. To test if you set up the new network correctly, you create a new server on the network and check if it responds when you connect to it.