2015-04-30 05:32:34 +00:00
---
layout: "google"
page_title: "Google: google_dns_record_set"
sidebar_current: "docs-google-dns-record-set"
description: |-
Manages a set of DNS records within Google Cloud DNS.
---
# google\_dns\_record\_set
2018-01-17 19:19:55 +00:00
Manages a set of DNS records within Google Cloud DNS. For more information see [the official documentation ](https://cloud.google.com/dns/records/ ) and
[API ](https://cloud.google.com/dns/api/v1/resourceRecordSets ).
2015-04-30 05:32:34 +00:00
2017-10-24 21:43:35 +00:00
~> **Note:** The Google Cloud DNS API requires NS records be present at all
times. To accommodate this, when creating NS records, the default records
Google automatically creates will be silently overwritten. Also, when
destroying NS records, Terraform will not actually remove NS records, but will
report that it did.
2015-04-30 05:32:34 +00:00
## Example Usage
2017-08-01 16:59:27 +00:00
### Binding a DNS name to the ephemeral IP of a new instance:
2015-04-30 05:32:34 +00:00
2017-04-17 10:17:54 +00:00
```hcl
2017-08-01 16:59:27 +00:00
resource "google_dns_record_set" "frontend" {
name = "frontend.${google_dns_managed_zone.prod.dns_name}"
type = "A"
ttl = 300
managed_zone = "${google_dns_managed_zone.prod.name}"
rrdatas = ["${google_compute_instance.frontend.network_interface.0.access_config.0.assigned_nat_ip}"]
}
2015-04-30 05:32:34 +00:00
resource "google_compute_instance" "frontend" {
2016-04-10 21:34:15 +00:00
name = "frontend"
machine_type = "g1-small"
zone = "us-central1-b"
2017-09-29 23:04:52 +00:00
boot_disk {
initialize_params {
2018-08-28 23:58:27 +00:00
image = "debian-cloud/debian-9"
2017-09-29 23:04:52 +00:00
}
2016-04-10 21:34:15 +00:00
}
network_interface {
2017-02-18 22:48:50 +00:00
network = "default"
access_config = {}
2016-04-10 21:34:15 +00:00
}
2015-04-30 05:32:34 +00:00
}
2017-02-18 22:48:50 +00:00
2015-04-30 05:32:34 +00:00
resource "google_dns_managed_zone" "prod" {
2016-04-10 21:34:15 +00:00
name = "prod-zone"
dns_name = "prod.mydomain.com."
2015-04-30 05:32:34 +00:00
}
2017-08-01 16:59:27 +00:00
```
2015-04-30 05:32:34 +00:00
2018-04-09 21:46:42 +00:00
### Adding an A record
```hcl
resource "google_dns_record_set" "a" {
name = "backend.${google_dns_managed_zone.prod.dns_name}"
managed_zone = "${google_dns_managed_zone.prod.name}"
type = "A"
ttl = 300
rrdatas = ["8.8.8.8"]
}
resource "google_dns_managed_zone" "prod" {
name = "prod-zone"
dns_name = "prod.mydomain.com."
}
```
### Adding an MX record
```hcl
resource "google_dns_record_set" "mx" {
name = "${google_dns_managed_zone.prod.dns_name}"
managed_zone = "${google_dns_managed_zone.prod.name}"
type = "MX"
ttl = 3600
rrdatas = [
"1 aspmx.l.google.com.",
"5 alt1.aspmx.l.google.com.",
"5 alt2.aspmx.l.google.com.",
"10 alt3.aspmx.l.google.com.",
"10 alt4.aspmx.l.google.com."
]
}
resource "google_dns_managed_zone" "prod" {
name = "prod-zone"
dns_name = "prod.mydomain.com."
}
```
### Adding an SPF record
2017-08-01 16:59:27 +00:00
2018-05-01 22:22:29 +00:00
Quotes (`""`) must be added around your `rrdatas` for a SPF record. Otherwise `rrdatas` string gets split on spaces.
2017-08-01 16:59:27 +00:00
```hcl
resource "google_dns_record_set" "spf" {
2016-04-10 21:34:15 +00:00
name = "frontend.${google_dns_managed_zone.prod.dns_name}"
2017-08-01 16:59:27 +00:00
managed_zone = "${google_dns_managed_zone.prod.name}"
type = "TXT"
2016-04-10 21:34:15 +00:00
ttl = 300
2017-08-01 16:59:27 +00:00
rrdatas = ["\"v=spf1 ip4:111.111.111.111 include:backoff.email-example.com -all\""]
}
2016-04-10 21:34:15 +00:00
2017-08-01 16:59:27 +00:00
resource "google_dns_managed_zone" "prod" {
name = "prod-zone"
dns_name = "prod.mydomain.com."
2015-04-30 05:32:34 +00:00
}
```
## Argument Reference
The following arguments are supported:
2016-04-10 21:34:15 +00:00
* `managed_zone` - (Required) The name of the zone in which this record set will
reside.
2015-04-30 05:32:34 +00:00
* `name` - (Required) The DNS name this record set will apply to.
2016-04-10 21:34:15 +00:00
* `rrdatas` - (Required) The string data for the records in this record set
2017-08-01 16:59:27 +00:00
whose meaning depends on the DNS type. For TXT record, if the string data contains spaces, add surrounding `\"` if you don't want your string to get split on spaces.
2015-04-30 05:32:34 +00:00
* `ttl` - (Required) The time-to-live of this record set (seconds).
2016-04-10 21:34:15 +00:00
* `type` - (Required) The DNS record set type.
- - -
2018-03-12 20:59:47 +00:00
* `project` - (Optional) The ID of the project in which the resource belongs. If it
2016-04-10 21:34:15 +00:00
is not provided, the provider project is used.
2015-04-30 05:32:34 +00:00
## Attributes Reference
2016-04-10 21:34:15 +00:00
Only the arguments listed above are exposed as attributes.
2018-01-17 19:19:55 +00:00
## Import
DNS record set can be imported using the `zone name` , `record name` and record `type` , e.g.
```
$ terraform import google_dns_record_set.frontend prod-zone/frontend.prod.mydomain.com./A
```
2018-04-09 21:46:42 +00:00
Note: The record name must include the trailing dot at the end.