Skip to content

Commit

Permalink
fix(data/virtual_machine): populate network_speed_profile field
Browse files Browse the repository at this point in the history
The network_speed_profile field was always empty, as we never performed
the require lookups to populate it during the data source read
operation.
  • Loading branch information
jimeh committed Jan 26, 2023
1 parent ed440e9 commit cf88729
Show file tree
Hide file tree
Showing 6 changed files with 2,019 additions and 1,085 deletions.
18 changes: 18 additions & 0 deletions internal/provider/data_source_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ func dataSourceVirtualMachineRead(
diags = append(diags, diag.FromErr(err)...)
}

// As we set the speed profile for all interfaces on a VM, we only care
// about fetching details about any single interface.
vmnets, _, err := m.Core.VirtualMachineNetworkInterfaces.List(
ctx, vm.Ref(), &core.ListOptions{Page: 1, PerPage: 1},
)
if err != nil {
diags = append(diags, diag.FromErr(err)...)
} else if len(vmnets) > 0 {
vmnet, _, err2 := m.Core.VirtualMachineNetworkInterfaces.Get(
ctx, vmnets[0].Ref(),
)
if err2 != nil {
diags = append(diags, diag.FromErr(err2)...)
} else if vmnet.SpeedProfile != nil {
_ = d.Set("network_speed_profile", vmnet.SpeedProfile.Permalink)
}
}

err = d.Set("tags", flattenTagNames(vm.TagNames))
if err != nil {
diags = append(diags, diag.FromErr(err)...)
Expand Down
10 changes: 10 additions & 0 deletions internal/provider/data_source_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestAccKatapultDataSourceVirtualMachine_by_id(t *testing.T) {
ip_address_ids = [katapult_ip.web.id]
group_id = katapult_virtual_machine_group.web.id
tags = ["web", "public"]
network_speed_profile = "1gbps"
}
data "katapult_virtual_machine" "src" {
Expand Down Expand Up @@ -87,6 +88,10 @@ func TestAccKatapultDataSourceVirtualMachine_by_id(t *testing.T) {
"data.katapult_virtual_machine.src", "group_id",
"katapult_virtual_machine_group.web", "id",
),
resource.TestCheckResourceAttr(
"data.katapult_virtual_machine.src",
"network_speed_profile", "1gbps",
),
// TODO: populate and check disk_template and options when
// supported by the API.
resource.TestCheckNoResourceAttr(
Expand Down Expand Up @@ -136,6 +141,7 @@ func TestAccKatapultDataSourceVirtualMachine_by_fqdn(t *testing.T) {
ip_address_ids = [katapult_ip.web.id]
group_id = katapult_virtual_machine_group.web.id
tags = ["web", "public"]
network_speed_profile = "1gbps"
}
data "katapult_virtual_machine" "src" {
Expand Down Expand Up @@ -182,6 +188,10 @@ func TestAccKatapultDataSourceVirtualMachine_by_fqdn(t *testing.T) {
"data.katapult_virtual_machine.src", "group_id",
"katapult_virtual_machine_group.web", "id",
),
resource.TestCheckResourceAttr(
"data.katapult_virtual_machine.src",
"network_speed_profile", "1gbps",
),
// TODO: populate and check disk_template and options when
// supported by the API.
resource.TestCheckNoResourceAttr(
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
abicj93c9moj
3vacegc48pqd
Loading

0 comments on commit cf88729

Please sign in to comment.