Azure / aztfexport

A tool to bring existing Azure resources under Terraform's management
https://azure.github.io/aztfexport/
Mozilla Public License 2.0
1.53k stars 174 forks source link

Export Does Not Capture privateIPAllocationMethod For Static IP NICs #527

Closed jeffh-cloudflare closed 1 month ago

jeffh-cloudflare commented 1 month ago

I created several Network Interface objects when defining them in the Azure Portal. I assigned a Static IP to each Network Interface (default is Dynamic).

It doesn't seem like aztfexport reflects cases where a Network interface has a Static IP.

Any time I attempt to run Terraform to apply the configuration, I get the following error message:

Error: creating Network Interface (Subscription: "REDACTED" Resource Group Name: "my_resource_group" Network Interface Name: "vm_01_interface_eth0"): performing CreateOrUpdate: unexpected status 400 (400 Bad Request) with error: PrivateIPAddressMissing: Private IP address is required when privateIPAllocationMethod is Static in IP configuration /subscriptions/REDACTED/resourceGroups/my_resource_group/providers/Microsoft.Network/networkInterfaces/vm_01_interface_eth0/ipConfigurations/ipconfig1.

Steps to Reproduce:

  1. Create Network Interface object
  2. Edit properties
  3. Settings -> IP congurations
  4. Allocation: Static
  5. Private IP address: 10.10.10.100 (within subnet in corresponding virtual network)
  6. Run aztfexport and select the Resource Group (aztfexport resource-group my_resource_group)
  7. Remove Resource Group and all objects via the Azure Portal
  8. Run 'terraform apply'

I receive the aforementioned error message within a minute or so.

stemaMSFT commented 1 month ago

Hey Jeff,

Is there a reason you're attempting to remove all the resources/resource group in step 7? The tool cannot guarantee perfect repro of the resources that you create in the portal, the list of reasons of which are listed here.

jeffh-cloudflare commented 1 month ago

Thanks for getting back to me and sharing that resource with me!

I think I was able to identify the root cause of the issue. I'm about to try it out right now...

I found this message within the main.tf file:

  depends_on = [
    # One of azurerm_subnet.res-23,azurerm_subnet_route_table_association.res-24 (can't auto-resolve as their ids are identical)
  ]
}

I'm trying to see if I can manually resolve this.

I'm a Terraform n00b - so this is all a bit of a stretch right now. I'll get there. :-)

stemaMSFT commented 1 month ago

Glad to see you've found this! Feel free to close if this is resolve or re-comment if there are issues.

jeffh-cloudflare commented 1 month ago

Thanks for your help!