Skip to content

Commit 8f4c5e1

Browse files
committed
Proposal for dnsmasq options support
1 parent 924e603 commit 8f4c5e1

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

docs/resources/network.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Virtual network configuration
2424
- `autostart` (Boolean) Whether the network should be started automatically when the host boots
2525
- `bandwidth` (Attributes) Configures the bandwidth settings for the virtual network, specifying what limits are applied to data transport. (see [below for nested schema](#nestedatt--bandwidth))
2626
- `bridge` (Attributes) (see [below for nested schema](#nestedatt--bridge))
27+
- `dnsmasq_options` (String List) Appends <dnsmasq:options> to Network definition
2728
- `dns` (Attributes) DNS configuration for the network (see [below for nested schema](#nestedatt--dns))
2829
- `domain` (Attributes) Configures the domain associated with the network. (see [below for nested schema](#nestedatt--domain))
2930
- `forward` (Attributes) Network forwarding mode configuration (see [below for nested schema](#nestedatt--forward))

internal/provider/network_resource.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type NetworkResourceModel struct {
2929
generated.NetworkModel
3030
ID types.String `tfsdk:"id"` // Resource identifier (UUID)
3131
Autostart types.Bool `tfsdk:"autostart"` // Provider-specific: whether to autostart
32+
DnsmasqOptions types.List `tfsdk:"dnsmasq_options"` // List of strings
3233
}
3334

3435
func NewNetworkResource() resource.Resource {
@@ -70,6 +71,11 @@ func (r *NetworkResource) Schema(ctx context.Context, req resource.SchemaRequest
7071
Optional: true,
7172
Computed: true,
7273
},
74+
"dnsmasq_options": schema.ListAttribute{
75+
Description: "List of dnsmasq options (e.g., 'foo=bar', 'cname=*.example.com,master.example.com')",
76+
Optional: true,
77+
ElementType: types.StringType,
78+
},
7379
})
7480
}
7581

@@ -107,6 +113,22 @@ func (r *NetworkResource) Create(ctx context.Context, req resource.CreateRequest
107113
return
108114
}
109115

116+
// Handle dnsmasq options
117+
if !model.DnsmasqOptions.IsNull() && !model.DnsmasqOptions.IsUnknown() {
118+
var options []string
119+
diags := model.DnsmasqOptions.ElementsAs(ctx, &options, false)
120+
if !diags.HasError() && len(options) > 0 {
121+
networkXML.DnsmasqOptions = &libvirtxml.NetworkDnsmasqOptions{
122+
Option: make([]libvirtxml.NetworkDnsmasqOption, len(options)),
123+
}
124+
for i, opt := range options {
125+
networkXML.DnsmasqOptions.Option[i] = libvirtxml.NetworkDnsmasqOption{
126+
Value: opt,
127+
}
128+
}
129+
}
130+
}
131+
110132
// Marshal to XML
111133
xmlDoc, err := networkXML.Marshal()
112134
if err != nil {
@@ -404,5 +426,15 @@ func (r *NetworkResource) readNetwork(ctx context.Context, model *NetworkResourc
404426
model.Autostart = types.BoolValue(autostart == 1)
405427
}
406428

429+
// Read dnsmasq options
430+
if networkXML.DnsmasqOptions != nil && len(networkXML.DnsmasqOptions.Option) > 0 {
431+
options := make([]string, len(networkXML.DnsmasqOptions.Option))
432+
for i, opt := range networkXML.DnsmasqOptions.Option {
433+
options[i] = opt.Value
434+
}
435+
model.DnsmasqOptions, _ = types.ListValueFrom(ctx, types.StringType, options)
436+
} else {
437+
model.DnsmasqOptions = types.ListNull(types.StringType)
438+
}
407439
return nil
408440
}

0 commit comments

Comments
 (0)