Reference documentation and code samples for the Cloud DNS API class Google::Cloud::Dns::Zone::Transaction.
DNS Zone Transaction
This object is used by #update when passed a block. These
methods are used to update the records that are sent to the Google
Cloud DNS API.
Inherits
Object
Example
require"google/cloud/dns"dns=Google::Cloud::Dns.newzone=dns.zone"example-com"zone.updatedo|tx|tx.add"example.com.","A",86400,"1.2.3.4"tx.remove"example.com.","TXT"tx.replace"example.com.","MX",86400,["10 mail1.example.com.","20 mail2.example.com."]tx.modify"www.example.com.","CNAME"do|cname|cname.ttl=86400# only change the TTLendend
Methods
#add
defadd(name,type,ttl,data)
Adds a record to the Zone.
Parameters
name (String) — The owner of the record. For example:
example.com..
type (String) — The identifier of a supported record
type.
For example: A, AAAA, CNAME, MX, or TXT.
ttl (Integer) — The number of seconds that the record can be
cached by resolvers.
data (String, Array<String>) — The resource record data, as
determined by type and defined in RFC 1035 (section
5) and RFC 1034
(section
3.6.1). For
example: 192.0.2.1 or example.com..
require"google/cloud/dns"dns=Google::Cloud::Dns.newzone=dns.zone"example-com"zone.updatedo|tx|tx.modify"www.example.com.","CNAME"do|cname|cname.ttl=86400# only change the TTLendend
#remove
defremove(name,type)
Removes records from the Zone. The records are looked up before they
are removed.
Parameters
name (String) — The owner of the record. For example:
example.com..
type (String) — The identifier of a supported record
type.
For example: A, AAAA, CNAME, MX, or TXT.
Replaces existing records on the Zone. Records matching the name
and type are replaced.
Parameters
name (String) — The owner of the record. For example:
example.com..
type (String) — The identifier of a supported record
type.
For example: A, AAAA, CNAME, MX, or TXT.
ttl (Integer) — The number of seconds that the record can be
cached by resolvers.
data (String, Array<String>) — The resource record data, as
determined by type and defined in RFC 1035 (section
5) and RFC 1034
(section
3.6.1). For
example: 192.0.2.1 or example.com..
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud DNS API - Class Google::Cloud::Dns::Zone::Transaction (v1.1.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.1.0 (latest)](/ruby/docs/reference/google-cloud-dns/latest/Google-Cloud-Dns-Zone-Transaction)\n- [1.0.0](/ruby/docs/reference/google-cloud-dns/1.0.0/Google-Cloud-Dns-Zone-Transaction)\n- [0.37.0](/ruby/docs/reference/google-cloud-dns/0.37.0/Google-Cloud-Dns-Zone-Transaction)\n- [0.36.1](/ruby/docs/reference/google-cloud-dns/0.36.1/Google-Cloud-Dns-Zone-Transaction)\n- [0.35.1](/ruby/docs/reference/google-cloud-dns/0.35.1/Google-Cloud-Dns-Zone-Transaction) \nReference documentation and code samples for the Cloud DNS API class Google::Cloud::Dns::Zone::Transaction.\n\nDNS Zone Transaction\n--------------------\n\nThis object is used by [#update](/ruby/docs/reference/google-cloud-dns/latest/Google-Cloud-Dns-Zone#Google__Cloud__Dns__Zone_update_instance_ \"Google::Cloud::Dns::Zone#update (method)\") when passed a block. These\nmethods are used to update the records that are sent to the Google\nCloud DNS API. \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/dns\"\n\ndns = Google::Cloud::Dns.new\nzone = dns.zone \"example-com\"\nzone.update do |tx|\n tx.add \"example.com.\", \"A\", 86400, \"1.2.3.4\"\n tx.remove \"example.com.\", \"TXT\"\n tx.replace \"example.com.\", \"MX\", 86400, [\"10 mail1.example.com.\",\n \"20 mail2.example.com.\"]\n tx.modify \"www.example.com.\", \"CNAME\" do |cname|\n cname.ttl = 86400 # only change the TTL\n end\nend\n```\n\nMethods\n-------\n\n### #add\n\n def add(name, type, ttl, data)\n\nAdds a record to the Zone. \n**Parameters**\n\n- **name** (String) --- The owner of the record. For example: `example.com.`.\n- **type** (String) --- The identifier of a [supported record\n type](https://cloud.google.com/dns/what-is-cloud-dns). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.\n- **ttl** (Integer) --- The number of seconds that the record can be cached by resolvers.\n- **data** (String, Array\\\u003cString\\\u003e) --- The resource record data, as determined by `type` and defined in [RFC 1035 (section\n 5)](http://tools.ietf.org/html/rfc1035#section-5) and [RFC 1034\n (section\n 3.6.1)](http://tools.ietf.org/html/rfc1034#section-3.6.1). For example: `192.0.2.1` or `example.com.`.\n**Example** \n\n```ruby\nrequire \"google/cloud/dns\"\n\ndns = Google::Cloud::Dns.new\nzone = dns.zone \"example-com\"\nzone.update do |tx|\n tx.add \"example.com.\", \"A\", 86400, \"1.2.3.4\"\nend\n```\n\n### #modify\n\n def modify(name, type, &block) { |record| ... }\n\nModifies records on the Zone. Records matching the `name` and `type`\nare yielded to the block where they can be modified. \n**Parameters**\n\n- **name** (String) --- The owner of the record. For example: `example.com.`.\n- **type** (String) --- The identifier of a [supported record\ntype](https://cloud.google.com/dns/what-is-cloud-dns). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`. \n**Yields**\n\n- (record) --- a block yielding each matching record \n**Yield Parameter**\n\n- **record** ([Record](./Google-Cloud-Dns-Record)) --- the record to be modified\n**Example** \n\n```ruby\nrequire \"google/cloud/dns\"\n\ndns = Google::Cloud::Dns.new\nzone = dns.zone \"example-com\"\nzone.update do |tx|\n tx.modify \"www.example.com.\", \"CNAME\" do |cname|\n cname.ttl = 86400 # only change the TTL\n end\nend\n```\n\n### #remove\n\n def remove(name, type)\n\nRemoves records from the Zone. The records are looked up before they\nare removed. \n**Parameters**\n\n- **name** (String) --- The owner of the record. For example: `example.com.`.\n- **type** (String) --- The identifier of a [supported record\n type](https://cloud.google.com/dns/what-is-cloud-dns). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.\n**Example** \n\n```ruby\nrequire \"google/cloud/dns\"\n\ndns = Google::Cloud::Dns.new\nzone = dns.zone \"example-com\"\nzone.update do |tx|\n tx.remove \"example.com.\", \"TXT\"\nend\n```\n\n### #replace\n\n def replace(name, type, ttl, data)\n\nReplaces existing records on the Zone. Records matching the `name`\nand `type` are replaced. \n**Parameters**\n\n- **name** (String) --- The owner of the record. For example: `example.com.`.\n- **type** (String) --- The identifier of a [supported record\n type](https://cloud.google.com/dns/what-is-cloud-dns). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.\n- **ttl** (Integer) --- The number of seconds that the record can be cached by resolvers.\n- **data** (String, Array\\\u003cString\\\u003e) --- The resource record data, as determined by `type` and defined in [RFC 1035 (section\n 5)](http://tools.ietf.org/html/rfc1035#section-5) and [RFC 1034\n (section\n 3.6.1)](http://tools.ietf.org/html/rfc1034#section-3.6.1). For example: `192.0.2.1` or `example.com.`.\n**Example** \n\n```ruby\nrequire \"google/cloud/dns\"\n\ndns = Google::Cloud::Dns.new\nzone = dns.zone \"example-com\"\nzone.update do |tx|\n tx.replace \"example.com.\",\n \"MX\", 86400,\n [\"10 mail1.example.com.\",\n \"20 mail2.example.com.\"]\nend\n```"]]