Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power State not reported in azurerm_virtual_machine and azurerm_virtual_machine_scale_set data sources #26990

Closed
1 task done
ned1313 opened this issue Aug 9, 2024 · 2 comments · Fixed by #26991
Closed
1 task done
Labels
Milestone

Comments

@ned1313
Copy link
Contributor

ned1313 commented Aug 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

Terraform Version

1.9.3

AzureRM Provider Version

3.115.0

Affected Resource(s)/Data Source(s)

azurerm_virtual_machine azurerm_virtual_machine_scale_set

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.0"
    }
  }
}

provider "azurerm" {
  features {}
}

data "azurerm_virtual_machine" "example" {
  name                = "check-vm"
  resource_group_name = "check-vm"
}

output "power_state" {
  value = data.azurerm_virtual_machine.example.power_state
}

data "azurerm_virtual_machine_scale_set" "flexible" {
  name                = "vmss-test"
  resource_group_name = "vmss-test"
}

data "azurerm_virtual_machine_scale_set" "uniform" {
  name                = "uniform-test"
  resource_group_name = "vmss-test"
}

output "flexible_power" {
  value = { for instance in data.azurerm_virtual_machine_scale_set.flexible.instances : instance.name => instance.power_state }
}

output "uniform_power" {
  value = { for instance in data.azurerm_virtual_machine_scale_set.uniform.instances : instance.name => instance.power_state }
}

Debug Output/Panic Output

N/A

Expected Behaviour

flexible_power = {
  "vmss-test_3b9d9442" = "running"
  "vmss-test_931fa536" = "running"
}
power_state = "running"
uniform_power = {
  "uniform-test_0" = "running"
  "uniform-test_1" = "running"
}

Actual Behaviour

flexible_power = {
  "vmss-test_3b9d9442" = ""
  "vmss-test_931fa536" = ""
}
power_state = ""
uniform_power = {
  "uniform-test_0" = ""
  "uniform-test_1" = ""
}

Steps to Reproduce

  1. Provision an Azure VM, Azure VM Scale Set in Uniform mode, and VM Scale Set in Flexible mode
  2. Run terraform apply with the supplied configuration and the correct resource group name and resource names
  3. The output for the power_state attribute will be blank

Important Factoids

No response

References

This was previously resolved in PR #22851. Refactoring of the code to support the newer API broke it again.

@github-actions github-actions bot added the v/3.x label Aug 9, 2024
@ned1313
Copy link
Contributor Author

ned1313 commented Aug 9, 2024

There are actually two separate problems.

azurerm_virtual_machine data source

This data source is using the resp, err := client.Get(ctx, id, virtualmachines.DefaultGetOperationOptions()) statement here. InstanceView is required to get the power state of the VM and the DefaultGetOperationOptions() doesn't include the InstanceView in the Expand field of the struct.

azurerm_virtual_machine_scale_set data source

This one is trickier b/c there are two orchestration models that require different API endpoints to inspect the properties of the underlying VMs. Uniform orchestration uses the VMSS API and Flexible uses the VM API. For Uniform, you can include the InstanceView argument in the ListComplete call. For Flexible, you need to add the InstanceView argument to individual calls to the Azure VM client Get function.

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
2 participants