Skill 1.1.2
Declarative and imperative approaches
Key Concepts
An imperative script lists commands in order: create a network, then a subnet, then a server. Running it twice may create duplicates or fail, unless the author writes checks for every case. A declarative configuration, such as Terraform's, describes what should exist: one network, one subnet and one server with these settings. Terraform compares that description with what it already manages and works out the actions needed.
Declarative configuration makes Terraform idempotent: applying an unchanged configuration again results in no changes. To scale from two servers to three, you change a number, and Terraform adds one server rather than three. Terraform also works out the order of operations from the references between resources, so the author does not have to sequence them.