Materiały:
- The Zen of Ansible - Declarative is better than imperative – most of the time
- Provisioners Without a Resource
- Imperative vs Declarative IaC: Ansible and Terraform
- Declarative vs. Imperative Infrastructure As Code
Przykłady:
- Ansible - deklaratywny moduł:
- name: Ensure nginx is installed
package:
name: nginx
state: present
- Ansible - imperatywny moduł:
- name: Create a directory
command: mkdir /path/to/directory
- Terraform - deklaratywny zasób:
resource "aws_instance" "this" {
ami = "ami-12345678901234567"
instance_type = "t2.micro"
}
- Terraform - imperatywny zasób:
resource "null_resource" "this" {
provisioner "local-exec" {
command = "echo 'This is a provisioner script'"
}
depends_on = [aws_instance.this]
}