Telmate / terraform-provider-proxmox

Terraform provider plugin for proxmox
MIT License
2.17k stars 523 forks source link

Attributes are not pulled, if a machine is imported #745

Closed jsaalfeld closed 8 months ago

jsaalfeld commented 1 year ago

Create new Virtual Machine in Proxmox (without Terraform!):

 * General:
  * Any name, I choose "TF-RESET-TEST"
  * ID doesnt really matter, i choose 3500
 * OS:
  * "Do not attach Drive"
  * Guest OS Type: Linux, Version: 5.x - 2.6 Kernel
 * System:
  * Leave all to default
  * Check that SCSI Controller is set to VirtIO SCSI Single
 * Disks:
  * Bus: SCSI / 0
  * Storage: I choose our Proxmox Ceph
  * Size: 20G
  * No SSD Emulation
  * Backup enabled
  * No Discard
  * IO Thread enabled
 * CPU:
  * 1 Socket
  * 1 CPU
  * Leave architecture on "default"
 * Memory:
  * Ballooning active
  * Size: 2048
 * Network:
  * Choose your standard settings for testing machines

Use these steps to avoid https://github.com/Telmate/terraform-provider-proxmox/issues/744

Go to your local console and create a new directory and add the main.tf:

terraform {
  required_providers {
    proxmox = {
      source  = "telmate/proxmox"
      version = "2.9.14"
    }
  }
}

provider "proxmox" {
  pm_api_url      = "https://#IP:8006/api2/json"
  pm_tls_insecure = true
  pm_user         = "#USER@pve"
  pm_password     = "#PASS"
}

And now - Import!:

terraform init

echo 'resource "proxmox_vm_qemu" "TF-RESET-TEST" {
  # (resource arguments)
}' > TF-RESET-TEST.tf

terraform import proxmox_vm_qemu.TF-RESET-TEST #NODE-NAME/qemu/3500

terraform state show -no-color proxmox_vm_qemu.TF-RESET-TEST > TF-RESET-TEST.tf

first of all, remove the entries, that are only information sources and can't be set:

sed '/storage_type/d' -i TF-RESET-TEST.tf
sed '/unused_disk/d' -i TF-RESET-TEST.tf
sed '/reboot_required/d' -i TF-RESET-TEST.tf
sed '/id/d' -i TF-RESET-TEST.tf
terraform fmt

Maybe change the network, since sometimes the network bridge is off.

Verify your lokal state:

% terraform plan
proxmox_vm_qemu.TF-RESET-TEST: Refreshing state... [id=pve-ni-04/qemu/3500]

Terraform used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # proxmox_vm_qemu.TF-RESET-TEST will be updated in-place
  ~ resource "proxmox_vm_qemu" "TF-RESET-TEST" {
      + additional_wait           = 5
      + automatic_reboot          = true
      + clone_wait                = 10
      + guest_agent_ready_timeout = 100
        id                        = "#NODE/qemu/3500"
        name                      = "TF-RESET-TEST"
      + preprovision              = true
      + vlan                      = -1
        # (26 unchanged attributes hidden)

        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

───────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't
guarantee to take exactly these actions if you run "terraform apply" now.

And now check for the attributes (https://registry.terraform.io/providers/Telmate/proxmox/latest/docs/resources/vm_qemu#attribute-reference):

% terraform state pull | grep default_ipv4
            "default_ipv4_address": null,
% terraform state pull | grep ssh_host
            "ssh_host": null,
% terraform state pull | grep ssh_port
            "ssh_port": null,

The IP Adress will be listed fine in your machine overview and can be hard-coded into the Cloud-Init file. But it won't show up as a resource.

2023-04-17 12_10_09-pve-ni-01 - Proxmox Virtual Environment - Brave

2023-04-17 12_07_45-pve-ni-01 - Proxmox Virtual Environment - Brave

You will encounter this issue only, when you import a machine. When the machine is created via terraform, the attributes will be pulled correctly.

This was tested with Proxmox 7.3 and Terraform 1.4.4.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 60 days with no activity. Please update the provider to the latest version and, in the issue persist, provide full configuration and debug logs

jsaalfeld commented 1 year ago

The Issue Persist with the currently latest Proxmox, Terraform und Provider-Version.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 60 days with no activity. Please update the provider to the latest version and, in the issue persist, provide full configuration and debug logs

jsaalfeld commented 1 year ago

not stale

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 60 days with no activity. Please update the provider to the latest version and, in the issue persist, provide full configuration and debug logs

thigg commented 1 year ago

Stale not

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 60 days with no activity. Please update the provider to the latest version and, in the issue persist, provide full configuration and debug logs

thigg commented 10 months ago

Please disable this bot

github-actions[bot] commented 8 months ago

This issue is stale because it has been open for 60 days with no activity. Please update the provider to the latest version and, in the issue persist, provide full configuration and debug logs

github-actions[bot] commented 8 months ago

This issue was closed because it has been inactive for 5 days since being marked as stale.

JimKlapwijk commented 7 months ago

Still happens.