Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

After some changes in network configuration VM is recreating #2164

Open
4 tasks done
perrfect opened this issue Apr 8, 2024 · 3 comments
Open
4 tasks done

After some changes in network configuration VM is recreating #2164

perrfect opened this issue Apr 8, 2024 · 3 comments
Labels
bug Type: Bug needs-triage Status: Issue Needs Triage

Comments

@perrfect
Copy link

perrfect commented Apr 8, 2024

Community Guidelines

  • I have read and agree to the HashiCorp Community Guidelines .
  • Vote on this issue by adding a 馃憤 reaction to the original issue initial description to help the maintainers prioritize.
  • Do not leave "+1" or other comments that do not add relevant information or questions.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Terraform

1.7.5

Terraform Provider

2.7.0

VMware vSphere

7.0.0.10600

Description

After changing some network configuration a VM is recreated in the whole. The VM is cloned from a template.
Template is Rocky Linux 8.9 and installed VMware guest tools version 12.3.5.46049

Affected Resources or Data Sources

vsphere_network

Terraform Configuration

data "vsphere_datacenter" "datacenter" {
  name = var.vsphere_datacenter_name
}

data "vsphere_host" "host" {
  name          = var.vsphere_host_name
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_datastore" "datastore" {
  name          = var.vsphere_datastore_name
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_network" "network" {
  count         = length(var.vm_vsphere_networks)
  name          = var.vm_vsphere_networks[count.index].name
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_virtual_machine" "template" {
  name          = var.vsphere_template_name
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

resource "vsphere_virtual_machine" "vm" {
  name                    = var.vm_name
  resource_pool_id        = data.vsphere_host.host.resource_pool_id
  host_system_id          = data.vsphere_host.host.id
  datastore_id            = data.vsphere_datastore.datastore.id
  num_cpus                = var.vm_cpu_numbers
  memory                  = var.vm_memory
  guest_id                = var.vm_guest_id
  dynamic "network_interface" {
    for_each = data.vsphere_network.network
    content {
      network_id          = network_interface.value.id
      adapter_type        = data.vsphere_virtual_machine.template.network_interface_types[0]
    }
  }
  disk {
    label                 = var.vm_disk_label
    size                  = var.vm_disk_size
  }
  clone {
    template_uuid         = data.vsphere_virtual_machine.template.id
    customize {
      linux_options {
        host_name         = var.vm_template_clone_customize_host_name
        domain		        = var.vm_template_clone_customize_domain_name
      }
      dynamic "network_interface" {
        for_each = var.vm_vsphere_networks
        content {
          ipv4_address	  = network_interface.value.ipv4_address
          ipv4_netmask	  = network_interface.value.ipv4_netmask
          dns_server_list	= network_interface.value.dns_server_list
        }
      }
    ipv4_gateway          = var.vm_template_network_interface_ip_gateway
    }
  }
}
module "proxy-01" {
    source = "../modules/rocky"
    
    vsphere_datacenter_name                  = var.vsphere_datacenter_name
    vsphere_host_name                        = var.vsphere_host_name
    vsphere_datastore_name                   = var.vsphere_datastore_name
    vm_name                                  = "proxy-01"
    vm_cpu_numbers                           = "2"
    vm_memory                                = "2048"
    vm_guest_id                              = "rhel8_64Guest"
    vm_disk_label                            = "disk0"
    vm_disk_size                             = "15"
    vsphere_template_name                    = "rocky_8_9"
    vm_template_clone_customize_host_name    = "proxy-01"
    vm_template_clone_customize_domain_name  = "local"
    vm_vsphere_networks = [ {
        name            = "net-1G"
        ipv4_address    = "172.16.1.145"
        ipv4_netmask    = "24"
        dns_server_list = [ "172.16.1.2", "1.1.1.1" ]
        }
    ]
    vm_template_network_interface_ip_gateway = "172.16.1.1"
}

Debug Output

  # module.proxy-01.vsphere_virtual_machine.vm will be updated in-place
  ~ resource "vsphere_virtual_machine" "vm" {                                                                                                                                                                                                                                             
        id                                      = "4201fe47-20ed-5501-af1e-e3fe31a47ebf"
        name                                    = "proxy-01"    
        tags                                    = []                
        # (68 unchanged attributes hidden)                      
                                                                      
      ~ clone {                                                                                                                              
            # (5 unchanged attributes hidden)                                                                                                
                                                                                                                                             
          ~ customize {                                                                                                                      
                # (4 unchanged attributes hidden)                                                                                            
                                                                      
              ~ network_interface {                                  
                  ~ dns_server_list = [             
                      - "172.16.1.3",                              
                      + "172.16.1.2",                                                                                                      
                        "1.1.1.1",                      
                    ]                                            
                    # (3 unchanged attributes hidden)                
                }                                         
                                                                      
                # (2 unchanged blocks hidden)                                                                                                
            }                                                                                                                                
        }                                                         
                                                                                                                                             
        # (3 unchanged blocks hidden)                                                                                                        
    }                                                            
                                                                                                                                             
  # module.proxy-02.vsphere_virtual_machine.vm will be updated in-place
  ~ resource "vsphere_virtual_machine" "vm" {                                                                                                
        id                                      = "4201e046-43f4-ada5-c3e2-9ee3f709e5cf"
        name                                    = "proxy-02"                                                                            
        tags                                    = []            
        # (68 unchanged attributes hidden)                                                                                                   
                                                                      
      ~ clone {                                                                                                                              
            # (5 unchanged attributes hidden)                                                                                                
                                                                                                                                             
          ~ customize {                                              
                # (4 unchanged attributes hidden)                                                                                            
                                                                      
              ~ network_interface {                                                                                                          
                  ~ dns_server_list = [                                                                                                                                                                                                                                                   
                      - "172.16.1.3",                                                                                                      
                      + "172.16.1.2",                              
                        "1.1.1.1",                                                                                                           
                    ]                                                                                                                        
                    # (3 unchanged attributes hidden)                                                                                        
                }                                                                                                                                                                                                                                                                         
                                                                                                                                             
                # (2 unchanged blocks hidden)                                                                                                
            }                                                                                                                                
        }                                                                                                                                    
                                                                                                                                             
        # (3 unchanged blocks hidden)                                                                                                        
    }                                                                                                                                        
                                                                                                                                             
Plan: 0 to add, 2 to change, 0 to destroy.

Panic Output

No response

Expected Behavior

When changing some network configuration (e.g dns servers, netmask, gateway) a VM should not be created anew.

Actual Behavior

After changing the DNS servers list the VM is created in a new way.

Steps to Reproduce

  1. Clear Rocky Linux 8.9 system
  2. Installed VMware guest tools
  3. Create VM
  4. After creating change DNS serves a list of other network settings.

Environment Details

No response

Screenshots

No response

References

No response

@perrfect perrfect added bug Type: Bug needs-triage Status: Issue Needs Triage labels Apr 8, 2024
Copy link

github-actions bot commented Apr 8, 2024

Hello, perrfect! 馃枑

Thank you for submitting an issue for this provider. The issue will now enter into the issue lifecycle.

If you want to contribute to this project, please review the contributing guidelines and information on submitting pull requests.

@tenthirtyam
Copy link
Collaborator

Did you try ignore_changes?

@perrfect
Copy link
Author

perrfect commented Apr 8, 2024

Did you try ignore_changes?

No, I didn't try.
Should I add ignore_changes for network_interface or another resource?

  lifecycle {
    ignore_changes = [
      network_interface,
    ]
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Bug needs-triage Status: Issue Needs Triage
Projects
None yet
Development

No branches or pull requests

2 participants