Azure / Azure/terraform

Microsoft.AzureStackHCI/networkInterfaces tags update disconnects the VM permanently

Open
#416 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
HCL
Stars
925
Forks
930
Avg merge
4d 15h
Merged PRs (30d)
5

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Terraform Version

1.10.4

### Provider Version

2.2.0

### Current Behavior

We are creating HCI linux VMs with terraform and azapi_resource with "Microsoft.AzureStackHCI/networkInterfaces@2024-08-01-preview" API
when network interface tags are changed, the NI seems to disconnect briefly from the VM, making the VM lose all network and never restoring.
A reboot does not fix this issue.
No other VM resources with tags seems to face this issue.
When this happens, we are forced to replace the VM entirely, leading to uptime issues.

The issue happens with the latest preview version of the API and several previous ones.

### Expected Behavior

For tags to be updated, like with any other resource

### Terraform configuration

```terraform
$ terraform providers

Providers required by configuration:
.
│   ├── provider[registry.terraform.io/hashicorp/azurerm] >= 4.15.0
│   ├── provider[registry.terraform.io/hashicorp/vault] ~> 3.0
│   ├── provider[registry.terraform.io/hashicorp/random] >= 3.6.0
│   ├── provider[registry.terraform.io/hashicorp/time] >= 0.12.0
│   ├── provider[registry.terraform.io/azure/azapi] >= 2.2.0
│   ├── provider[terraform.io/builtin/terraform]

resource "azapi_resource" "azure_stack_hci_network_interface" {
type = "Microsoft.AzureStackHCI/networkInterfaces@2024-08-01-preview"
location = data.azapi_resource.vm_resource_group.location
name = format("%s-%s", local.vm_name, "ni")
parent_id = data.azapi_resource.vm_resource_group.id
tags = local.resource_tags

body = {
properties = {
ipConfigurations = [
{
properties = {
subnet = {
id = data.azapi_resource.logical_network.id
}
}
}
]
}
extendedLocation = {
name = data.azapi_resource.custom_location.id
type = "CustomLocation"
}
}

lifecycle {
create_before_destroy = true
}
}

locals {
dynamic_tags = {
BusinessUnit = var.bu
CreationDate = time_static.creation.rfc3339
Component = var.component
Environment = var.env
}
resource_tags = merge(
var.default_tags,
local.dynamic_tags,
var.resource_tags,
)
}
```

### Steps To Reproduce

1. `terraform init -backend-config dev.backend.tfvars --upgrade --reconfigure`
2. `terraform apply -var-file dev.tfvars -parallelism=100`

### Anything else?

maybe related https://github.com/Azure/bicep-types-az/issues/2246

we have been forced to add ignore_changes lifecycle rule to the NI resources, until this issue is fixed.
```
lifecycle {
create_before_destroy = true
ignore_changes = [
tags
]
}
```
Not being able to have correct tags is not ideal in a production system.

We have tested CLI updates, and none reproduced this issue. So far only seems to affect modifications via terraform.
`az azurestackhci networkinterface update --tags additionalProperties="sample" --name "hci-4cdf-ni" --resource-group "rg"`
`az network nic update --name hci-4cdf-ni --resource-group rg --set properties.creationDate=$(date +%Y-%m-%dT%H:%M:%S)`

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue names no repository files or tests. Start by reproducing the Terraform configuration with a tag-only update, then compare the Terraform/AzAPI operation with the listed Azure CLI updates. Done means changing network-interface tags no longer permanently disconnects the VM and the existing reproduction is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, terraform
Domain
cloud, infrastructure, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.