Summary
Add a pihole_password resource to manage the Pi-hole admin password through Terraform, with built-in handling for the password propagation delay.
Background
Currently, the Pi-hole admin password must be set outside of Terraform (e.g., via Ansible or CLI). This creates a dependency ordering challenge:
- Ansible creates Pi-hole instance
- Ansible sets password via
pihole setpassword
- Terraform authenticates to create DNS records
Additionally, there's a ~3 second propagation delay after pihole setpassword before the password is active in the API. If Terraform runs too quickly after password change, authentication fails.
Proposed Solution
Add a pihole_password resource:
resource "pihole_password" "admin" {
password = var.pihole_password
}
Implementation Details
- Set password via API - Use the Pi-hole v6 API endpoint to set the password
- Built-in delay - After setting password, wait ~3-5 seconds before marking resource as created
- Implicit dependency - Other resources (like
pihole_dns_record) should implicitly depend on password being set
- Idempotency - Check if current password matches before updating (via auth test)
API Reference
Pi-hole v6 stores password in webserver.api.password config. The CLI uses:
pihole-FTL --config webserver.api.password "newpassword"
The equivalent REST API call would need to be identified.
Benefits
- Single source of truth for Pi-hole configuration in Terraform
- Proper dependency ordering handled automatically
- No race conditions between password set and subsequent API calls
- Eliminates need for Ansible/CLI password management
Environment
- Pi-hole: v6.3 / FTL v6.4.1
- Provider: poindexter12/pihole v1.0.0
- Terraform: v1.14.1
Summary
Add a
pihole_passwordresource to manage the Pi-hole admin password through Terraform, with built-in handling for the password propagation delay.Background
Currently, the Pi-hole admin password must be set outside of Terraform (e.g., via Ansible or CLI). This creates a dependency ordering challenge:
pihole setpasswordAdditionally, there's a ~3 second propagation delay after
pihole setpasswordbefore the password is active in the API. If Terraform runs too quickly after password change, authentication fails.Proposed Solution
Add a
pihole_passwordresource:Implementation Details
pihole_dns_record) should implicitly depend on password being setAPI Reference
Pi-hole v6 stores password in
webserver.api.passwordconfig. The CLI uses:pihole-FTL --config webserver.api.password "newpassword"The equivalent REST API call would need to be identified.
Benefits
Environment