liveBook · Manning

Declarative programming

As explained in Acing the CCNA Exam: Volume 2 Advanced Networking and Security

A declarative approach specifies the desired end state while leaving the sequence of operations needed to reach it to the automation system.

Declarative programming defines the desired end state and lets an automation system determine the operations required to reach it. In infrastructure automation, configuration files describe target resources instead of prescribing every configuration step. section 25.2

Apply the pattern through a state-driven workflow:

  • Write the desired infrastructure state in configuration files. section 25.2.2
  • Plan the changes and verify what will be executed before applying them. section 25.2.2
  • Compare the desired state with recorded current state, then apply the necessary changes. section 25.2.2

Terraform uses this model for infrastructure provisioning: Terraform Core processes HCL configuration, maintains the state file, and communicates with providers through APIs. Puppet uses a declarative DSL for configuration management, while Chef and Ansible primarily specify procedural steps. section 25.2.2 section 25.2.3

Desired service state

A Puppet resource can declare that the SSH service must be running: service { 'ssh': ensure => running, }. The declaration states the required condition without detailing the commands needed to produce it. section 25.2.3

Figure 25.6 Provisioning resources with Terraform. Configuration files are processed byTerraform Core to interact with various providers (i.e., public cloud providers) and manage infrastructure resources while maintaining state information in the state file.
A diagram of a software process Description automatically generated

Trace how configuration files pass through Terraform Core to providers while infrastructure state is maintained. section 25.2.2

How Acing the CCNA Exam: Volume 2 Advanced Networking and Security covers it

How deep it goes
Explains state declarations, planning, comparison, application, and state maintenance, but does not detail reconciliation algorithms.
Examples
Uses Terraform HCL configuration, a Puppet SSH service declaration, and provider-based infrastructure provisioning as examples.
What it assumes
Assumes familiarity with infrastructure resources and configuration files while defining procedural and declarative approaches explicitly.
What you can do after
Apply it via Terraform or Puppet by declaring target state and verifying or applying the resulting changes.
How it connects
Connects infrastructure as code, configuration management, Terraform, Puppet, procedural programming, and state management.

Also explained in

Compare how 14 books explain declarative programming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the CCNA Exam: Volume 2 Advanced Networking and Security. The section links point to the parts of the book it draws on.