Skip to content

Commit

Permalink
fix: add remaining data source attributes (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 authored Sep 19, 2024
1 parent c90a7e6 commit 439e10a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 2 deletions.
43 changes: 42 additions & 1 deletion pkg/config-api-provider/provider/data-sources/wired_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ type wiredNetworkDataSource struct {
}

type wiredNetworkDataSourceModel struct {
ID types.String `tfsdk:"id"`
ID types.String `tfsdk:"id"`
Alias types.String `tfsdk:"alias"`
IpVersion types.String `tfsdk:"ip_version"`
Security types.String `tfsdk:"security"`
DnsLookupDomain types.String `tfsdk:"dns_lookup_domain"`
DisableEdns types.Bool `tfsdk:"disable_edns"`
UseDns64 types.Bool `tfsdk:"use_dns64"`
ExternalConnectivity types.Bool `tfsdk:"external_connectivity"`
VlanId types.Int64 `tfsdk:"vlan_id"`

Filter struct {
WiredNetworkID string `tfsdk:"wired_network_id"`
} `tfsdk:"filter"`
Expand All @@ -40,6 +49,30 @@ func (d *wiredNetworkDataSource) Schema(_ context.Context, _ datasource.SchemaRe
"id": schema.StringAttribute{
Computed: true,
},
"alias": schema.StringAttribute{
Computed: true,
},
"ip_version": schema.StringAttribute{
Computed: true,
},
"security": schema.StringAttribute{
Computed: true,
},
"dns_lookup_domain": schema.StringAttribute{
Computed: true,
},
"disable_edns": schema.BoolAttribute{
Computed: true,
},
"use_dns64": schema.BoolAttribute{
Computed: true,
},
"external_connectivity": schema.BoolAttribute{
Computed: true,
},
"vlan_id": schema.Int64Attribute{
Computed: true,
},
"filter": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
Expand Down Expand Up @@ -77,6 +110,14 @@ func (d *wiredNetworkDataSource) Read(ctx context.Context, req datasource.ReadRe

network := networkResponse.WiredNetworks[0]
state.ID = types.StringValue(network.Uid)
state.Alias = types.StringValue(network.Alias)
state.IpVersion = types.StringValue(network.IpVersion)
state.Security = types.StringValue(*network.Security.Get())
state.DnsLookupDomain = types.StringValue(*network.DnsLookupDomain.Get())
state.DisableEdns = types.BoolValue(network.DisableEdns)
state.UseDns64 = types.BoolValue(network.UseDns64)
state.ExternalConnectivity = types.BoolValue(network.ExternalConnectivity)
state.VlanId = types.Int64Value(int64(*network.VlanId.Get()))

// Set state
diags = resp.State.Set(ctx, &state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ type wirelessNetworkDataSource struct {
}

type wirelessNetworkDataSourceModel struct {
ID types.String `tfsdk:"id"`
ID types.String `tfsdk:"id"`
Ssid types.String `tfsdk:"ssid"`
Alias types.String `tfsdk:"alias"`
IpVersion types.String `tfsdk:"ip_version"`
Security types.String `tfsdk:"security"`
Hidden types.Bool `tfsdk:"hidden"`
BandLocking types.String `tfsdk:"band_locking"`
DnsLookupDomain types.String `tfsdk:"dns_lookup_domain"`
DisableEdns types.Bool `tfsdk:"disable_edns"`
UseDns64 types.Bool `tfsdk:"use_dns64"`
ExternalConnectivity types.Bool `tfsdk:"external_connectivity"`

Filter struct {
WirelessNetworkID string `tfsdk:"wireless_network_id"`
} `tfsdk:"filter"`
Expand All @@ -40,6 +51,36 @@ func (d *wirelessNetworkDataSource) Schema(_ context.Context, _ datasource.Schem
"id": schema.StringAttribute{
Computed: true,
},
"ssid": schema.StringAttribute{
Computed: true,
},
"alias": schema.StringAttribute{
Computed: true,
},
"ip_version": schema.StringAttribute{
Computed: true,
},
"security": schema.StringAttribute{
Computed: true,
},
"hidden": schema.BoolAttribute{
Computed: true,
},
"band_locking": schema.StringAttribute{
Computed: true,
},
"dns_lookup_domain": schema.StringAttribute{
Computed: true,
},
"disable_edns": schema.BoolAttribute{
Computed: true,
},
"use_dns64": schema.BoolAttribute{
Computed: true,
},
"external_connectivity": schema.BoolAttribute{
Computed: true,
},
"filter": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
Expand Down Expand Up @@ -77,6 +118,16 @@ func (d *wirelessNetworkDataSource) Read(ctx context.Context, req datasource.Rea

network := networkResponse.WirelessNetworks[0]
state.ID = types.StringValue(network.Uid)
state.Ssid = types.StringValue(network.Ssid)
state.Alias = types.StringValue(network.Alias)
state.IpVersion = types.StringValue(network.IpVersion)
state.Security = types.StringValue(*network.Security.Get())
state.Hidden = types.BoolValue(network.Hidden)
state.BandLocking = types.StringValue(network.BandLocking)
state.DnsLookupDomain = types.StringValue(*network.DnsLookupDomain.Get())
state.DisableEdns = types.BoolValue(network.DisableEdns)
state.UseDns64 = types.BoolValue(network.UseDns64)
state.ExternalConnectivity = types.BoolValue(network.ExternalConnectivity)

// Set state
diags = resp.State.Set(ctx, &state)
Expand Down
8 changes: 8 additions & 0 deletions pkg/config-api-provider/test/data_source_wired_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ func TestWiredNetworkDataSource(t *testing.T) {
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "id", "uid"),
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "alias", "alias"),
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "ip_version", "ip_version"),
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "security", "security"),
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "dns_lookup_domain", "dns_lookup_domain"),
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "disable_edns", "false"),
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "use_dns64", "false"),
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "external_connectivity", "false"),
resource.TestCheckResourceAttr("data.uxi_wired_network.my_wired_network", "vlan_id", "123"),
),
},
},
Expand Down
10 changes: 10 additions & 0 deletions pkg/config-api-provider/test/data_source_wireless_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ func TestWirelessNetworkDataSource(t *testing.T) {
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "id", "uid"),
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "ssid", "ssid"),
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "alias", "alias"),
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "ip_version", "ip_version"),
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "security", "security"),
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "hidden", "false"),
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "band_locking", "band_locking"),
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "dns_lookup_domain", "dns_lookup_domain"),
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "disable_edns", "false"),
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "use_dns64", "false"),
resource.TestCheckResourceAttr("data.uxi_wireless_network.my_wireless_network", "external_connectivity", "false"),
),
},
},
Expand Down

0 comments on commit 439e10a

Please sign in to comment.