---
title: "infoblox_mx_record Data Source"
canonical: "https://docs.infoblox.com/space/ipamdriverterraform/216039759/infoblox_mx_record%20Data%20Source"
format: markdown
---
Use the data source to retrieve the following information for an MX record, which is managed by a NIOS server:

| **Parameter** | **Description** | **Example** |
| --- | --- | --- |
| `dns_view` | The DNS view in which the record's zone exists. | `dnsview1` |
| `fqdn` | The DNS zone (as a fully qualified domain name) to which a mail exchange host is assigned. | `samplemx.demo.com` |
| `mail_exchanger` | The mail exchange host's fully qualified domain name. | `mx1.secure-mail-provider.net` |
| `preference` | The preference number (0-65535) for this record. | `6000` |
| `zone` | The zone that contains the record in the specified DNS view. | `test.com` |
| `ttl` | The Time to Live value of the record, in seconds. | `3600` |
| `comment` | A description of the record. This is a regular comment. | `spare node for the service` |
| `ext_attrs` | The set of extensible attributes of the record, if any. The content is formatted as a string of JSON map. | `"{\"Owner\":\"State Library\", \"Expires\":\"never\"}` |

To retrieve information about MX records that match the specified filters, use the `filters` argument and specify the parameters mentioned in the below table. These are the searchable parameters of the corresponding object in Infoblox NIOS WAPI. If you do not specify any parameter, the data source retrieves information about all MX records in the NIOS Grid.

The following table describes the parameters you can define in an `infoblox_mx_record` data source block:

| **Parameter** | **Alias*** | **Description** |
| --- | --- | --- |
| `name` | `fqdn` | Specifies the fully qualified domain name of the DNS zone to which a mail exchange host is assigned. |
| `mail exchenger` | Required | Specifies the mail exchange host's fully qualified domain name.  
Example: `big-company.com` |
| `preference` | Required | Specifies the preference number (0-65535) for the record |
| `view` | `dns_view` | Specifies the DNS view in which the zone’s record exists.  
If a value is not specified, matching objects are retrieved from all DNS views in the NIOS Grid. |
| `zone` | `zone` | Specifies the zone that contains the record. |
| `comment` | `comment` | Describes the record. |
| Extensible Attributes | - | Specifies the extensible attributes specified for the record. You must specify the key/value pair within the `filters` argument.  
Example:  
`filters = {`  
`"*Site" = "some test site"`  
`}` |

*Aliases are the parameter names used in the prior releases of Infoblox IPAM Plug-In for Terraform. Do not use the alias names for parameters in the data source blocks. Using them can result in error scenarios.

## Example of the MX Record Data Source Block

The following example defines a data source of type `infoblox_mx_record` and the name "`ds2`", which is configured in a Terraform file. You can reference this data source and retrieve information about it.

`resource "infoblox_mx_record" "rec2" {`  
`  dns_view = "nondefault_dnsview1"`  
`  fqdn = "example2.org"`  
`  mail_exchanger = "sample.test.com"`  
`  preference = 40`  
`  comment = "example MX-record"`  
`  ttl = 120`  
`  ext_attrs = jsonencode({`  
`    "Location" = "Las Vegas"`  
`  })`  
`}`  
  
`data "infoblox_mx_record" "ds2" {`  
`  filters = {`  
`    view = "nondefault_dnsview1"`  
`    name = "rec2.example2.org"`  
`    mail_exchanger = "sample.test.com"`  
`  }`  
`  // This is just to ensure that the record has been be created`  
`  // using 'infoblox_mx_record' resource block before the data source will be queried.`  
`  depends_on = [infoblox_mx_record.rec2]`  
`}`

`output "mx_rec_res" {`  
`  value = data.infoblox_mx_record.ds2`  
`}`

`// accessing individual field in results`  
`output "mx_rec_name" {`  
`  value = data.infoblox_mx_record.ds2.results.0.fqdn //zero represents index of json object from results list`  
`}`  


`// accessing MX-Record through EAs`  
`data "infoblox_mx_record" "mx_rec_ea" {`  
`    filters = {`  
`      "*Location" = "California"`  
`      "*Location!" = "Florida"`  
`      "*TestEA" = "automate"`  
`    }`  
`}`

`// retrieves matching MX-Records with EA, if any`  
`output "mx_rec_out" {`  
`    value = data.infoblox_mx_record.mx_rec_ea`  
`}`