Skip to content

Latest commit

 

History

History
168 lines (137 loc) · 5.92 KB

File metadata and controls

168 lines (137 loc) · 5.92 KB
layout ns1
page_title NS1: ns1_zone
sidebar_current docs-ns1-resource-zone
description Provides a NS1 Zone resource.

ns1_zone

Provides a NS1 DNS Zone resource. This can be used to create, modify, and delete zones.

Example Usage

# Create a new DNS zone
resource "ns1_zone" "example" {
  zone = "terraform.example.io"
  ttl  = 600
}

# Create a new primary zone
resource "ns1_zone" "example_primary" {
  zone     = "terraform-primary.example.io"
  secondaries {
    ip     = "2.2.2.2"
  }
  secondaries {
    ip     = "3.3.3.3"
    port   = 5353
    notify = true
  }
}

# Create a new secondary zone
resource "ns1_zone" "example_primary" {
  zone     = "terraform-primary.example.io"
  primary  = "2.2.2.2"
  additional_primaries = ["3.3.3.3", "4.4.4.4"]
}

# Create a zone with NS record managed by terraform
resource "ns1_zone" "example_ns_management" {
  zone                   = "terraform-ns.example.io"
  autogenerate_ns_record = false
}
# Use the dns_servers attribute to set answers for our NS1-provided nameservers
resource "ns1_record" "example_ns_management_ns" {
  zone   = ns1_zone.example_ns_management.zone
  domain = ns1_zone.example_ns_management.zone
  type   = "NS"

  dynamic "answers" {
    for_each = split(",", ns1_zone.example_ns_management.dns_servers)
    content {
      answer = answers.value
    }
  }

  answers {
    answer = "some_other_nameserver.example.com"
  }
}

# Create a new secondary zone with TSIG enabled
resource "ns1_zone" "example_tsig" {
  zone     = "terraform-tsig.example.io"
  primary  = "1.1.1.1"
  tsig = {
    enabled = true
    name = "terraform_tsigKey"
    hash = "hmac-sha256"
    key = "Ok1qR5IW1ajVka5cHPEJQIXfLyx5V3PSkFBROAzOn21JumDq6nIpoj6H8rfj5Uo+Ok55ZWQ0Wgrf302fDscHLA=="
  }
}

Argument Reference

The following arguments are supported:

  • zone - (Required) The domain name of the zone.
  • link - (Optional) The target zone(domain name) to link to.
  • primary - (Optional) The primary zones' IPv4 address. This makes the zone a secondary. Conflicts with secondaries.
  • additional_primaries - (Optional) List of additional IPv4 addresses for the primary zone. Conflicts with secondaries.
  • ttl - (Optional/Computed) The SOA TTL.
  • refresh - (Optional/Computed) The SOA Refresh. Conflicts with primary and additional_primaries (default must be accepted).
  • retry - (Optional/Computed) The SOA Retry. Conflicts with primary and additional_primaries (default must be accepted).
  • expiry - (Optional/Computed) The SOA Expiry. Conflicts with primary and additional_primaries (default must be accepted).
  • nx_ttl - (Optional/Computed) The SOA NX TTL. Conflicts with primary and additional_primaries (default must be accepted).
  • dnssec - (Optional/Computed) Whether or not DNSSEC is enabled for the zone. Note that DNSSEC must be enabled on the account by support for this to be set to true.
  • networks - (Optional/Computed) List of network IDs for which the zone is available. If no network is provided, the zone will be created in network 0, the primary NS1 Global Network.
  • secondaries - (Optional) List of secondary servers. This makes the zone a primary. Conflicts with primary and additional_primaries. Secondaries is documented below.
  • autogenerate_ns_record - (Optional, default: true). If set to false, clears the autogenerated NS record on zone creation. This allows an automated workflow for creating zones with the NS record in terraform state. See above for an example. Note that this option only has an effect when a zone is being created.
  • tags - map of tags in the form of "key" = "value" where both key and value are strings
  • tsig - TSIG is documented below

Secondaries

A zone can have zero or more secondaries. Note how this is implemented in the example above. A secondary has the following fields:

  • ip - (Required) IPv4 address of the secondary server.
  • port - (Optional, default: 53) Port of the the secondary server.
  • notify - (Optional, default: false) Whether we send NOTIFY messages to the secondary host when the zone changes. Default false.
  • networks - (Computed) - List of network IDs (int) for which the zone should be made available. Default is network 0, the primary NSONE Global Network. Normally, you should not have to worry about this.

TSIG

A secondary zone can have the TSIG enabled to use a TSIG Key. TSIG has the following fields:

  • enabled - (Required) Enables the use of TSIG key.
  • name - (Required) TSIG key name.
  • hash - (Required) Hash algorithm used.
  • key - (Required) The TSIG key secret.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • dns_servers - (Computed) Authoritative Name Servers.
  • hostmaster - (Computed) The SOA Hostmaster.

A note on making Primary or Secondary changes to zones

Switching a zone to being a secondary forces a new resource. In other words, the zone will first be destroyed, then recreated as a secondary. Editing or removing the primary key, or directly changing a secondary zone to a primary (by removing the primary and additional_primaries keys, and setting secondaries) is supported "in place". However, in these situations we do not alter records on the zone. You may need to amend records, or finagle them into Terraform state. As a particular example, if you change a secondary zone to be primary (or just not-a-secondary) before a zone transfer has occurred, you can end up with no records on the zone.

Currently, this provider does not support zones being both Primary and Secondary. If that functionality is important for your workflow, please open an issue or contact support, so we can prioritize the work accordingly.

Import

terraform import ns1_zone.<name> <zone>

So for the example above:

terraform import ns1_zone.example terraform.example.io

NS1 Documentation

Zone Api Docs