<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Архивы Terraform - Boxvirt - Proxmox &amp; OPNsense Infrastructure Guides</title>
	<atom:link href="https://boxvirt.com/tag/terraform/feed/" rel="self" type="application/rss+xml" />
	<link>https://boxvirt.com/tag/terraform/</link>
	<description>Practical self-hosted infrastructure guides for Proxmox, OPNsense, and Docker.</description>
	<lastBuildDate>Sun, 03 Aug 2025 14:54:34 +0000</lastBuildDate>
	<language>ru-RU</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://boxvirt.com/wp-content/uploads/2025/07/cropped-ChatGPT-Image-12-июл.-2025-г.-19_41_55-32x32.png</url>
	<title>Архивы Terraform - Boxvirt - Proxmox &amp; OPNsense Infrastructure Guides</title>
	<link>https://boxvirt.com/tag/terraform/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Deploy Proxmox VMs with Terraform in a Docker Container</title>
		<link>https://boxvirt.com/deploy-proxmox-vms-with-terraform-in-a-docker-container/</link>
					<comments>https://boxvirt.com/deploy-proxmox-vms-with-terraform-in-a-docker-container/#respond</comments>
		
		<dc:creator><![CDATA[eXtre]]></dc:creator>
		<pubDate>Sun, 03 Aug 2025 14:54:33 +0000</pubDate>
				<category><![CDATA[Docker]]></category>
		<category><![CDATA[Proxmox]]></category>
		<category><![CDATA[Terraform]]></category>
		<guid isPermaLink="false">https://boxvirt.com/?p=145</guid>

					<description><![CDATA[<p>Automating your infrastructure is a cornerstone of modern DevOps, and Proxmox is a fantastic virtualization platform. When you combine it with Terraform, you unlock the power of Infrastructure [&#8230;]</p>
<p>Сообщение <a href="https://boxvirt.com/deploy-proxmox-vms-with-terraform-in-a-docker-container/">Deploy Proxmox VMs with Terraform in a Docker Container</a> появились сначала на <a href="https://boxvirt.com">Boxvirt - Proxmox &amp; OPNsense Infrastructure Guides</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Automating your infrastructure is a cornerstone of modern DevOps, and <strong>Proxmox</strong> is a fantastic virtualization platform. When you combine it with <strong>Terraform</strong>, you unlock the power of Infrastructure as Code (IaC), allowing you to define and manage your virtual machines programmatically.</p>



<p>This guide is for <strong>beginners</strong> who want a clean, isolated, and repeatable way to run Terraform by setting it up inside a <strong>Docker container</strong>.</p>



<h3 class="wp-block-heading"><strong><img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f3a8.png" alt="🎨" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Image 1: Architectural Overview</strong></h3>



<p>First, let&#8217;s visualize our goal. Our setup will look like this: you run Docker on your machine, which hosts a Terraform container. This container then communicates with your Proxmox server&#8217;s API to build, modify, or destroy virtual machines.</p>



<ul class="wp-block-list">
<li><strong>Explanation:</strong> This diagram shows a clean workflow. Your workstation instructs a self-contained Docker environment, which in turn manages your Proxmox infrastructure. This prevents clutter on your local machine and ensures a consistent environment.</li>
</ul>



<h3 class="wp-block-heading"><strong>Part 1: Prerequisites</strong></h3>



<p>Before we begin, make sure you have:</p>



<ol start="1" class="wp-block-list">
<li>A running <strong>Proxmox VE</strong> server.</li>



<li>The IP address of your Proxmox server.</li>



<li><strong>Docker</strong> installed and running on your local workstation.</li>



<li>A <strong>Proxmox API Token</strong>. To create one, go to your Proxmox web UI and navigate to <code>Datacenter</code> -> <code>Permissions</code> -> <code>API Tokens</code>. Click <code>Add</code>, give it a memorable ID (e.g., <code>terraform-user@pve</code>), and save the <strong>Token ID</strong> and <strong>Secret</strong> securely.</li>
</ol>



<h3 class="wp-block-heading"><strong>Part 2: Setting Up the Terraform Docker Environment</strong></h3>



<p>We&#8217;ll create a dedicated directory for our project and a <code>Dockerfile</code> to define our environment.</p>



<p>First, create a project folder: <code>mkdir proxmox-terraform &amp;&amp; cd proxmox-terraform</code></p>



<p>Now, create a file named <code>Dockerfile</code> inside this directory.</p>



<h3 class="wp-block-heading"><strong><img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f3a8.png" alt="🎨" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Image 2: The Dockerfile</strong></h3>



<p>This <code>Dockerfile</code> is simple. It uses the official Terraform image and adds <code>git</code>, which is required by the Terraform Proxmox provider to download modules.</p>



<ul class="wp-block-list">
<li><strong>Explanation:</strong> This file instructs Docker to use the latest official Terraform image and add the <code>git</code> package. The <code>WORKDIR</code> command sets the default directory inside the container, keeping our project files organized.</li>
</ul>



<p>Build your Docker image with this command: <code>docker build -t terraform-proxmox .</code></p>



<h3 class="wp-block-heading"><strong>Part 3: Configuring Terraform</strong></h3>



<p>Next, create a file named <code>main.tf</code>. This is where you&#8217;ll define the Proxmox provider and the virtual machines you want to create.</p>



<p>Terraform</p>



<pre class="wp-block-code"><code><code>terraform {
  required_providers {
    proxmox = {
      source  = "telmate/proxmox"
      version = "2.9.14"
    }
  }
}

provider "proxmox" {
  pm_api_url = "https://YOUR_PROXMOX_IP:8006/api2/json"
  pm_api_token_id = "YOUR_API_TOKEN_ID"
  pm_api_token_secret = "YOUR_API_TOKEN_SECRET"

  # Set to true if your Proxmox has a self-signed certificate
  pm_tls_insecure = true
}

# --- Define your VM resource here ---
resource "proxmox_vm_qemu" "example_vm" {
  name        = "terraform-vm-01"
  target_node = "pve" # The name of your Proxmox node

  # A pre-prepared template or existing VM to clone
  clone = "ubuntu-2204-cloud-template"
  
  agent       = 1
  os_type     = "cloud-init"
  cores       = 1
  sockets     = 1
  cpu         = "host"
  memory      = 1024
  scsihw      = "virtio-scsi-pci"
  bootdisk    = "scsi0"

  disk {
    size        = "20G"
    type        = "scsi"
    storage     = "local-lvm" # Your target storage
  }

  network {
    model       = "virtio"
    bridge      = "vmbr0"
    firewall    = false
  }
}</code>

</code></pre>



<p><strong>Important:</strong></p>



<ul class="wp-block-list">
<li>Replace <code>YOUR_PROXMOX_IP</code>, <code>YOUR_API_TOKEN_ID</code>, and <code>YOUR_API_TOKEN_SECRET</code> with your actual credentials.</li>



<li>Make sure the <code>clone</code> value points to an existing VM template in your Proxmox server.</li>



<li>Check that <code>target_node</code> and <code>storage</code> match your Proxmox setup.</li>
</ul>



<h3 class="wp-block-heading"><strong>Part 4: Running Terraform from Docker</strong></h3>



<p>Now for the fun part. We will run the standard Terraform commands, but we&#8217;ll execute them through our Docker container.</p>



<ol start="1" class="wp-block-list">
<li><strong>Initialize Terraform:</strong> This downloads the Proxmox provider. <code>docker run -it --rm -v $(pwd):/terraform terraform-proxmox init</code></li>



<li><strong>Create an Execution Plan:</strong> Terraform will check your configuration and show you what it&#8217;s going to do. <code>docker run -it --rm -v $(pwd):/terraform terraform-proxmox plan</code></li>
</ol>



<h3 class="wp-block-heading"><strong><img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f3a8.png" alt="🎨" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Image 3: The Terraform Plan</strong></h3>



<p>The output of the <code>plan</code> command is your safety check. It tells you exactly what resources will be created, changed, or destroyed. For our example, it will plan to create one new resource.</p>



<ul class="wp-block-list">
<li><strong>Explanation:</strong> This graphic symbolizes the clear and predictable output of the <code>plan</code> command. The <code>+</code> icon indicates that a new virtual machine will be added to your infrastructure, giving you full confidence before you apply any changes.</li>
</ul>



<ol start="3" class="wp-block-list">
<li><strong>Apply the Plan:</strong> If you&#8217;re happy with the plan, apply it to create the VM. <code>docker run -it --rm -v $(pwd):/terraform terraform-proxmox apply --auto-approve</code></li>
</ol>



<p>That&#8217;s it! After a few moments, you should see your new virtual machine, <code>terraform-vm-01</code>, appear in your Proxmox web interface. You have successfully automated VM deployment using <strong>Terraform</strong> from a clean <strong>Docker</strong> environment.</p>
<p>Сообщение <a href="https://boxvirt.com/deploy-proxmox-vms-with-terraform-in-a-docker-container/">Deploy Proxmox VMs with Terraform in a Docker Container</a> появились сначала на <a href="https://boxvirt.com">Boxvirt - Proxmox &amp; OPNsense Infrastructure Guides</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://boxvirt.com/deploy-proxmox-vms-with-terraform-in-a-docker-container/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
