Coder Social home page Coder Social logo

vincentdcmps / terraform-provider-hetznerdns Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yoo/terraform-provider-hetznerdns

0.0 0.0 0.0 128 KB

Terraform provider for Hetzner DNS

License: Mozilla Public License 2.0

Shell 0.58% Go 98.70% Makefile 0.73%

terraform-provider-hetznerdns's Introduction

Terraform Provider for Hetzner DNS

CI Build GitHub release (latest by date) GitHub

Read about what I learnt while implementing this Terraform Provider.

This provider is on published on the Terraform registry.

You can find resources and data sources documentation there or here.

Requirements

  • Terraform > v1.0
  • Go 1.16 (to build the provider plugin)

Installing and Using this Plugin

You most likely want to download the provider from Terraform Registry. If you want or need to install the provider locally, take a look at INSTALL.

Using Provider from Terraform Registry (TF >= 1.0)

This provider is published and available there. If you want to use it, just add the following to your terraform.tf:

terraform {
  required_providers {
    hetznerdns = {
      source = "timohirt/hetznerdns"
      version = "2.1.0"
    }
  }
  required_version = ">= 1.0"
}

Then run terraform init to download the provider.

Authentication

Once installed you have three options to provide the required API token that is used to authenticate at the Hetzner DNS API.

Enter API Token when needed

You can enter it every time you run terraform.

Configure the Provider to take the API Token from a Variable

Add the following to your terraform.tf:

variable "hetznerdns_token" {}

provider "hetznerdns" {
  apitoken = var.hetznerdns_token
}

Now, assign your API token to hetznerdns_token in terraform.tfvars:

hetznerdns_token = "kkd993i3kkmm4m4m4"

You don't have to enter the API token anymore.

Inject the API Token via the Environment

Assign the API token to HETZNER_DNS_API_TOKEN env variable.

export HETZNER_DNS_API_TOKEN=<your api token>

The provider uses this token and you don't have to enter it anymore.

Example Usage

# Specify a zone for a domain (example.com)
resource "hetznerdns_zone" "example_com" {
  name = "example.com"
  ttl  = 60
}

# Handle root (example.com)
resource "hetznerdns_record" "example_com_root" {
  zone_id = hetznerdns_zone.example_com.id
  name    = "@"
  value   = hcloud_server.server_name.ipv4_address
  type    = "A"
  # You only need to set a TTL if it's different from the zone's TTL above
  ttl     = 300
}

# Handle wildcard subdomain (*.example.com)
resource "hetznerdns_record" "all_example_com" {
  zone_id = hetznerdns_zone.example_com.id
  name    = "*"
  value   = hcloud_server.server_name.ipv4_address
  type    = "A"
}

# Handle specific subdomain (books.example.com)
resource "hetznerdns_record" "books_example_com" {
  zone_id = hetznerdns_zone.example_com.id
  name    = "books"
  value   = hcloud_server.server_name.ipv4_address
  type    = "A"
}

# Handle email (MX record with priority 10)
resource "hetznerdns_record" "example_com_email" {
  zone_id = hetznerdns_zone.example_com.id
  name    = "@"
  value   = "10 mail.example.com"
  type    = "MX"
}

# SPF record
resource "hetznerdns_record" "example_com_spf" {
  zone_id = hetznerdns_zone.example_com.id
  name    = "@"
  # The entire value needs to be enclosed in quotes in the zone file, if it contains a space or a quote. For Terraform, you need to escape these "inner" quotes:
  value   = "\"v=spf1 ip4:1.2.3.4 -all\""
  # Or let `jsonencode()` take care of the escaping:
  value   = jsonencode("v=spf1 ip4:1.2.3.4 -all")
  type    = "TXT"
}

terraform-provider-hetznerdns's People

Contributors

timohirt avatar thomaslandauer avatar l-with avatar vincentdcmps avatar frisch12 avatar felixhummel avatar lazyfrosch avatar 90er avatar qbart avatar yoo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.