Auto-update blog content from Obsidian: 2025-05-28 12:31:32
All checks were successful
Deploy / Deploy (push) Successful in 4s

This commit is contained in:
Gitea Actions
2025-05-28 12:31:32 +00:00
parent 45198461b4
commit f7e08ae058
2 changed files with 984 additions and 12 deletions

View File

@@ -1,8 +1,8 @@
---
title: Deploy VM on Proxmox with Terraform
description:
description: Learn how to deploy a VM on Proxmox using Terraform and a cloud-init template, making your infrastructure reproducible and easy to manage.
date: 2025-05-25
draft: true
draft: false
tags:
- terraform
- proxmox
@@ -34,7 +34,7 @@ To use Terraform, youll need a provider, a plugin that lets Terraform interac
- [**Telmate/proxmox**](https://registry.terraform.io/providers/Telmate/proxmox/latest): One of the original providers. Its widely used but not very actively maintained. Its simple to use, with plenty of documentation available online, but has limited features, with only 4 resources are available and no data sources: for example, I wasnt able to retrieve node resource details.
- [**bpg/proxmox**](https://registry.terraform.io/providers/bpg/proxmox/latest): A newer and more actively developed provider, apparently developed by a single guy, with cleaner syntax and much wider resources support. It was harder to setup but I found it mature enough to work with it.
I chose the `bpg/proxmox` provider because its better maintained at the time of writing and I needed to retrieve nodes values, such as their hostname.
I chose the `bpg/proxmox` provider because its better maintained at the time of writing and I needed to retrieve nodes values, such as their hostname, etc.
---
## Prepare the Environment
@@ -45,7 +45,7 @@ Check out my previous article on [Proxmox - Create a Cloud-Init VM Template]({{<
### Install Terraform
For the Terraform installation, I followed the [documentation](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) to install it into my LXC container.
For the Terraform installation into my LXC container, I followed the [documentation](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli).
```bash
# Ensure that your system is up to date and you have installed the `gnupg`, `software-properties-common`, and `curl` packages installed. You will use these packages to verify HashiCorp's GPG signature and install HashiCorp's Debian package repository.
@@ -111,7 +111,7 @@ pveum user add terraformer@pve --password <password>
pveum aclmod / -user terraformer@pve -role TerraformUser
```
4. **Create API token for the user `terraformer`**
4. **Create API Token for the user `terraformer`**
```bash
pveum user token add terraformer@pve terraform -expire 0 -privsep 0 -comment "Terraform token"
```
@@ -408,7 +408,7 @@ proxmox_endpoint = <your Proxox endpoint>
proxmox_api_token = <your Proxmox API token for the user terraformer>
```
To improve readability, you can automatically formats your Terraform code `terraform fmt`, to follow standard style conventions, making it clean and consistent.
> 💡 To improve readability, you can automatically formats your Terraform code `terraform fmt`, to follow standard style conventions, making it clean and consistent.
### Initialize your Workspace
@@ -659,11 +659,11 @@ vm_ip = "192.168.66.156"
✅ Done! Weve successfully created our first VM on Proxmox using Terraform in just a few minutes.
![Summary of the newly created VM on Proxmox](img/proxmox-terraform-new-vm.png)
![Résumé de la nouvelle VM crée sur Proxmox](img/proxmox-terraform-new-vm.png)
### SSH Connection
Cherry on the cake: Terraform gives us the IP address, and thanks to cloud-init, SSH is ready to go.
🍒 Cherry on the cake: Terraform gives us the IP address, and thanks to cloud-init, SSH is ready to go.
```bash
$ ssh 192.168.66.156
@@ -707,7 +707,7 @@ See "man sudo_root" for details.
vez@zenith-vm:~$
```
This works like a charm, wonderful. We can see that my user is already created, it has all sudo permissions and the system is up-to-date.
This works like a charm, wonderful. We can see that my user is already created, it has all sudo permissions and the system is up-to-date.
### Idempotency
@@ -735,11 +735,11 @@ vm_ip = "192.168.66.156"
✅ No change as expected!
### Remove your infrastructure
### Remove your Infrastructure
To remove a Terraform-managed infrastructure, simply run the command `terraform destroy`.
Terraform will show you a detailed plan of everything its about to delete, and ask for confirmation before proceeding. Once confirmed, it removes all resources it previously created
Terraform will show you a detailed plan of everything its about to delete, and ask for confirmation before proceeding. Once confirmed, it removes all resources it previously created.
```bash
$ terraform destroy
@@ -961,7 +961,7 @@ proxmox_virtual_environment_file.cloud_config: Destruction complete after 0s
Destroy complete! Resources: 2 destroyed.
```
💣 **Boom**! The VM has been destroyed and we can redeploy another instance at will!
💣 **Boom**! The VM has been destroyed and we can now redeploy another instance at will!
---
## Conclusion