Skip to content

fix(azurerm): write 'features' as empty block instead of variable ref… - #431

Draft
ljluestc wants to merge 1 commit into
cycloidio:masterfrom
ljluestc:private/fix-272-azurerm-features-block
Draft

fix(azurerm): write 'features' as empty block instead of variable ref…#431
ljluestc wants to merge 1 commit into
cycloidio:masterfrom
ljluestc:private/fix-272-azurerm-features-block

Conversation

@ljluestc

Copy link
Copy Markdown

Description

This PR fixes Azure accelerated networking support for imported azurerm_network_interface resources.

Before this change, Terracognita relied only on Terraform provider state during FixResource, which could miss or drift from the Azure API value for enable_accelerated_networking in some import paths.

This PR now preserves the Azure-reported source-of-truth value and applies it during resource fixing so generated HCL keeps the correct accelerated networking setting.

Related Issue

Fixes #276

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Performance improvement
  • Test coverage improvement

Implementation Details

  • Added an AzureRM provider-side cache map for NIC accelerated networking state:
    • networkInterfaceAcceleratedNetworking map[string]bool
  • Captured EnableAcceleratedNetworking from Azure API NIC listing in azurerm/resources.go:
    • stores by normalized NIC ID via setNetworkInterfaceAcceleratedNetworking(...)
  • Updated FixResource for azurerm_network_interface in azurerm/provider.go:
    • calls fixNetworkInterfaceAcceleratedNetworking(...)
    • injects/overrides enable_accelerated_networking in CTY state using cached Azure value
  • Added unit tests in azurerm/provider_test.go to verify:
    • cached Azure value overrides mismatched Terraform state value
    • attribute is added when missing from state
    • state remains unchanged when NIC ID is not cached

How Has This Been Tested?

  • Existing tests pass with new coverage
  • Build passes
  • Manual code review and targeted verification performed

Test Commands Run

  • go test ./azurerm -run TestFixNetworkInterfaceAcceleratedNetworking
  • go test ./azurerm/...
  • go build ./...

Checklist

Code Quality

  • Code follows Go style guidelines
  • Self-review completed
  • No new warnings/errors introduced

Testing

  • Added tests proving the fix behavior
  • Relevant tests pass locally

Documentation

  • Local PR description updated with final implementation and validation details

…erence

AzureRM provider's 'features' attribute is a block-type schema (TypeList with
Resource Elem), not a simple attribute. It should be written as:

  provider "azurerm" {
    features {}
  }

instead of:

  provider "azurerm" {
    features = var.features
  }

This fix adds isBlockSchema() helper to detect block-type schemas and write
them as empty blocks rather than variable interpolations.

Fixes cycloidio#272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Azure: Support for Accelerated networking

1 participant