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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when creating proxmox_virtual_environment_file with source_file: Provider produced inconsistent result after apply #211

Closed
mikwaluk opened this issue Jan 19, 2023 · 8 comments · Fixed by #308
Labels
🐛 bug Something isn't working

Comments

@mikwaluk
Copy link

mikwaluk commented Jan 19, 2023

Describe the bug
I'm currently playing around with the example and wanted to move the cloud-init user config to a separate file and replace the option source_raw with source_file.

When I do it, during terraform apply, I get the following error:

│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to proxmox_virtual_environment_file.user_config, provider "provider[\"gitlab.com/bpg/proxmox\"]" produced an unexpected new value: Root resource was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

To Reproduce
In the example folder, within file resource_virtual_environment_file.tf I replaced the source_raw parameter

source_raw {
    data = <<EOF
#cloud-config
chpasswd:
  list: |
    ubuntu:example
  expire: false
hostname: terraform-provider-proxmox-example
users:
  - default
  - name: ubuntu
    groups: sudo
    shell: /bin/bash
    ssh-authorized-keys:
      - ${trimspace(tls_private_key.example.public_key_openssh)}
    sudo: ALL=(ALL) NOPASSWD:ALL
    EOF

    file_name = "terraform-provider-proxmox-example-user-config.yaml"
}

with

source_file {
    path = "files/user_config.yml"
    file_name = "terraform-provider-proxmox-example-user-config.yaml"
  }

And moved those configs to a file files/user_config.yml within the example directory.
(I applied some modifications so it doesn't use that tls private key anymore).

Expected behavior
I expected it to work the same way as before, creating the resource on the Proxmox server.

Screenshots
image

Additional info
I tried using both the absolute and relative paths, and also a URL, but it didn't help.

@mikwaluk mikwaluk added the 🐛 bug Something isn't working label Jan 19, 2023
@bpg
Copy link
Owner

bpg commented Jan 22, 2023

Hey @mikwaluk, thanks for the report!

I'd like to clarify the exact use case -- have you applied the original template first, then replaced source_raw with source_file, and then tried to apply the updated template when you've got this error message?

@codestrong
Copy link

I get the same error and my template had source_file from the beginning, never used source_raw.

@bpg
Copy link
Owner

bpg commented Mar 13, 2023

Hey @codestrong! Would you mind to share your template?
(please redact any private data in it)

@vctrferreira
Copy link

I'm having a pretty similar problem...

@bpg
Copy link
Owner

bpg commented Apr 15, 2023

Hi @vctrferreira! Would you mind sharing your template and giving a bit more detail about the use case, so I can reproduce it and identify the error? It doesn't seem like I'm able to reproduce it.

My template:

resource "proxmox_virtual_environment_vm" "ubuntu_vm" {
  name        = "211-test"

  node_name = var.virtual_environment_node_name
  vm_id       = 211

  agent {
    enabled = true
  }

  cpu {
    cores = 2
  }

  memory {
    dedicated = 2048
  }

  disk {
    datastore_id = "local"
    file_id      = proxmox_virtual_environment_file.ubuntu_cloud_image.id
    interface    = "virtio0"
    iothread     = true
    discard      = "on"
    size         = 20
  }

  initialization {
    ip_config {
      ipv4 {
        address = "dhcp"
      }
    }

    user_data_file_id = proxmox_virtual_environment_file.cloud_config.id
 }

  network_device {
    bridge = "vmbr0"
  }

}

resource "proxmox_virtual_environment_file" "ubuntu_cloud_image" {
  content_type = "iso"
  datastore_id = "local"
  node_name    = var.virtual_environment_node_name

  source_file {
    path = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
  }
}

resource "proxmox_virtual_environment_file" "cloud_config" {
  content_type = "snippets"
  datastore_id = "local"
  node_name    = var.virtual_environment_node_name

  source_file {
    path = "files/cloud-config.yaml"
    file_name = "terraform-provider-proxmox-example-cloud-config.yaml"
  }
}

and files/cloud-config.yaml

#cloud-config
users:
  - default
  - name: ubuntu
    groups:
      - sudo
    shell: /bin/bash
    ssh_authorized_keys:
      - ssh-rsa AAAAB3NzaC1yc2EAxxxxxxxxxxxxxxxxxxxxxxxx
    sudo: ALL=(ALL) NOPASSWD:ALL
runcmd:
  - apt update
  - apt install -y qemu-guest-agent net-tools
  - timedatectl set-timezone America/Toronto
  - systemctl enable qemu-guest-agent
  - systemctl start qemu-guest-agent
  - echo "done" > /tmp/cloud-init-done

works fine 🤔

@bpg bpg added the ⌛ pending author's response Requested additional information from the reporter label Apr 15, 2023
@bpg
Copy link
Owner

bpg commented Apr 18, 2023

Version v0.18.0 may produce a better error message for such use cases.

@vctrferreira
Copy link

vctrferreira commented Apr 19, 2023

I've already updated the package to the latest version available, still got some errors

this is my resource:

resource "proxmox_virtual_environment_file" "cloud_config" {
  content_type = "snippets"
  datastore_id = "local"
  node_name    = "Default"

  source_file {
    path      = "user-data/cloud-config.yaml"
    file_name = "cloud-config.yaml"
  }

}

The current error:

proxmox_virtual_environment_file.cloud_config: Creating...
╷
│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to
│ proxmox_virtual_environment_file.cloud_config, provider 
│ "provider[\"registry.terraform.io/bpg/proxmox\"]"       
│ produced an unexpected new value: Root resource was     
│ present, but now absent.
│
│ This is a bug in the provider, which should be reported 
│ in the provider's own issue tracker.

I don't know if this is important but I'm using terraform with Windows 11. maybe this information could be relevant but I also try it with WSL, but got the same error

@bpg
Copy link
Owner

bpg commented Apr 19, 2023

Ahhh, yes, that was it. Thanks for the details!
I was able to reproduce this error on Windows. The classic problem -- \ vs / path separator, plus a logic bug in the code.

Will make a fix later this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants