Harden read-only provider with tests, docs, and CI

This commit is contained in:
beatz174-bit
2026-04-21 14:39:36 +10:00
parent cf47a6ed48
commit 6cc1b206dc
24 changed files with 711 additions and 246 deletions
+21 -19
View File
@@ -52,11 +52,11 @@ func (d *domainsDataSource) Metadata(_ context.Context, req datasource.MetadataR
func (d *domainsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "List DNS domains from Dynu.",
Description: "Lists DNS domains visible to the configured Dynu API key.",
Attributes: map[string]schema.Attribute{
"domains": schema.ListNestedAttribute{
Computed: true,
Description: "List of Dynu DNS domains.",
Description: "Sorted list of domains. Timestamps are returned exactly as Dynu provides them.",
NestedObject: schema.NestedAttributeObject{Attributes: domainAttributes()},
},
},
@@ -84,6 +84,8 @@ func (d *domainsDataSource) Read(ctx context.Context, _ datasource.ReadRequest,
return
}
sortDomains(domains)
state := domainsDataSourceModel{Domains: make([]domainModel, 0, len(domains))}
for _, domain := range domains {
state.Domains = append(state.Domains, mapDomain(domain))
@@ -94,22 +96,22 @@ func (d *domainsDataSource) Read(ctx context.Context, _ datasource.ReadRequest,
func domainAttributes() map[string]schema.Attribute {
return map[string]schema.Attribute{
"id": schema.Int64Attribute{Computed: true},
"name": schema.StringAttribute{Computed: true},
"unicode_name": schema.StringAttribute{Computed: true},
"token": schema.StringAttribute{Computed: true, Sensitive: true},
"state": schema.StringAttribute{Computed: true},
"group": schema.StringAttribute{Computed: true},
"ipv4_address": schema.StringAttribute{Computed: true},
"ipv6_address": schema.StringAttribute{Computed: true},
"ttl": schema.Int64Attribute{Computed: true},
"ipv4": schema.BoolAttribute{Computed: true},
"ipv6": schema.BoolAttribute{Computed: true},
"ipv4_wildcard_alias": schema.BoolAttribute{Computed: true},
"ipv6_wildcard_alias": schema.BoolAttribute{Computed: true},
"allow_zone_transfer": schema.BoolAttribute{Computed: true},
"dnssec": schema.BoolAttribute{Computed: true},
"created_on": schema.StringAttribute{Computed: true},
"updated_on": schema.StringAttribute{Computed: true},
"id": schema.Int64Attribute{Computed: true, Description: "Dynu domain ID."},
"name": schema.StringAttribute{Computed: true, Description: "Primary domain name."},
"unicode_name": schema.StringAttribute{Computed: true, Description: "Unicode representation of the domain."},
"token": schema.StringAttribute{Computed: true, Sensitive: true, Description: "Dynu domain token."},
"state": schema.StringAttribute{Computed: true, Description: "Dynu domain state."},
"group": schema.StringAttribute{Computed: true, Description: "Dynu domain group."},
"ipv4_address": schema.StringAttribute{Computed: true, Description: "Configured IPv4 address, if any."},
"ipv6_address": schema.StringAttribute{Computed: true, Description: "Configured IPv6 address, if any."},
"ttl": schema.Int64Attribute{Computed: true, Description: "DNS TTL in seconds."},
"ipv4": schema.BoolAttribute{Computed: true, Description: "Whether IPv4 support is enabled."},
"ipv6": schema.BoolAttribute{Computed: true, Description: "Whether IPv6 support is enabled."},
"ipv4_wildcard_alias": schema.BoolAttribute{Computed: true, Description: "Whether IPv4 wildcard alias is enabled."},
"ipv6_wildcard_alias": schema.BoolAttribute{Computed: true, Description: "Whether IPv6 wildcard alias is enabled."},
"allow_zone_transfer": schema.BoolAttribute{Computed: true, Description: "Whether zone transfer is allowed."},
"dnssec": schema.BoolAttribute{Computed: true, Description: "Whether DNSSEC is enabled."},
"created_on": schema.StringAttribute{Computed: true, Description: "Creation timestamp as returned by Dynu."},
"updated_on": schema.StringAttribute{Computed: true, Description: "Last update timestamp as returned by Dynu."},
}
}