infobloxopen / terraform-provider-infoblox

Infoblox NIOS Terraform Provider
https://github.com/infobloxopen/terraform-provider-infoblox
Mozilla Public License 2.0
67 stars 73 forks source link

Importing one infoblox_ip_allocation resource will convert ALL infoblox_ip_allocation resources #324

Open grimm26 opened 6 months ago

grimm26 commented 6 months ago

When you import one infoblox_ip_allocation resource, it will convert all existing infoblox_ip_allocation resources to the v2 schema and thereby delete all of the information in a v1 infoblox_ip_allocation resource. This is yet ANOTHER roadblock in the way of actually upgrading from v1 of the provider.

Here is an example of what happened to the in the state file when I imported a different infoblox_ip_allocation resource:

{                                                                                                                                                                                                                                                                                           
        "module": "module.focal_nodes_hlr",                                                                                                                                                                                                                                                       
        "mode": "managed",                                                                                                                                                                                                                                                                        
        "type": "infoblox_ip_allocation",                                                                                                                                                                                                                                                         
        "name": "ib",                                                                                                                                                                                                                                                                             
        "provider": "provider[\"registry.terraform.io/infobloxopen/infoblox\"].enova",                                                                                                                                                                                                            
        "instances": [                                                                                                                                                                                                                                                                            
          {                                                                                                                                                                                                                                                                                       
            "index_key": "env-spew-stg01",                                                                                                                                                                                                                                                        
            "schema_version": 0,                                                                                                                                                                                                                                                                  
            "attributes": {                                                                                                                                                                                                                                                                       
              "cidr": "10.16.101.0/24",                                                                                                                                                                                                                                                           
              "dns_view": "inside",                                                                                                                                                                                                                                                               
              "enable_dns": true,                                                                                                                                                                                                                                                                 
              "id": "record:host/ZG5zLmhvc3QkLjEuY29tLmVub3ZhLmhsci5lbnYtc3Bldy1zdGcwMQ:env-spew-stg01.hlr.nope.com/inside",                                                                                                                                                                     
              "ip_addr": "10.16.101.22",                                                                                                                                                                                                                                                          
              "mac_addr": null,                                                                                                                                                                                                                                                                   
              "network_view_name": "default",                                                                                                                                                                                                                                                     
              "tenant_id": "default",                                                                                                                                                                                                                                                             
              "vm_id": null,                                                                                                                                                                                                                                                                      
              "vm_name": "env-spew-stg01",                                                                                                                                                                                                                                                        
              "zone": "hlr.nope.com"                                                                                                                                                                                                                                                             
            }

became

   {                                                                                                                                                                                                                                                                                             
      "module": "module.focal_nodes_hlr",                                                                                                                                                                                                                                                         
      "mode": "managed",                                                                                                                                                                                                                                                                          
      "type": "infoblox_ip_allocation",                                                                                                                                                                                                                                                           
      "name": "ib",                                                                                                                                                                                                                                                                               
      "provider": "provider[\"registry.terraform.io/infobloxopen/infoblox\"].enova",                                                                                                                                                                                                              
      "instances": [                                                                                                                                                                                                                                                                              
        {                                                                                                                                                                                                                                                                                         
          "index_key": "env-spew-stg01",                                                                                                                                                                                                                                                          
          "schema_version": 0,                                                                                                                                                                                                                                                                    
          "attributes": {                                                                                                                                                                                                                                                                         
            "allocated_ipv4_addr": null,                                                                                                                                                                                                                                                          
            "allocated_ipv6_addr": null,                                                                                                                                                                                                                                                          
            "comment": null,                                                                                                                                                                                                                                                                      
            "dns_view": "inside",                                                                                                                                                                                                                                                                 
            "enable_dns": true,                                                                                                                                                                                                                                                                   
            "ext_attrs": null,                                                                                                                                                                                                                                                                    
            "fqdn": null,                                                                                                                                                                                                                                                                         
            "id": "record:host/ZG5zLmhvc3QkLjEuY29tLmVub3ZhLmhsci5lbnYtc3Bldy1zdGcwMQ:env-spew-stg01.hlr.nope.com/inside",                                                                                                                                                                       
            "internal_id": null,                                                                                                                                                                                                                                                                  
            "ipv4_addr": null,                                                                                                                                                                                                                                                                    
            "ipv4_cidr": null,                                                                                                                                                                                                                                                                    
            "ipv6_addr": null,                                                                                                                                                                                                                                                                    
            "ipv6_cidr": null,                                                                                                                                                                                                                                                                    
            "network_view": null,                                                                                                                                                                                                                                                                 
            "ref": null,                                                                                                                                                                                                                                                                          
            "ttl": null                                                                                                                                                                                                                                                                           
          },                                         

Now I can't even pull the info for the resource out of the state file to import it (after removing it from state first, because the infoblox v2 provider won't allow updating an infoblox_ip_allocation resource in place).

Please have the import function ONLY touch the resource that is being imported.

JkhatriInfobox commented 4 months ago

Hi @grimm26, Certainly! Could you please provide additional details about the specific versions you are encountering issues with? This will help me better understand the context and provide more targeted assistance.

grimm26 commented 4 months ago

Hi @grimm26, Certainly! Could you please provide additional details about the specific versions you are encountering issues with? This will help me better understand the context and provide more targeted assistance.

I have infoblox resources that have been created and managed with v1.1.1 of the infoblox provider. I am attempting to upgrade to v2.5.0 of the infoblox provider. the infoblox_ip_allocation resource is the only one that we use that does not allow direct upgrade from v1.1.1 to v2.5.0 so those resources have to be removed from terraform state and then imported again.

The problem is that once I remove and import the first one, it changes the data structure of ALL infoblox_ip_allocation resources in the state file. This effectively deletes all of the information out of the state file for those resources thereby breaking my migration.

My migration steps roughly were:

  1. terraform state list |grep infoblox_ip_allocation
  2. loop through infoblox_ip_allocation resources found:
    1. terraform state show infoblox_ip_allocation.foo # save info
    2. terraform state rm infoblox_ip_allocation.foo
    3. add terraform id to HOST record (creating new HOST record if needed)
    4. terraform import infoblox_ip_allocation.foo XXXXXXXX The first time through that loop, all of the information for other infoblox_ip_allocation resources is deleted.

I ended up writing a script to just manually edit the state file to finally be over with this years long debacle of trying to upgrade from v1.1.1