Menu

We passed null to say use the default and Terraform switched off deletion protection
📰

We passed null to say use the default and Terraform switched off deletion protection

DEV Community: terraform·Sergey Shinder·16 days ago
#xGDGtQw2
#devtoterraform#devto#dev#module#null
Reading 0:00
15s threshold

In August an engineer ran terraform destroy in what he thought was his own sandbox workspace. It was the shared QA environment, and among the things it removed was the QA database. Nobody worried at first, because our database module sets deletion_protection to true, and AWS refuses to delete an RDS instance with that flag set. The instance was gone anyway.

The platform team owns the database module, and its variable for the flag has a default of true. Most teams do not call it directly. They call a wrapper module that adds their naming and tags, and the wrapper exposes the same setting with a default of null. The intention, written in a comment in the wrapper, was simple: if a team says nothing, let the platform module decide.

That is not what null does. A variable in Terraform is nullable unless it says otherwise, and passing null into a nullable variable does not mean the caller left it out. It means the caller set it to null, and the default is never consulted.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.