A Terraform provider for managing Pi-hole resources

terraform-provider-pihole

test workflow status terraform registry

Pi-hole is an ad blocking application which acts as a DNS proxy that returns empty responses when DNS requests for known advertisement domains are made from your devices. It has a number of additional capabilities like optional DHCP server capabilities, specific allow/deny profiles for specific clients, and a neat UI with a ton of information regarding your internet traffic.

Pi-hole is an open source project and can be found at https://github.com/pi-hole/pi-hole.

Provider Development

There are a few ways to configure local providers. See the somewhat obscure Terraform plugin installation documentation for a potential recommended way.

One way to run a local provider is to build the project, move it to the Terraform plugins directory and then use a required_providers block to note the address and version.

# from the project root
go build .

# Note the `/darwin_amd64/` path portion targets a Mac with an AMD64 processor, 
# see https://github.com/ryanwholey/terraform-provider-pihole/blob/main/.goreleaser.yml#L18-L27
# for possible supported combinations

mkdir -p ~/.terraform.d/plugins/terraform.local/local/pihole/0.0.1/darwin_amd64/

cp terraform-provider-pihole ~/.terraform.d/plugins/terraform.local/local/pihole/0.0.1/darwin_amd64/terraform-provider-pihole_v0.0.1

In the Terraform workspace, use a required_providers block to target the locally built provider

terraform {
  required_providers {
    pihole = {
      source  = "terraform.local/local/pihole"
      version = "0.0.1"
    }
  }
}

Testing

Unit tests can be ran with a simple command

make test

Acceptance can run against any Pi-hole deployment given that PIHOLE_URL and PIHOLE_PASSWORD are set in the shell. A dockerized Pi-hole can be ran via the docker-compose file provided in the project root.

# from the project root
docker-compose up -d --build

export PIHOLE_URL=http://localhost:8080
export PIHOLE_PASSWORD=test

make testall

Docs

Documentation is auto-generated via tfplugindocs from description fields within the provider package, as well as examples and templates from the examples/ and templates/ folders respectively.

To generate the docs, ensure that tfplugindocs is installed, then run

make docs
Comments
  • invalid character '<' looking for beginning of value

    invalid character '<' looking for beginning of value

    I was just trying to automate DNS entry creation as I create VMs.

    Error

    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
      + create
    
    Terraform will perform the following actions:
    
      # pihole_dns_record.record will be created
      + resource "pihole_dns_record" "record" {
          + domain = "hoku-1"
          + id     = (known after apply)
          + ip     = "192.168.86.190"
        }
    
    ╷
    │ Error: invalid character '<' looking for beginning of value
    │
    │   with pihole_dns_record.record,
    │   on homelab.tf line 79, in resource "pihole_dns_record" "record":
    │   79: resource "pihole_dns_record" "record" {
    │
    ╵
    

    Details

    ❯ tf --version
    Terraform v1.1.5
    on darwin_amd64
    + provider registry.terraform.io/hashicorp/random v3.1.0
    + provider registry.terraform.io/ryanwholey/pihole v0.0.9
    + provider registry.terraform.io/telmate/proxmox v2.9.3
    
    # homelab.tf
    resource "pihole_dns_record" "record" {
      domain = "hoku-1"
      ip     = "192.168.86.190"
    }
    
    # main.tf
    terraform {
      backend "s3" {}
    
      required_providers {
        pihole = {
          source = "ryanwholey/pihole"
          version = "0.0.9"
        }
        proxmox = {
          source  = "telmate/proxmox"
          version = "2.9.3"
        }
      }
    }
    
    ...
    
    provider "pihole" {
      url = var.pihole_url
      password = var.pihole_password
    }
    
    # vars.tf
    # variables passed in via a .env file
    variable "pihole_url" {
      type = string
      description = "URL for pihole"
      sensitive = true
    }
    
    variable "pihole_password" {
      type = string
      description = "Password for pihole"
      sensitive = true
    }
    

    I've already made sure I'm using the admin password used for logging into pihole (as was stated in #22). Not entirely sure what's going on because I think I've set everything up correctly. I am using a traefik reverse proxy in front of pihole for HTTPS so the url I pass into that variable ends with /index.php?login. That was the only way I could get it to not error out trying to connect. I see the following error if I try to omit that bit.

    # when using "https://pihole.internal.mydomain.dev" instead of "https://pihole.internal.mydomain.dev/index.php?login"
    ╷
    │ Error: login failed: session ID not found in response
    │
    │   with provider["registry.terraform.io/ryanwholey/pihole"],
    │   on main.tf line 22, in provider "pihole":
    │   22: provider "pihole" {
    │
    ╵
    
  • invalid character 'E' looking for beginning of value

    invalid character 'E' looking for beginning of value

    Hi there, thanks for creating this module, just the thing I was looking for!

    Unfortunately I've encountered the following issue when trying to provision a DNS record. Any help appreciated!

    Error

    
    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
      + create
    
    Terraform will perform the following actions:
    
      # pihole_dns_record.record will be created
      + resource "pihole_dns_record" "record" {
          + domain = "example.local"
          + id     = (known after apply)
          + ip     = "192.168.0.69"
        }
    
    Plan: 1 to add, 0 to change, 0 to destroy.
    
    Do you want to perform these actions?
      Terraform will perform the actions described above.
      Only 'yes' will be accepted to approve.
    
      Enter a value: yes
    
    pihole_dns_record.record: Creating...
    ╷
    │ Error: invalid character 'E' looking for beginning of value
    │
    │   with pihole_dns_record.record,
    │   on main.tf line 10, in resource "pihole_dns_record" "record":
    │   10: resource "pihole_dns_record" "record" {
    │
    ╵
    

    Config

    My setup looks a little bit like this, running Terraform in WSL

    $ terraform version
    Terraform v1.1.4
    on linux_amd64
    + provider registry.terraform.io/ryanwholey/pihole v0.0.7
    
    resource "pihole_dns_record" "record" {
      domain = "example.local"
      ip     = "192.168.0.69"
    }
    
    variable pihole_api_token {
      type = string
      description = "The API token for authenticating with the PiHole API"
    }
    
    terraform {
      required_providers {
        pihole = {
          source  = "ryanwholey/pihole"
          version = "0.0.7"
        }
      }
    }
    
    provider "pihole" {
      # Configuration options
      url      = "http://pihole.local"
      password = var.pihole_api_token
    }
    
  • Support import and refresh operations

    Support import and refresh operations

    In order to get this to work (which it otherwise does spectacularly) I had to remove all pre-existing configured CNAME and DNS entries. I had attempted to update using -refresh-only and no import information is listed in the docs. I'm not even sure what would be required to get that working.

    https://learn.hashicorp.com/tutorials/terraform/refresh

  • Bump goreleaser/goreleaser-action from 2.7.0 to 2.8.0

    Bump goreleaser/goreleaser-action from 2.7.0 to 2.8.0

    Bumps goreleaser/goreleaser-action from 2.7.0 to 2.8.0.

    Release notes

    Sourced from goreleaser/goreleaser-action's releases.

    v2.8.0

    What's Changed

    Full Changelog: https://github.com/goreleaser/goreleaser-action/compare/v2.6.1...v2.8.0

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Error with Pi-Hole v5.12

    Error with Pi-Hole v5.12

    Hello,

    I got this error since the Update pi-hole v5.12 and AdminLTE v5.14 Error: failed to fetch custom DNS records: failed to parse customDNS list body: json: cannot unmarshal array into Go value of type pihole.dnsRecordListResponse

    regards

  • chore: Check for updates on gha using dependabot monthly

    chore: Check for updates on gha using dependabot monthly

    This will check for updates on any github action which this project uses.

    https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot

  • chore: Bump terraform-plugin-* and testify

    chore: Bump terraform-plugin-* and testify

    github.com/hashicorp/terraform-plugin-docs v0.5.0 -> v0.8.1
    github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1 -> v2.16.0
    github.com/stretchr/testify v1.7.0 -> v1.7.1
    
  • Support API token authentication

    Support API token authentication

    There has been some movement on the Pi-hole side to support API operations via API token!

    It looks like it currently supports add/delete/list custom A & CNAME records, although the API response still looks to be in flux.

    Might be time to move the Pi-hole client out to its own repo so it can be updated and released independently.

  • Bump actions/checkout from 2.3.4 to 2.3.5

    Bump actions/checkout from 2.3.4 to 2.3.5

    Bumps actions/checkout from 2.3.4 to 2.3.5.

    Release notes

    Sourced from actions/checkout's releases.

    v2.3.5

    Update dependencies

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • build(deps): bump amannn/action-semantic-pull-request from 4 to 5

    build(deps): bump amannn/action-semantic-pull-request from 4 to 5

    Bumps amannn/action-semantic-pull-request from 4 to 5.

    Release notes

    Sourced from amannn/action-semantic-pull-request's releases.

    v5.0.0

    5.0.0 (2022-10-11)

    ⚠ BREAKING CHANGES

    • Enum options need to be newline delimited (to allow whitespace within them) (#205)

    Features

    • Enum options need to be newline delimited (to allow whitespace within them) (#205) (c906fe1)

    v4.6.0

    4.6.0 (2022-09-26)

    Features

    • Provide error messages as outputs.error_message (#194) (880a3c0)

    v4.5.0

    4.5.0 (2022-05-04)

    Features

    v4.4.0

    4.4.0 (2022-04-22)

    Features

    • Add options to pass custom regex to conventional-commits-parser (#177) (956659a)

    v4.3.0

    4.3.0 (2022-04-13)

    Features

    • Add ignoreLabels option to opt-out of validation for certain PRs (#174) (277c230)

    v4.2.0

    ... (truncated)

    Changelog

    Sourced from amannn/action-semantic-pull-request's changelog.

    5.0.1 (2022-10-14)

    Bug Fixes

    • Upgrade GitHub Action to use Node v16 (#207) (6282ee3)

    5.0.0 (2022-10-11)

    ⚠ BREAKING CHANGES

    • Enum options need to be newline delimited (to allow whitespace within them) (#205)

    Features

    • Enum options need to be newline delimited (to allow whitespace within them) (#205) (c906fe1)

    4.6.0 (2022-09-26)

    Features

    • Provide error messages as outputs.error_message (#194) (880a3c0)

    4.5.0 (2022-05-04)

    Features

    4.4.0 (2022-04-22)

    Features

    • Add options to pass custom regex to conventional-commits-parser (#177) (956659a)

    4.3.0 (2022-04-13)

    Features

    • Add ignoreLabels option to opt-out of validation for certain PRs (#174) (277c230)

    4.2.0 (2022-02-08)

    Features

    ... (truncated)

    Commits
    • 01d5fd8 chore: Release 5.0.2 [skip ci]
    • 91f4126 fix: Upgrade @actions/core to avoid deprecation warnings (#208)
    • 0a457e2 ci: Fix branch name in dist check (#209)
    • 570204e chore: Release 5.0.1 [skip ci]
    • 6282ee3 fix: Upgrade GitHub Action to use Node v16 (#207)
    • 7c194c2 docs: Use latest major [skip ci]
    • 5369185 chore: Release 5.0.0 [skip ci]
    • c906fe1 feat!: Enum options need to be newline delimited (to allow whitespace within ...
    • b314c1b docs: Improve example for composing outputs (#206)
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • build(deps): bump actions/setup-go from 2 to 3

    build(deps): bump actions/setup-go from 2 to 3

    Bumps actions/setup-go from 2 to 3.

    Release notes

    Sourced from actions/setup-go's releases.

    Update actions/cache version to 3.0.0

    In scope of this release we updated actions/cache package as the new version contains fixes for caching error handling

    v3.0.0

    What's Changed

    Breaking Changes

    With the update to Node 16, all scripts will now be run with Node 16 rather than Node 12.

    This new major release removes the stable input, so there is no need to specify additional input to use pre-release versions. This release also corrects the pre-release versions syntax to satisfy the SemVer notation (1.18.0-beta1 -> 1.18.0-beta.1, 1.18.0-rc1 -> 1.18.0-rc.1).

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-go@v3
        with:
          go-version: '1.18.0-rc.1' 
      - run: go version
    

    Add check-latest input

    In scope of this release we add the check-latest input. If check-latest is set to true, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a Go version will then be downloaded from go-versions repository. By default check-latest is set to false. Example of usage:

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-go@v2
        with:
          go-version: '1.16'
          check-latest: true
      - run: go version
    

    Moreover, we updated @actions/core from 1.2.6 to 1.6.0

    v2.1.5

    In scope of this release we updated matchers.json to improve the problem matcher pattern. For more information please refer to this pull request

    v2.1.4

    What's Changed

    New Contributors

    Full Changelog: https://github.com/actions/setup-go/compare/v2.1.3...v2.1.4

    v2.1.3

    • Updated communication with runner to use environment files rather then workflow commands

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Address breaking changes for 2022.07.1

    Address breaking changes for 2022.07.1

    Tests are failing with image tag >= 2022.07.1. Investigate, and fix. If any fixes require breaking changes to the provider, bump to the next major on release.

OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)
OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)

Terraform Provider OpenAPI This terraform provider aims to minimise as much as possible the efforts needed from service providers to create and mainta

Dec 26, 2022
Terraform provider to help with various AWS automation tasks (mostly all that stuff we cannot accomplish with the official AWS terraform provider)
Terraform provider to help with various AWS automation tasks (mostly all that stuff we cannot accomplish with the official AWS terraform provider)

terraform-provider-awsutils Terraform provider for performing various tasks that cannot be performed with the official AWS Terraform Provider from Has

Dec 8, 2022
Terraform Provider for Azure (Resource Manager)Terraform Provider for Azure (Resource Manager)
Terraform Provider for Azure (Resource Manager)Terraform Provider for Azure (Resource Manager)

Terraform Provider for Azure (Resource Manager) Version 2.x of the AzureRM Provider requires Terraform 0.12.x and later, but 1.0 is recommended. Terra

Oct 16, 2021
Terraform-provider-mailcow - Terraform provider for Mailcow

Terraform Provider Scaffolding (Terraform Plugin SDK) This template repository i

Dec 31, 2021
Terraform-provider-buddy - Terraform Buddy provider For golang

Terraform Provider for Buddy Documentation Requirements Terraform >= 1.0.11 Go >

Jan 5, 2022
Terraform-provider-vercel - Terraform Vercel Provider With Golang

Vercel Terraform Provider Website: https://www.terraform.io Documentation: https

Dec 14, 2022
Terraform-provider-age - Age Terraform Provider with golang

Age Terraform Provider This provider lets you generate an Age key pair. Using th

Feb 15, 2022
Terraform-in-Terraform: Execute Modules directly from the Terraform Registry

Terraform-In-Terraform Provider This provider allows running Terraform in Terraform. This might seem insane but there are some edge cases where it com

Dec 25, 2022
Terraform utility provider for constructing bash scripts that use data from a Terraform module

Terraform Bash Provider This is a Terraform utility provider which aims to robustly generate Bash scripts which refer to data that originated in Terra

Sep 6, 2022
Quick start repository for creating a Terraform provider using terraform-plugin-framework

Terraform Provider Scaffolding (Terraform Plugin Framework) This template repository is built on the Terraform Plugin Framework. The template reposito

Dec 15, 2022
Terraform Provider Scaffolding (Terraform Plugin SDK)

Terraform Provider Scaffolding (Terraform Plugin SDK) This template repository is built on the Terraform Plugin SDK. The template repository built on

Feb 8, 2022
Hashicups-tf-provider - HashiCups Terraform Provider Tutorial

Terraform Provider HashiCups Run the following command to build the provider go

Jan 10, 2022
Terrform Provider for Managing Dkron Jobs

Terraform Provider Dkron Provider for managing https://dkron.io/ jobs. Usage examples terraform { required_providers { dkron = { version =

Oct 17, 2022
A tool to bring existing Azure resources under Terraform's management

Azure Terrafy A tool to bring your existing Azure resources under the management of Terraform. Install go install github.com/magodo/aztfy@latest Usage

Dec 9, 2021
A Terraform module that creates AWS alerts billing for your resources.

terraform-aws-billing-alarms terraform-aws-billing-alarms for project Replace name project to New Project agr 'terraform-aws-billing-alarms' 'new-pr

Oct 20, 2021
A tool to bring existing Azure resources under Terraform's management

Azure Terrafy A tool to bring your existing Azure resources under the management of Terraform. Goal Azure Terrafy imports the resources inside a resou

Jan 1, 2023
Simple tool to move Azure resources based on Terraform state

aztfmove Simple tool to move Azure resources based on Terraform state Goal It is sometimes inevitable to move Azure resources to a new subscription or

Dec 29, 2022
Additional Terraform resources for working with AWS KMS

This is a (hopefully temporary) Terraform provider for working with AWS KMS, particularly for generating data keys. It attempts to correct a deficienc

Nov 29, 2021