netbox_virtual_machine.tf.j2 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. data "netbox_cluster" "{{ resource_name }}_cluster" {
  2. name = "{{ cluster_ref }}"
  3. }
  4. data "netbox_site" "{{ resource_name }}_site" {
  5. name = "{{ site_ref }}"
  6. }
  7. resource "netbox_virtual_machine" "{{ resource_name }}" {
  8. name = "{{ vm_name }}"
  9. cluster_id = data.netbox_cluster.{{ resource_name }}_cluster.id
  10. {% if site_ref %}
  11. site_id = data.netbox_site.{{ resource_name }}_site.id
  12. {% endif %}
  13. status = "{{ status }}"
  14. {% if device_ref %}
  15. device_id = netbox_device.{{ device_ref }}.id
  16. {% endif %}
  17. {% if resources_enabled %}
  18. vcpus = {{ vcpus }}
  19. memory = {{ memory_mb }}
  20. disk = {{ disk_gb }}
  21. {% endif %}
  22. {% if description_enabled %}
  23. comments = "{{ description_text }}"
  24. {% endif %}
  25. {% if depends_on_enabled %}
  26. depends_on = [{{ dependencies }}]
  27. {% endif %}
  28. {% if lifecycle_enabled %}
  29. lifecycle {
  30. {% if prevent_destroy %}
  31. prevent_destroy = true
  32. {% endif %}
  33. {% if create_before_destroy %}
  34. create_before_destroy = true
  35. {% endif %}
  36. {% if ignore_changes %}
  37. ignore_changes = [{{ ignore_changes }}]
  38. {% endif %}
  39. }
  40. {% endif %}
  41. }
  42. {% if ipam_enabled %}
  43. resource "netbox_interface" "{{ resource_name }}_interface" {
  44. name = "{{ interface_name }}"
  45. virtual_machine_id = netbox_virtual_machine.{{ resource_name }}.id
  46. }
  47. resource "netbox_ip_address" "{{ resource_name }}_ip" {
  48. ip_address = "{{ primary_ip4 }}"
  49. status = "active"
  50. {% if dns_name %}
  51. dns_name = "{{ dns_name }}"
  52. {% endif %}
  53. interface_id = netbox_interface.{{ resource_name }}_interface.id
  54. object_type = "virtualization.vminterface"
  55. }
  56. resource "netbox_primary_ip" "{{ resource_name }}_primary_ip" {
  57. ip_address_id = netbox_ip_address.{{ resource_name }}_ip.id
  58. virtual_machine_id = netbox_virtual_machine.{{ resource_name }}.id
  59. }
  60. {% endif %}