Sobes.tech
Junior

What are the two main methods of describing infrastructure using Infrastructure as Code (IaC)?

sobes.tech AI

Answer from AI

Declarative and imperative.

  • Declarative (Declarative IaC): Describes the desired end state of the infrastructure. The IaC tool itself determines the steps to achieve this state. Focus on "what", not on "how".

    Examples of tools: Terraform, AWS CloudFormation, Pulumi.

  • Imperative (Imperative IaC): Describes the sequence of commands or steps needed to configure the infrastructure. Focus on "how", not on "what".

    Examples of tools: Chef, Puppet (classic approach), Ansible (with declarative elements).

Characteristic Declarative approach Imperative approach
Description Desired end state Sequence of steps (script)
User Describes "what" Describes "how"
Idempotency Built into the tool Achieved manually or with plugins
Conciseness Often more concise and readable Can be more verbose
Flexibility Less flexible for complex logic More flexible for non-standard scenarios
Examples Terraform, CloudFormation, Pulumi Chef, Puppet, OpsCode, Ansible