Vsphere virtual machines: how to apply domain configuration to resolv.conf and eth configuration

278 views
Skip to first unread message

Luca I

unread,
May 5, 2016, 10:54:11 AM5/5/16
to Terraform
Hi.

Is there a way to apply domain configuration to /etc/resolv.conf and to ethernet configuration? These are my tf settings:

#define variable from terraform.tvars
variable "vsphere_user"       {}
variable "vsphere_password"   {}
variable "vsphere_server"     {}
variable "vsphere_cluster"    {}
variable "vsphere_datacenter" {}
variable "vsphere_domain"     {}
variable "vsphere_dns"        {}

# Configure the VMware vSphere Provider
provider "vsphere" {
  user           = "${var.vsphere_user}"
  password       = "${var.vsphere_password}"
  vsphere_server = "${var.vsphere_server}"
  allow_unverified_ssl = true
}

# Create a folder
resource "vsphere_folder" "testfolder" {
  path = "TEST/Vms"
  datacenter = "${var.vsphere_datacenter}"
}

# Create a virtual machine within the folder
resource "vsphere_virtual_machine" "web" {
  name   = "terraform-web"
  folder = "${vsphere_folder.testfolder.path}"
  vcpu   = 2
  memory = 2048
  datacenter = "${var.vsphere_datacenter}"
  cluster = "${var.vsphere_cluster}"
  domain = "my.custom.domain"
  gateway = "172.16.1.1"
  dns_servers = ["172.16.1.34"]
  #resource_pool = ""

  network_interface {
    label = "virtualwire_Template"
    ipv4_address = "172.16.1.2"
    ipv4_prefix_length = "28"
  }

  disk {
    template = "TEMPLATE/mytemplate"
  }
}


Configurations on new VM are correct on hosts file, but on resolv.conf and eth there is a default value (vsphere.local):

-/etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.2 terraform-web.my.custom.domain terraform-web

-/etc/resolv.conf
search vsphere.local
nameserver 172.16.1.34

-/etc/sysconfig/network-scripts/ifcfg-eth0
HWADDR=00:50:56:a0:12:4c
NAME=eth0
GATEWAY=172.16.1.1
DNS1=172.16.1.34
DOMAIN=vsphere.local
DEVICE=eth0
ONBOOT=yes
USERCTL=no
BOOTPROTO=static
NETMASK=255.255.255.240
IPADDR=172.16.1.2
PEERDNS=no
IPV6INIT=no

check_link_down() {
 return 1;
}

Thanks,
Luca.

Reply all
Reply to author
Forward
0 new messages