pulumi-azure-native
pulumi-azure-native copied to clipboard
resource_group_name property is null on pulumi_azure_native.compute.VirtualMachine
What happened?
I migrated some code from Azure Classic to Azure Native. The original code uses the resource_group_name property on a pulumi_azure.compute.VirtualMachine resource, but after migration my code starting failing because the property is null on pulumi_azure_native.compute.VirtualMachine resources.
Example
resource_group_name = instance.resource_group_name
resource_group_name is always null when instance is of type pulumi_azure_native.compute.VirtualMachine
Output of pulumi about
CLI
Version 3.105.0
Go Version go1.21.6
Go Compiler gc
Plugins NAME VERSION alicloud 3.36.0 aws 5.41.0 awsx 1.0.2 azure 5.43.0 azure-native 2.28.0 docker 3.6.1 gcp 6.55.1 oci 0.16.0 python unknown
Host
OS amazon
Version 2023
Arch x86_64
This project is written in python: executable='/usr/bin/python3' version='3.9.16'
Additional context
No response
Contributing
Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).
Hi @talawahtech, could you share the code you're using to provision the VirtualMachine resource so we can try to reproduce what you're seeing?
@mjeffryes here you go:
import pulumi
from pulumi_azure_native import compute, network, resources
# Create a new resource group
resource_group = resources.ResourceGroup('resource_group')
# Create a virtual network
virtual_network = network.VirtualNetwork(
'virtual_network',
resource_group_name=resource_group.name,
address_space=network.AddressSpaceArgs(address_prefixes=['10.0.0.0/16']),
location=resource_group.location,
)
# Create a subnet
subnet = network.Subnet(
'subnet',
resource_group_name=resource_group.name,
virtual_network_name=virtual_network.name,
address_prefix='10.0.2.0/24',
)
# Create a network interface
network_interface = network.NetworkInterface(
'network_interface',
resource_group_name=resource_group.name,
location=resource_group.location,
ip_configurations=[network.NetworkInterfaceIPConfigurationArgs(
name='ip_configuration',
subnet=network.SubnetArgs(
id=subnet.id,
),
private_ip_allocation_method=network.IPAllocationMethod.DYNAMIC,
)],
)
# Choose an available VM image and version
image_reference = compute.ImageReferenceArgs(
publisher='canonical',
offer='0001-com-ubuntu-server-focal',
sku='20_04-lts-gen2',
version='latest',
)
# Define the OS disk for the VM
os_disk = compute.OSDiskArgs(
create_option=compute.DiskCreateOption.FROM_IMAGE,
name='myosdisk1',
)
# Create the virtual machine
vm = compute.VirtualMachine(
'virtual_machine',
resource_group_name=resource_group.name,
location=resource_group.location,
network_profile=compute.NetworkProfileArgs(
network_interfaces=[
compute.NetworkInterfaceReferenceArgs(
id=network_interface.id,
primary=True,
),
],
),
os_profile=compute.OSProfileArgs(
computer_name='hostname',
admin_username='adminuser',
admin_password='Password1234!',
),
storage_profile=compute.StorageProfileArgs(
image_reference=image_reference,
os_disk=os_disk,
),
hardware_profile=compute.HardwareProfileArgs(
vm_size='Standard_D2s_v5',
),
)
# Export
pulumi.export('vm.location', vm.location)
pulumi.export('vm.os_profile.admin_username', vm.os_profile.admin_username)
pulumi.export('vm.hardware_profile.vm_size', vm.hardware_profile.vm_size)
pulumi.export('vm.resource_group_name', vm.resource_group_name)
pulumi.export('resource_group.name', resource_group.name)
This is the output I am getting from pulumi up
❯ pulumi up
Previewing update (dev):
Type Name Plan
pulumi:pulumi:Stack azure-native-github-issue-dev
Outputs:
+ vm.resource_group_name : output<string>
Resources:
6 unchanged
Do you want to perform this update? yes
Updating (dev):
Type Name Status
pulumi:pulumi:Stack azure-native-github-issue-dev
Outputs:
resource_group.name : "resource_groupXXXXXXX"
vm.hardware_profile.vm_size : "Standard_D2s_v5"
vm.location : "westus2"
vm.os_profile.admin_username: "adminuser"
Resources:
6 unchanged
Duration: 1s
As you can see resource_group.name is output, but vm.resource_group_name is not even displayed. If you output the entire vm object it shows resource_group_name : <null>.
Huh, that is pretty strange; you're right to expect that all the inputs would be reflected in the outputs of the resource.
My best guess is that either Azure is not returning anything and we're neglecting to copy over the inputs to the outputs, or the the API is explicitly returning a null for that field, which we respect and so don't copy the input value to the output.
I did notice you're on azure-native 2.28.0 and there have been some possibly relevant changes in that area since that release. Would you mind trying again on v2.30.0 and reporting if there's any difference in the behavior?
I can confirm that the behavior is still the same with pulumi 3.108.1 and azure-native 2.30.0
❯ pulumi about
CLI
Version 3.108.1
Go Version go1.22.0
Go Compiler gc
Plugins
NAME VERSION
azure-native 2.30.0
python unknown
Host
OS amazon
Version 2
Arch x86_64
I would like to generalize this issue. resource_group_name getter (output) is missing in many resources. I've been mainly concerned about containerservice.ManagedCluster, sql.Server and network.VirtualNetwork as those I need to add subresources/related resources for and all subresources need name and resource group name of the parent to be able to construct the resource manager ID.
The reason seems to be that the Azure Resource Manager does return name, location and id in the response, but it does not return resourceGroupName. It can only be deducted from the id. So that's what probably should be mixed into the generated classes.
Extracting from the long ID would be better than copying from input, because we can import the resource using the long ID and then the resource group name won't be in the input, but especially then it is useful in the output – e.g. when a vnet is set up by someone else, who has permissions to set up whatever peering is needed, and then we need to connect some project resources to it.
This is actually tracked in https://github.com/pulumi/pulumi-azure-native/issues/574, so I'll close this issue as a duplicate. I added a comment to that issue mentioning bad Python experience.