liveBook · Manning

Declarative programming

As explained in Grokking Software Architecture

A programming approach that specifies the desired result or state rather than the steps to produce it.

Declarative programming states what should exist, not the steps to create it. For infrastructure, a configuration describes the desired resources; Terraform works out the API calls and changes needed to make reality match. section 9.12 section 9.7

Describe the result

A SQL declaration might ask for a table with three columns without specifying how the database builds it. Similarly, an HCL blueprint can ask for one database and one storage bucket; Terraform figures out how to provision them. Its state file records what exists so it can calculate the changes needed. section 9.7 section 9.12

The contrast is with imperative programming, which specifies how to proceed using logic such as loops and conditionals. Declarative configuration avoids writing the infrastructure API calls, security handshakes, and retry logic yourself. section 9.7

How Grokking Software Architecture covers it

How deep it goes
Explains desired-state configuration, Terraform planning, and state tracking without detailing HCL syntax or engine internals.
Examples
Compares declaring a three-column SQL table with requesting a database and storage bucket in Terraform.
What you can do after
Configure infrastructure by declaring desired resources in HCL and letting Terraform determine how to provision them.
How it connects
Connects Infrastructure as Code with Terraform, HCL, SQL, and imperative programming.

Also explained in

Compare how 15 books explain declarative programming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.