Skip to content

Conversation

@OJFord
Copy link

@OJFord OJFord commented Jan 5, 2026

It's not presently possible to determine the tailnet/MagicDNS name without a tailscale_device(s) data source and some string manipulation.

Ideally, there'd be an API for this directy, but in lieu of that this commit moves the device list/error (or 0 device) handling/string manipulation into the provider; so that the terraform config can more cleanly and naturally read from:
tailscale_dns_configuration.x.magic_dns_name

to get the name like 'hyperactive-sloth.ts.net' directly.

Copilot AI review requested due to automatic review settings January 5, 2026 01:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new magic_dns_name computed attribute to the tailscale_dns_configuration resource, making it easier to obtain the tailnet's MagicDNS domain name (e.g., 'hyperactive-sloth.ts.net') without requiring a separate tailscale_device(s) data source and manual string manipulation.

Key changes:

  • Added magic_dns_name as a computed string attribute to the DNS configuration schema
  • Implemented logic to extract the MagicDNS domain name from the first device's name when MagicDNS is enabled
  • Updated documentation to reflect the new read-only attribute

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
tailscale/resource_dns_configuration.go Adds the magic_dns_name schema attribute and implements the logic to retrieve and populate it by fetching the device list and extracting the tailnet domain from the first device's name
docs/resources/dns_configuration.md Documents the new magic_dns_name read-only attribute in the schema reference section

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 143 to 165
var magicDNSName string
var diags diag.Diagnostics
if configuration.Preferences.MagicDNS {
devices, err := client.Devices().List(ctx)
if err != nil {
diags = append(diags, diagnosticsError(err, "There is a MagicDNS name, but we failed to get devices")...)
} else if len(devices) == 0 {
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "There is a MagicDNS name, but we failed to get devices",
})
} else {
parts := strings.Split(devices[0].Name, ".")
if len(parts) != 4 {
diags = append(diags, diagnosticsError(err, "There is a MagicDNSName, but unexpected device name format")...)
} else {
magicDNSName = strings.Join(parts[1:], ".")
}
}
}
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new magic_dns_name computed attribute lacks test coverage. The tests should verify that the attribute is properly populated when MagicDNS is enabled and devices are present, and that it handles edge cases like when there are no devices or when MagicDNS is disabled.

Copilot uses AI. Check for mistakes.
Comment on lines 155 to 157
parts := strings.Split(devices[0].Name, ".")
if len(parts) != 4 {
diags = append(diags, diagnosticsError(err, "There is a MagicDNSName, but unexpected device name format")...)
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code assumes all device names have exactly 4 parts when split by "." (hostname.user.tailnet.domain), but this assumption may not always hold. If the device name format varies (e.g., shorter names in certain configurations), the code will silently fail to set magic_dns_name without providing useful debugging information about what the actual format was. Consider logging or including the actual device name in the error diagnostic to aid troubleshooting.

Copilot uses AI. Check for mistakes.
It's not presently possible to determine the tailnet/MagicDNS name
without a `tailscale_device(s)` data source and some string
manipulation.

Ideally, there'd be an API for this directy, but in lieu of that this
commit moves the device list/error (or 0 device) handling/string
manipulation into the provider; so that the terraform config can more
cleanly and naturally read from:
  tailscale_dns_configuration.x.magic_dns_name

to get the name like 'hyperactive-sloth.ts.net' directly.

Signed-off-by: Oliver Ford <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant