10 Testing and Refactoring
This chapter covers:
- Tainting and rotating AWS access keys provisioned by Terraform
- Module expansion refactoring techniques
- Migrating state with terraform mv and terraform state commands
- Importing existing resources with terraform import
- Testing Infrastructure as Code with terraform-exec
The ancient Greek philosopher Heraclitus is famous for positing that: “Life is flux”. In other words, change is inevitable, and to resist change is to resist the essence of our existence. Perhaps nowhere is change more pronounced than in the software industry. Either due to changing customer requirements, or shifting market conditions, software is guaranteed to change. If not actively maintained, software degrades over time. Refactoring and testing are steps that developers take to keep software current.
What is refactoring? Refactoring is the art of improving the design of code without changing existing behavior or adding new functionality. Benefits of refactoring include:
- Maintainability – the ability to quickly fix bugs and address problems faced by customers.
- Extensibility – how easy it is to add new features. If your software is extensible, then you are more agile and able to respond to marketplace changes.
- Reusability – removing duplicated and highly coupled code. Reusable code is readable and easier to maintain.