This commit is contained in:
2026-04-23 12:28:18 +10:00
2 changed files with 10 additions and 14 deletions
+5 -7
View File
@@ -100,20 +100,18 @@ func (d *dnsRecordsDataSource) Configure(_ context.Context, req datasource.Confi
}
func (d *dnsRecordsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config struct {
Hostname types.String `tfsdk:"hostname"`
}
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
var hostname types.String
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("hostname"), &hostname)...)
if resp.Diagnostics.HasError() {
return
}
if config.Hostname.IsUnknown() || config.Hostname.IsNull() {
if hostname.IsUnknown() || hostname.IsNull() {
resp.Diagnostics.AddAttributeError(path.Root("hostname"), "Invalid hostname", "The hostname must be known and non-null.")
return
}
domainID, domainName, err := d.clientProvider.client.GetRootDomain(ctx, config.Hostname.ValueString())
domainID, domainName, err := d.clientProvider.client.GetRootDomain(ctx, hostname.ValueString())
if err != nil {
resp.Diagnostics.AddError(diagnosticSummary("Unable to resolve Dynu domain from hostname", err), err.Error())
return
@@ -128,7 +126,7 @@ func (d *dnsRecordsDataSource) Read(ctx context.Context, req datasource.ReadRequ
sortDNSRecords(records)
state := dnsRecordsDataSourceModel{
Hostname: config.Hostname,
Hostname: hostname,
DomainID: types.Int64Value(domainID),
DomainName: types.StringValue(domainName),
Records: make([]dnsRecordStateItem, 0, len(records)),
+5 -7
View File
@@ -73,20 +73,18 @@ func (d *domainDataSource) Configure(_ context.Context, req datasource.Configure
}
func (d *domainDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config struct {
Hostname types.String `tfsdk:"hostname"`
}
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
var hostname types.String
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("hostname"), &hostname)...)
if resp.Diagnostics.HasError() {
return
}
if config.Hostname.IsUnknown() || config.Hostname.IsNull() {
if hostname.IsUnknown() || hostname.IsNull() {
resp.Diagnostics.AddAttributeError(path.Root("hostname"), "Invalid hostname", "The hostname must be known and non-null.")
return
}
domainID, _, err := d.clientProvider.client.GetRootDomain(ctx, config.Hostname.ValueString())
domainID, _, err := d.clientProvider.client.GetRootDomain(ctx, hostname.ValueString())
if err != nil {
resp.Diagnostics.AddError(diagnosticSummary("Unable to resolve Dynu domain from hostname", err), err.Error())
return
@@ -104,7 +102,7 @@ func (d *domainDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}
state := domainDataSourceModel{
Hostname: config.Hostname,
Hostname: hostname,
Domain: domainObject,
}