-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
feat(vm): Add support for setting the VM TPM State device #743
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rgl! Thank you so much for contributing this feature!
I've added a few missing pieces to make CustomTPMState
encoding / decoding work. After that I was able to create a VM without issues:
I've also removed Size
field from CustomTPMState
, as we can't readlly do anything with the size of TPM.
Overall it looks really good! The next steps would be to:
- add proof of work
- add documentation
- perhaps check how does it work when cloning a VM with tpm
Feel free to reach out with any questions, will be happy to help!
fmt.Sprintf("file=%s", r.FileVolume), | ||
} | ||
|
||
if r.Version != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit puzzled about this. When, in my terraform program, I just use tpm_state {}
, it seems this is being nil
because what end's up being created in proxmox is a v1.2
TPM device, but shouldn't this be v2.0
instead (because that's the default value set in the terraform schema definition)?
PS I'm now even more puzzled, since, after the first terraform apply, I've modified the terraform program to use tpm_state { version = "v2.0" }
, but that change was not picked up by the next terraform apply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's odd. What is in the TF output? When I'm using the same tpm_state {}
the TF prints out this:
<skipped>
+ tpm_state {
+ datastore_id = "local-lvm"
+ version = "v2.0"
}
}
Plan: 1 to add, 0 to change, 0 to destroy.
proxmox_virtual_environment_vm.ubuntu_vm: Creating...
proxmox_virtual_environment_vm.ubuntu_vm: Creation complete after 7s [id=453]
and VM gets creating with expected TPM.
Probably your local TF state got messed up after renaming? The provider's default version v2.0
was not set to the correct attribute, and when provider was reading the state it got no version. Then when this was pushed to TF the PVE's default (i assume it is 1.2) got applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When in doubt, I always destroy everything and delete the tfstate, but it still does not work as I expected.
I do see the same diff as you, with v2.0
, but all the requests/responses to/from proxmox do not mention version=v2.0
at all, in fact, there is no version
argument floating around at all, so the default proxmox tpm version of v1.2
is used. And I still don't known why this is happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... I'll try to debug it today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to mention:
- I'm using terraform 1.6.4
- I'm using proxmox 8.1.3
- I'm using https://github.com/rgl/terraform-proxmox-debian-example to clone an UEFI debian base image that was previously created by https://github.com/rgl/debian-vagrant#proxmox-usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it's about cloning then! :) Fixed a small bug in vmGetTPMState
, should be working now.
BTW, this is a bare minimum template I used for testing TPM, takes a second to apply:
resource "proxmox_virtual_environment_vm" "ubuntu_vm_template" {
name = "453-test-template"
node_name = "pve"
vm_id = 453
started = false
template = true
}
resource "proxmox_virtual_environment_vm" "ubuntu_vm_cloned" {
depends_on = [proxmox_virtual_environment_vm.ubuntu_vm_template]
name = "453-test-tpm"
node_name = "pve"
vm_id = 454
clone {
vm_id = 453
}
tpm_state {
datastore_id = "local-lvm"
version = "v2.0"
}
started = false
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you! its now working nicely!
I've rebased the branch over v0.39.0. the final PR should be squashed if you agree.
I will do the remaining tasks that you've asked initially.
Signed-off-by: Rui Lopes <[email protected]>
Signed-off-by: Pavel Boldyrev <[email protected]>
Signed-off-by: Rui Lopes <[email protected]>
Signed-off-by: Pavel Boldyrev <[email protected]>
Signed-off-by: Rui Lopes <[email protected]>
Signed-off-by: Rui Lopes <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work, thank a lot @rgl for contributing this!
I like your very detailed Proof of Work 🤩
LGTM! 🚀
Add support for setting the VM TPM State hardware.
Please feel free to squash all the commits.
The TPM State hardware can be declared as:
Contributor's Note
/docs
for any user-facing features or additions./example
for any new or updated resources / data sources.make example
to verify that the change works as expected.I've partially executed the example (see error after the screenshot). Here's the screenshot of the example created VM that shows it with the TPM State device:
Here's the error (which seems not related to this PR):
Proof of Work
Given the following terraform program:
terraform apply
looks like:And the end result in Proxmox looks like:
Community Note
Closes #453