Skip to content

Commit

Permalink
Merge pull request #24 from squat/add_capacities_to_ib_network_data_s…
Browse files Browse the repository at this point in the history
…ource

feat: capacity in data.ib_network
  • Loading branch information
ajeyaraj-crusoe authored Dec 19, 2024
2 parents ed40f1f + 41f1566 commit 3d866b3
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions internal/ib_network/ib_network_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ type ibNetworksDataSourceModel struct {
IBNetworks []ibNetworkModel `tfsdk:"ib_networks"`
}

type ibNetworkCapacityModel struct {
Quantity int64 `tfsdk:"quantity"`
SliceType string `tfsdk:"slice_type"`
}

type ibNetworkModel struct {
ID string `tfsdk:"id"`
Name string `tfsdk:"name"`
Location string `tfsdk:"location"`
ID string `tfsdk:"id"`
Name string `tfsdk:"name"`
Location string `tfsdk:"location"`
Capacities []ibNetworkCapacityModel `tfsdk:"capacities"`
}

func NewIBNetworkDataSource() datasource.DataSource {
Expand Down Expand Up @@ -65,6 +71,19 @@ func (ds *ibNetworksDataSource) Schema(ctx context.Context, request datasource.S
"location": schema.StringAttribute{
Computed: true,
},
"capacities": schema.ListNestedAttribute{
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"quantity": schema.Int64Attribute{
Computed: true,
},
"slice_type": schema.StringAttribute{
Computed: true,
},
},
},
},
},
},
},
Expand All @@ -91,10 +110,18 @@ func (ds *ibNetworksDataSource) Read(ctx context.Context, req datasource.ReadReq

var state ibNetworksDataSourceModel
for i := range dataResp.Items {
capacities := make([]ibNetworkCapacityModel, 0, len(dataResp.Items[i].Capacities))
for _, c := range dataResp.Items[i].Capacities {
capacities = append(capacities, ibNetworkCapacityModel{
Quantity: int64(c.Quantity),
SliceType: c.SliceType,
})
}
state.IBNetworks = append(state.IBNetworks, ibNetworkModel{
ID: dataResp.Items[i].Id,
Name: dataResp.Items[i].Name,
Location: dataResp.Items[i].Location,
ID: dataResp.Items[i].Id,
Name: dataResp.Items[i].Name,
Location: dataResp.Items[i].Location,
Capacities: capacities,
})
}

Expand Down

0 comments on commit 3d866b3

Please sign in to comment.