-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DNS record data source #1906
Add DNS record data source #1906
Conversation
changelog detected ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've added some notes inline; we probably need to work out how we want to search/filter for a single record before going any further.
For the search, what about using the list DNS record API call (https://api.cloudflare.com/#dns-records-for-a-zone-list-dns-records) but applying a filter of hostname and a type of "A" unless set? Could even make the page response only be 1 record on 1 page. The only case where I can see that not working would be MX records, given they have a priority with likely the same hostname. |
yep, where possible, offload the actual searching the Cloudflare API and don't do it in the data source itself. check out |
This is what I devised records, err := client.DNSRecords(ctx, zoneID, searchRecord)
if err != nil {
return diag.FromErr(fmt.Errorf("error listing DNS records: %w", err))
}
if len(records) == 0 {
return diag.Errorf("didn't get any DNS records for hostname: %s", searchRecord.Name)
}
if len(records) != 1 && !contains([]string{"MX", "URI"}, searchRecord.Type) {
return diag.Errorf("only wanted 1 DNS record. Got %d records", len(records))
} else {
for _, record := range records {
if record.Priority == searchRecord.Priority {
records = []cloudflare.DNSRecord{record}
break
}
}
if len(records) != 1 {
return diag.Errorf("unable to find single record for %s type %s", searchRecord.Name, searchRecord.Type)
}
} I can't do the page limiting as the cloudflare-go function only search with a DNS record and returns all matching records. The logic behind it is
|
…provider-cloudflare into record-data-source
This functionality has been released in v3.24.0 of the Terraform Cloudflare Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
Adds a data source for an existing DNS record
Resolves #1904