=============== LIBRARY RULES =============== From library maintainers: - Provider source is `bpg/proxmox` in `required_providers` — not the unmaintained `danitso/proxmox` fork it descends from. - Newer resources use the short `proxmox_` prefix; legacy resources use `proxmox_virtual_environment_`. Both ship in the same provider binary. - Prefer API token auth (`api_token`) over username/password. Some resources (file uploads, certain VM/LXC operations) additionally require an `ssh` block on the provider. - For VMs with `started = true`, attach a bootable disk (e.g. cloud image) first, and set `stop_on_destroy = true` so Terraform can destroy running VMs. - Target Proxmox VE 9.x. PVE 8.x mostly works but is not actively tested; PVE 7.x is unsupported. ### Configure Example Deployment Variables Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/README.md Set up the necessary variables in `terraform.tfvars` to deploy example resources. Ensure these match your Proxmox environment configuration. ```sh virtual_environment_endpoint = "https://pve.example.com:8006/" virtual_environment_ssh_username = "terraform" virtual_environment_api_token = "terraform@pve!provider=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" virtual_environment_root_password = "your-root-password" ``` -------------------------------- ### Create Custom Cloud-Init User Data Snippet Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/guides/cloud-init.md This snippet defines a custom cloud-init configuration for a Ubuntu VM, including hostname, user setup, package installation (qemu-guest-agent, net-tools, curl), and running commands to enable and start the guest agent. It uses a local file data source to inject an SSH public key. ```terraform data "local_file" "ssh_public_key" { filename = "./id_rsa.pub" } resource "proxmox_virtual_environment_file" "user_data_cloud_config" { content_type = "snippets" datastore_id = "local" node_name = "pve" source_raw { data = <<-EOF #cloud-config hostname: test-ubuntu timezone: America/Toronto users: - default - name: ubuntu groups: - sudo shell: /bin/bash ssh_authorized_keys: - ${trimspace(data.local_file.ssh_public_key.content)} sudo: ALL=(ALL) NOPASSWD:ALL package_update: true packages: - qemu-guest-agent - net-tools - curl runcmd: - systemctl enable qemu-guest-agent - systemctl start qemu-guest-agent - echo "done" > /tmp/cloud-config.done EOF file_name = "user-data-cloud-config.yaml" } } ``` -------------------------------- ### Install and Run tfplugindocs for Documentation Generation Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/guides/dev-troubleshooting.md Ensure the correct version of tfplugindocs is installed using 'go install' before running 'make docs' to generate provider documentation. ```bash go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs make docs ``` -------------------------------- ### Running Proxmox Terraform Examples Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/guides/dev-proxmox-setup.md Execute all defined Terraform resources in the example directory against your Proxmox instance using the provided make command. ```sh make example ``` -------------------------------- ### Example Usage of proxmox_sdn_vnet Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/sdn_vnet.md Demonstrates how to configure SDN Zones and VNets, including basic and isolated VNet setups. Ensure the proxmox_sdn_applier resource is used to apply configurations. ```terraform # SDN Zone (Simple) - Basic zone for simple vnets resource "proxmox_sdn_zone_simple" "example_zone_1" { id = "zone1" # nodes = ["pve"] # Optional: omit to apply to all nodes in cluster mtu = 1500 # Optional attributes dns = "1.1.1.1" dns_zone = "example.com" ipam = "pve" reverse_dns = "1.1.1.1" depends_on = [ proxmox_sdn_applier.finalizer ] } # SDN Zone (Simple) - Second zone for demonstration resource "proxmox_sdn_zone_simple" "example_zone_2" { id = "zone2" # nodes = ["pve"] # Optional: omit to apply to all nodes in cluster mtu = 1500 depends_on = [ proxmox_sdn_applier.finalizer ] } # Basic VNet (Simple) resource "proxmox_sdn_vnet" "basic_vnet" { id = "vnet1" zone = proxmox_sdn_zone_simple.example_zone_1.id depends_on = [ proxmox_sdn_applier.finalizer ] } # VNet with Alias and Port Isolation resource "proxmox_sdn_vnet" "isolated_vnet" { id = "vnet2" zone = proxmox_sdn_zone_simple.example_zone_2.id alias = "Isolated VNet" isolate_ports = true vlan_aware = false depends_on = [ proxmox_sdn_applier.finalizer ] } # SDN Applier for all resources resource "proxmox_sdn_applier" "vnet_applier" { depends_on = [ proxmox_sdn_zone_simple.example_zone_1, proxmox_sdn_zone_simple.example_zone_2, proxmox_sdn_vnet.basic_vnet, proxmox_sdn_vnet.isolated_vnet ] } resource "proxmox_sdn_applier" "finalizer" { } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_hardware_mapping_usb Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_hardware_mapping_usb.md This example shows how to use the `proxmox_virtual_environment_hardware_mapping_usb` data source to retrieve a USB hardware mapping and output its value. ```terraform data "proxmox_virtual_environment_hardware_mapping_usb" "example" { name = "example" } output "data_proxmox_virtual_environment_hardware_mapping_usb" { value = data.proxmox_virtual_environment_hardware_mapping_usb.example } ``` -------------------------------- ### Example Usage of proxmox_sdn_zone_simple Data Source Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/sdn_zone_simple.md This example demonstrates how to retrieve and output the details of a Simple Zone using the proxmox_sdn_zone_simple data source. Ensure the 'id' attribute matches an existing zone. ```terraform data "proxmox_sdn_zone_simple" "example" { id = "simple1" } output "data_proxmox_sdn_zone_simple" { value = { id = data.proxmox_sdn_zone_simple.example.id nodes = data.proxmox_sdn_zone_simple.example.nodes mtu = data.proxmox_sdn_zone_simple.example.mtu dns = data.proxmox_sdn_zone_simple.example.dns dns_zone = data.proxmox_sdn_zone_simple.example.dns_zone ipam = data.proxmox_sdn_zone_simple.example.ipam reverse_dns = data.proxmox_sdn_zone_simple.example.reverse_dns } } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_hardware_mapping_dir Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_hardware_mapping_dir.md Demonstrates how to use the proxmox_virtual_environment_hardware_mapping_dir data source to retrieve a directory mapping by its name and output its details. ```terraform data "proxmox_virtual_environment_hardware_mapping_dir" "example" { name = "example" } output "data_proxmox_virtual_environment_hardware_mapping_dir" { value = data.proxmox_virtual_environment_hardware_mapping_dir.example } ``` -------------------------------- ### Example proxmox_virtual_environment_realm_ldap and proxmox_virtual_environment_realm_sync usage Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_realm_sync.md This example demonstrates how to configure an LDAP realm and then trigger a synchronization for it. It shows setting up the LDAP server details and then configuring the sync scope, removal of vanished entries, and enabling new users. ```terraform resource "proxmox_virtual_environment_realm_ldap" "example" { realm = "example-ldap" server1 = "ldap.example.com" port = 389 base_dn = "ou=people,dc=example,dc=com" user_attr = "uid" # Enable group sync group_dn = "ou=groups,dc=example,dc=com" group_filter = "(objectClass=groupOfNames)" } resource "proxmox_virtual_environment_realm_sync" "example" { realm = proxmox_virtual_environment_realm_ldap.example.realm # Sync both users and groups scope = "both" # Remove entries that no longer exist in LDAP remove_vanished = "acl;entry;properties" # Enable new users/groups by default enable_new = true } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_hardware_mapping_pci Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_hardware_mapping_pci.md This example demonstrates how to use the proxmox_virtual_environment_hardware_mapping_pci data source to retrieve a PCI hardware mapping configuration and output its details. ```terraform data "proxmox_virtual_environment_hardware_mapping_pci" "example" { name = "example" } output "data_proxmox_virtual_environment_hardware_mapping_pci" { value = data.proxmox_virtual_environment_hardware_mapping_pci.example } ``` -------------------------------- ### Example proxmox_realm_sync Usage Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/realm_sync.md This example demonstrates how to configure a proxmox_realm_ldap resource and then use proxmox_realm_sync to synchronize it. It shows how to specify the sync scope, handle vanished entries, and enable new users. ```terraform resource "proxmox_realm_ldap" "example" { realm = "example-ldap" server1 = "ldap.example.com" port = 389 base_dn = "ou=people,dc=example,dc=com" user_attr = "uid" # Enable group sync group_dn = "ou=groups,dc=example,dc=com" group_filter = "(objectClass=groupOfNames)" } resource "proxmox_realm_sync" "example" { realm = proxmox_realm_ldap.example.realm # Sync both users and groups scope = "both" # Remove entries that no longer exist in LDAP remove_vanished = "acl;entry;properties" # Enable new users/groups by default enable_new = true } ``` -------------------------------- ### List all Replications Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_replications.md This example shows how to retrieve all replication configurations from Proxmox using the `proxmox_virtual_environment_replications` data source and output the results. ```terraform # List all Replications data "proxmox_virtual_environment_replications" "all" {} output "data_proxmox_virtual_environment_replications_all" { value = { replications = data.proxmox_virtual_environment_replications.all.replications } } ``` -------------------------------- ### Example proxmox_sdn_zone_evpn Resource Configuration Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/sdn_zone_evpn.md This snippet shows a complete example of how to configure an EVPN zone resource, including required and optional attributes. ```terraform resource "proxmox_sdn_zone_evpn" "example" { id = "evpn1" nodes = ["pve"] controller = "evpn-controller1" vrf_vxlan = 4000 # Optional attributes advertise_subnets = true disable_arp_nd_suppression = false exit_nodes = ["pve-exit1", "pve-exit2"] exit_nodes_local_routing = true primary_exit_node = "pve-exit1" rt_import = "65000:65000" mtu = 1450 # Generic optional attributes dns = "1.1.1.1" dns_zone = "example.com" ipam = "pve" reverse_dns = "1.1.1.1" } ``` -------------------------------- ### Example Usage of proxmox_hardware_mapping_dir Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/hardware_mapping_dir.md Demonstrates how to use the proxmox_hardware_mapping_dir data source to retrieve a directory mapping by its name and output the retrieved data. ```terraform data "proxmox_hardware_mapping_dir" "example" { name = "example" } output "data_proxmox_hardware_mapping_dir" { value = data.proxmox_hardware_mapping_dir.example } ``` -------------------------------- ### SDN Applier Example Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_sdn_applier.md This example demonstrates how to use the proxmox_virtual_environment_sdn_applier resource to trigger SDN configuration changes after SDN zone resources are created. It includes two simple SDN zones and an applier resource that depends on them and uses `replace_triggered_by` to ensure the applier runs after the zones are configured. ```terraform resource "proxmox_virtual_environment_sdn_zone_simple" "example_zone_1" { id = "zone1" nodes = ["pve"] mtu = 1500 # Optional attributes dns = "1.1.1.1" dns_zone = "example.com" ipam = "pve" reverse_dns = "1.1.1.1" depends_on = [ proxmox_virtual_environment_sdn_applier.finalizer ] } # SDN Zone (Simple) - Second zone for applier demonstration resource "proxmox_virtual_environment_sdn_zone_simple" "example_zone_2" { id = "zone2" nodes = ["pve"] mtu = 1500 depends_on = [ proxmox_virtual_environment_sdn_applier.finalizer ] } # SDN Applier - Applies SDN configuration changes resource "proxmox_virtual_environment_sdn_applier" "example_applier" { lifecycle { replace_triggered_by = [ proxmox_virtual_environment_sdn_zone_simple.example_zone_1, proxmox_virtual_environment_sdn_zone_simple.example_zone_2, ] } depends_on = [ proxmox_virtual_environment_sdn_zone_simple.example_zone_1, proxmox_virtual_environment_sdn_zone_simple.example_zone_2, ] } resource "proxmox_virtual_environment_sdn_applier" "finalizer" { } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_hardware_mapping_dir Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_hardware_mapping_dir.md This snippet shows how to define a directory mapping resource with a comment, name, and a map of devices including the node and path. ```terraform resource "proxmox_virtual_environment_hardware_mapping_dir" "example" { comment = "This is a comment" name = "example" # The actual map of devices. map = [ { node = "pve" path = "/mnt/data" }, ] } ``` -------------------------------- ### Basic VM Retrieval by Tags Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_vms.md Example of retrieving all VMs that have the tag 'ubuntu'. This is a simple filter based on a single tag. ```hcl data "proxmox_virtual_environment_vms" "ubuntu_vms" { tags = ["ubuntu"] } ``` -------------------------------- ### List all SDN VNets Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_sdn_vnets.md This example shows how to retrieve all SDN VNets and output their details. Note that this data source is deprecated. ```terraform data "proxmox_virtual_environment_sdn_vnets" "all" {} output "data_proxmox_virtual_environment_sdn_vnets_all" { value = { vnets = data.proxmox_virtual_environment_sdn_vnets.all.vnets } } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_vm Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_vm.md This snippet shows how to retrieve information about a specific virtual machine by providing its node name and VM ID. ```hcl data "proxmox_virtual_environment_vm" "test_vm" { node_name = "test" vm_id = 100 } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_groups Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_groups.md This snippet shows how to use the proxmox_virtual_environment_groups data source to retrieve information about available groups. No arguments are required. ```hcl data "proxmox_virtual_environment_groups" "available_groups" {} ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_sdn_zone_simple Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_sdn_zone_simple.md This snippet demonstrates how to configure a simple SDN zone with basic settings like ID, nodes, and MTU, along with optional DNS and IPAM configurations. ```terraform resource "proxmox_virtual_environment_sdn_zone_simple" "example" { id = "simple1" nodes = ["pve"] mtu = 1500 # Optional attributes dns = "1.1.1.1" dns_zone = "example.com" ipam = "pve" reverse_dns = "1.1.1.1" } ``` -------------------------------- ### Configure InfluxDB Metrics Server Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/metrics_server.md Example of configuring an InfluxDB metrics server. Ensure the server details and port are correct for your InfluxDB setup. ```terraform resource "proxmox_metrics_server" "influxdb_server" { name = "example_influxdb_server" server = "192.168.3.2" port = 8089 type = "influxdb" } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_apt_standard_repository Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_apt_standard_repository.md Demonstrates how to retrieve an APT standard repository using its handle and the target node. This snippet also shows how to output the retrieved data. ```terraform data "proxmox_virtual_environment_apt_standard_repository" "example" { handle = "no-subscription" node = "pve" } output "proxmox_virtual_environment_apt_standard_repository" { value = data.proxmox_virtual_environment_apt_standard_repository.example } ``` -------------------------------- ### Get Proxmox VE IP Address Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/guides/dev-proxmox-setup.md After installing Proxmox VE, find the assigned IP address of the virtual machine. This IP is used for SSH access and accessing the web console. ```text root@proxmox:~# ip a ... 3: vmbr0: mtu 1500 ... inet 192.168.122.43/24 scope global vmbr0 ... ``` -------------------------------- ### Example Usage of proxmox_apt_standard_repository Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/apt_standard_repository.md Demonstrates how to retrieve an APT standard repository using its handle and the target node. The output displays the retrieved repository's details. ```terraform data "proxmox_apt_standard_repository" "example" { handle = "no-subscription" node = "pve" } output "proxmox_apt_standard_repository" { value = data.proxmox_apt_standard_repository.example } ``` -------------------------------- ### Get Time from a Proxmox VE Node Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_time.md Use this data source to retrieve the current local time, time zone, and UTC time from a specific Proxmox VE node by its name. No additional setup is required beyond providing the node's name. ```hcl data "proxmox_virtual_environment_time" "first_node_time" { node_name = "first-node" } ``` -------------------------------- ### Clone with Disk Management Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_cloned_vm.md This example demonstrates cloning a VM and managing its disks. It includes resizing an existing boot disk (`scsi0`) and adding a new data disk (`scsi1`), specifying datastore, size, discard, and SSD properties. ```terraform resource "proxmox_virtual_environment_cloned_vm" "disk_managed" { node_name = "pve" name = "disk-clone" clone = { source_vm_id = 100 target_datastore = "local-lvm" } # Map-based disk management disk = { scsi0 = { # Resize the cloned boot disk datastore_id = "local-lvm" size_gb = 50 discard = "on" ssd = true } scsi1 = { # Add a new data disk datastore_id = "local-lvm" size_gb = 100 backup = false } } } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_apt_standard_repository Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_apt_standard_repository.md This snippet shows how to define an APT standard repository and then reference its attributes to configure a separate APT repository. Use this when you need to manage standard repositories and then use their details for other configurations. ```terraform resource "proxmox_virtual_environment_apt_standard_repository" "example" { handle = "no-subscription" node = "pve" } resource "proxmox_virtual_environment_apt_repository" "example" { enabled = true file_path = proxmox_virtual_environment_apt_standard_repository.example.file_path index = proxmox_virtual_environment_apt_standard_repository.example.index node = proxmox_virtual_environment_apt_standard_repository.example.node } ``` -------------------------------- ### Install virt-manager Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/guides/dev-proxmox-setup.md Install the virt-manager package on Debian-based systems. This tool is used to create and manage virtual machines. ```sh sudo apt-get install virt-manager ``` -------------------------------- ### Start mitmproxy for API Debugging Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/guides/dev-troubleshooting.md To inspect Proxmox API calls, start mitmproxy in regular mode on port 8080. ```bash mitmproxy --mode regular --listen-port 8080 ``` -------------------------------- ### Initialize Acceptance Test Environment Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/adr/006-testing-requirements.md Use `test.InitEnvironment(t)` to obtain provider factories and configuration helpers for setting up the test environment. ```go func TestAccResourceSDNVNet(t *testing.T) { t.Parallel() te := test.InitEnvironment(t) // te.AccProviders — pre-configured provider factories // te.RenderConfig() — template rendering with {{.NodeName}} } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_file Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_file.md Demonstrates how to use the `proxmox_virtual_environment_file` data source to retrieve information about different file types like ISOs, container templates, and cloud-init snippets. It also shows how to use the retrieved file information to configure a virtual machine. ```terraform terraform { required_providers { proxmox = { source = "bpg/proxmox" version = ">= 0.60.0" } } } provider "proxmox" { # Configuration options } data "proxmox_virtual_environment_file" "ubuntu_iso" { node_name = "pve" datastore_id = "local" content_type = "iso" file_name = "ubuntu-22.04.3-live-server-amd64.iso" } data "proxmox_virtual_environment_file" "ubuntu_container_template" { node_name = "pve" datastore_id = "local" content_type = "vztmpl" file_name = "ubuntu-22.04-standard_22.04-1_amd64.tar.zst" } data "proxmox_virtual_environment_file" "cloud_init_snippet" { node_name = "pve" datastore_id = "local" content_type = "snippets" file_name = "cloud-init-config.yaml" } data "proxmox_virtual_environment_file" "imported_file" { node_name = "pve" datastore_id = "local" content_type = "import" file_name = "imported-config.yaml" } output "ubuntu_iso_id" { value = data.proxmox_virtual_environment_file.ubuntu_iso.id } output "ubuntu_iso_size" { value = data.proxmox_virtual_environment_file.ubuntu_iso.file_size } output "container_template_format" { value = data.proxmox_virtual_environment_file.ubuntu_container_template.file_format } resource "proxmox_virtual_environment_vm" "example" { node_name = "pve" vm_id = 100 cdrom { file_id = data.proxmox_virtual_environment_file.ubuntu_iso.id } cpu { cores = 2 } memory { dedicated = 2048 } disk { datastore_id = "local-lvm" file_format = "qcow2" size = 20 } network_device { bridge = "vmbr0" } } ``` -------------------------------- ### Example Usage of proxmox_apt_repository Data Source Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/apt_repository.md Demonstrates how to retrieve APT repository information using the proxmox_apt_repository data source and output its details. ```terraform data "proxmox_apt_repository" "example" { file_path = "/etc/apt/sources.list" index = 0 node = "pve" } output "proxmox_apt_repository" { value = data.proxmox_apt_repository.example } ``` -------------------------------- ### Error Message Format Examples Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/adr/005-error-handling.md Examples illustrating the 'Unable to [Action] [Resource]' format for various resource lifecycle operations. The detail string should be err.Error(). ```text "Unable to Create SDN VNet" "Unable to Read SDN VNet After Creation" "Unable to Read SDN VNet" "Unable to Update SDN VNet" "Unable to Read SDN VNet After Update" "Unable to Delete SDN VNet" "Unable to Import SDN VNet" "SDN VNet Not Found" ``` -------------------------------- ### Proxmox HA Resource Example Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/haresource.md Example of how to define a Proxmox HA resource using Terraform. Ensure the HA group is defined and the resource ID is valid. ```terraform resource "proxmox_haresource" "example" { depends_on = [ proxmox_hagroup.example ] resource_id = "vm:123" state = "started" group = "example" comment = "Managed by Terraform" failback = true } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_apt_repository Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_apt_repository.md Demonstrates how to retrieve an APT repository configuration from a Proxmox VE node. Specify the file path, index, and node name to fetch the repository details. ```terraform data "proxmox_virtual_environment_apt_repository" "example" { file_path = "/etc/apt/sources.list" index = 0 node = "pve" } output "proxmox_virtual_environment_apt_repository" { value = data.proxmox_virtual_environment_apt_repository.example } ``` -------------------------------- ### Proxmox Virtual Environment HA Resource Example Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_haresource.md This example shows how to define a Proxmox HA resource for a virtual machine. It depends on a Proxmox HA group and sets the desired state and a comment. ```terraform resource "proxmox_virtual_environment_haresource" "example" { depends_on = [ proxmox_virtual_environment_hagroup.example ] resource_id = "vm:123" state = "started" group = "example" comment = "Managed by Terraform" } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_hardware_mappings Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_hardware_mappings.md Demonstrates how to use the proxmox_virtual_environment_hardware_mappings data source to retrieve different types of hardware mappings (dir, pci, usb) and output the PCI and USB mappings. ```terraform data "proxmox_virtual_environment_hardware_mappings" "example-dir" { check_node = "pve" type = "dir" } data "proxmox_virtual_environment_hardware_mappings" "example-pci" { check_node = "pve" type = "pci" } data "proxmox_virtual_environment_hardware_mappings" "example-usb" { check_node = "pve" type = "usb" } output "data_proxmox_virtual_environment_hardware_mappings_pci" { value = data.proxmox_virtual_environment_hardware_mappings.example-pci } output "data_proxmox_virtual_environment_hardware_mappings_usb" { value = data.proxmox_virtual_environment_hardware_mappings.example-usb } ``` -------------------------------- ### Replication Example Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/replication.md Example of how to configure a Proxmox VE replication job. This snippet shows how to set the source VM ID, target node, replication type, and optional attributes like schedule and comments. ```terraform resource "proxmox_replication" "example_replication_1" { id = "100-0" target = "pve-02" type = "local" # Optional attributes disable = false comment = "Replication to pve-02 every 30 min" schedule = "*/30" } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_sdn_zones Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_sdn_zones.md Demonstrates how to use the `proxmox_virtual_environment_sdn_zones` data source to list all SDN zones, filter by type (EVPN or Simple), and output the results. ```terraform # List all SDN zones data "proxmox_virtual_environment_sdn_zones" "all" {} # List only EVPN zones data "proxmox_virtual_environment_sdn_zones" "evpn_only" { type = "evpn" } # List only Simple zones data "proxmox_virtual_environment_sdn_zones" "simple_only" { type = "simple" } output "data_proxmox_virtual_environment_sdn_zones_all" { value = { zones = data.proxmox_virtual_environment_sdn_zones.all.zones } } output "data_proxmox_virtual_environment_sdn_zones_filtered" { value = { evpn_zones = data.proxmox_virtual_environment_sdn_zones.evpn_only.zones simple_zones = data.proxmox_virtual_environment_sdn_zones.simple_only.zones } } ``` -------------------------------- ### Basic Clone with Minimal Management Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_cloned_vm.md This example demonstrates a basic clone operation, explicitly managing only the CPU configuration and inheriting all other settings from the source template. ```terraform resource "proxmox_virtual_environment_cloned_vm" "basic_clone" { node_name = "pve" name = "basic-clone" clone = { source_vm_id = 100 # Template VM ID full = true # Perform full clone (not linked) } # Only manage CPU, inherit everything else from template cpu = { cores = 4 } } ``` -------------------------------- ### Example Usage of proxmox_hardware_mapping_dir Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/hardware_mapping_dir.md Demonstrates how to define and configure a directory mapping resource using Terraform. This includes setting a name, comment, and the specific node and path for the directory map. ```terraform resource "proxmox_hardware_mapping_dir" "example" { comment = "This is a comment" name = "example" # The actual map of devices. map = [ { node = "pve" path = "/mnt/data" }, ] } ``` -------------------------------- ### Acceptance Test File Placement Example Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/adr/006-testing-requirements.md Acceptance tests are colocated with their resource files, typically ending in '_test.go'. ```text fwprovider/cluster/sdn/vnet/ ├── resource.go ├── model.go └── resource_test.go # Acceptance tests here ``` -------------------------------- ### Basic proxmox_virtual_environment_apt_repository Usage Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_apt_repository.md This example shows how to configure a basic APT repository on a Proxmox VE node. Ensure the 'pve' node and '/etc/apt/sources.list' file path are correct for your environment. ```terraform resource "proxmox_virtual_environment_apt_repository" "example" { enabled = true file_path = "/etc/apt/sources.list" index = 0 node = "pve" } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_users Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_users.md This snippet shows how to use the proxmox_virtual_environment_users data source to retrieve all available user information. ```HCL data "proxmox_virtual_environment_users" "available_users" {} ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_hagroups Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_hagroups.md Demonstrates how to use the proxmox_virtual_environment_hagroups data source to retrieve HA group IDs and output them. ```terraform data "proxmox_virtual_environment_hagroups" "example" {} output "data_proxmox_virtual_environment_hagroups" { value = data.proxmox_virtual_environment_hagroups.example.group_ids } ``` -------------------------------- ### List all SDN VNets Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/sdn_vnets.md This example demonstrates how to use the `proxmox_sdn_vnets` data source to retrieve all available SDN VNets and then output their details. No specific configuration is required beyond having the data source defined. ```terraform data "proxmox_sdn_vnets" "all" {} output "data_proxmox_sdn_vnets_all" { value = { vnets = data.proxmox_sdn_vnets.all.vnets } } ``` -------------------------------- ### Rebuild and Reinstall Provider Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/guides/dev-troubleshooting.md If changes to the provider code are not reflected in Terraform, rebuild and reinstall the provider using 'go install .'. ```bash go install . ``` -------------------------------- ### Configure Graphite Metrics Server Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/metrics_server.md Example of configuring a Graphite metrics server. Specify the server address and the Graphite port. ```terraform resource "proxmox_metrics_server" "graphite_server" { name = "example_graphite_server" server = "192.168.4.2" port = 2003 type = "graphite" } ``` -------------------------------- ### Simple Clone using proxmox_virtual_environment_cloned_vm (New) Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/guides/migration-vm-clone.md Shows how to perform a basic VM clone using the newer proxmox_virtual_environment_cloned_vm resource. This resource offers more explicit control over devices and configuration. ```terraform resource "proxmox_virtual_environment_cloned_vm" "cloned_vm" { node_name = "pve" name = "my-cloned-vm" clone = { source_vm_id = 100 } cpu = { cores = 4 } # Map-based network devices network = { net0 = { bridge = "vmbr0" model = "virtio" } } } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_metrics_server Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_metrics_server.md Demonstrates how to configure different types of metric servers including InfluxDB, Graphite, and OpenTelemetry. Ensure the server details and types are correctly specified. ```terraform resource "proxmox_virtual_environment_metrics_server" "influxdb_server" { name = "example_influxdb_server" server = "192.168.3.2" port = 8089 type = "influxdb" } resource "proxmox_virtual_environment_metrics_server" "graphite_server" { name = "example_graphite_server" server = "192.168.4.2" port = 2003 type = "graphite" } resource "proxmox_virtual_environment_metrics_server" "opentelemetry_server" { name = "example_opentelemetry_server" server = "192.168.5.2" port = 4318 type = "opentelemetry" opentelemetry_proto = "http" opentelemetry_path = "/v1/metrics" } ``` -------------------------------- ### Basic Node Firewall Configuration Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_node_firewall.md Example of configuring basic node firewall options, including enabling or disabling the firewall. ```terraform resource "proxmox_virtual_environment_node_firewall" "node-pve1" { node_name = "pve1" enabled = false } ``` -------------------------------- ### Import an APT Standard Repository Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/apt_standard_repository.md This example shows the command to import an existing APT standard repository into Terraform state. Ensure the node name and handle match the actual configuration. ```shell #!/usr/bin/env sh # An APT standard repository can be imported using a comma-separated list consisting of the name of the Proxmox VE node, # and the standard repository handle in the exact same order, e.g.: terraform import proxmox_apt_standard_repository.example pve,no-subscription ``` -------------------------------- ### Importing a proxmox_virtual_environment_hagroup Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_hagroup.md This example demonstrates how to import an existing HA group into Terraform state. It requires the group name as an argument. ```shell #!/usr/bin/env sh # HA groups can be imported using their name, e.g.: terraform import proxmox_virtual_environment_hagroup.example example ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_user Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_user.md Use this data source to retrieve information about a specific Proxmox user by providing their user ID. ```hcl data "proxmox_virtual_environment_user" "operations_user" { user_id = "operation@pam" } ``` -------------------------------- ### Multi-step Acceptance Test with Import Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/adr/reference-examples.md An example of a multi-step acceptance test scenario that includes creating a resource, updating it, and then verifying its state through import. ```go {"create and update vnet with simple zone", []resource.TestStep{ { Config: te.RenderConfig(` resource "proxmox_virtual_environment_sdn_vnet" "test_vnet" { id = "testv" zone = proxmox_virtual_environment_sdn_zone_simple.test_zone.id alias = "Test VNet" }`), Check: resource.ComposeTestCheckFunc( test.ResourceAttributes("proxmox_virtual_environment_sdn_vnet.test_vnet", map[string]string{ "id": "testv", "zone": "testz", "alias": "Test VNet", }), ), }, { // Second step: update + import Config: te.RenderConfig(`...updated config...`), Check: resource.ComposeTestCheckFunc(...), ResourceName: "proxmox_virtual_environment_sdn_vnet.test_vnet", ImportStateId: "testv", ImportState: true, ImportStateVerify: true, }, }}, ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_firewall_rules Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/resources/virtual_environment_firewall_rules.md Demonstrates how to configure inbound firewall rules for a VM, including specific port allowances and referencing a security group. Ensure dependent resources like the VM and security group are defined. ```hcl resource "proxmox_virtual_environment_firewall_rules" "inbound" { depends_on = [ proxmox_virtual_environment_vm.example, proxmox_virtual_environment_cluster_firewall_security_group.example, ] node_name = proxmox_virtual_environment_vm.example.node_name vm_id = proxmox_virtual_environment_vm.example.vm_id rule { type = "in" action = "ACCEPT" comment = "Allow HTTP" dest = "192.168.1.5" dport = "80" proto = "tcp" log = "info" } rule { type = "in" action = "ACCEPT" comment = "Allow HTTPS" dest = "192.168.1.5" dport = "443" proto = "tcp" log = "info" } rule { security_group = proxmox_virtual_environment_cluster_firewall_security_group.example.name comment = "From security group" iface = "net0" } } ``` -------------------------------- ### Example Usage of proxmox_virtual_environment_pool Source: https://github.com/bpg/terraform-provider-proxmox/blob/main/docs/data-sources/virtual_environment_pool.md This snippet shows how to use the proxmox_virtual_environment_pool data source to retrieve information about a pool with the ID 'operations'. ```hcl data "proxmox_virtual_environment_pool" "operations_pool" { pool_id = "operations" } ```