<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by zidenis on Medium]]></title>
        <description><![CDATA[Stories by zidenis on Medium]]></description>
        <link>https://medium.com/@zidenis?source=rss-3ffa1b746888------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8pPnPHDtHxLkFC27cWm9Ag.jpeg</url>
            <title>Stories by zidenis on Medium</title>
            <link>https://medium.com/@zidenis?source=rss-3ffa1b746888------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 07:01:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zidenis/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Terraform Cookbook: Development Environment Recipe]]></title>
            <link>https://awstip.com/terraform-cookbook-development-environment-recipe-83ff6e4c94c7?source=rss-3ffa1b746888------2</link>
            <guid isPermaLink="false">https://medium.com/p/83ff6e4c94c7</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <dc:creator><![CDATA[zidenis]]></dc:creator>
            <pubDate>Mon, 23 Dec 2024 19:34:02 GMT</pubDate>
            <atom:updated>2024-12-31T17:32:45.804Z</atom:updated>
            <content:encoded><![CDATA[<p>A step-by-step guide to setting up a complete Terraform development environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZZtJEIoY4ukfombu" /></figure><p>TLDR: This tutorial provides a step-by-step guide to setting up a complete Terraform development environment, including version management (tenv), documentation generation (terraform-docs), linting (TFLint), security scanning (Trivy, Checkov), pre-commit hooks, and others. We use a cookbook-style approach for easy understanding, but if you just want the command script to set up the environment, you can get it <a href="https://github.com/zidenis/terraform-module-template-aws/blob/main/environment_setup.sh">here</a>.</p><h3>Development Environment Recipe</h3><blockquote><em>A quick and easy recipe to set up a killer development environment for writing Terraform modules. Tested on Linux Ubuntu 24.04.1 LTS for x86_64 architecture (should work on other debian-based systems. For other Linux distributions, some tweaks are required).</em></blockquote><p>Building robust and secure infrastructure with Terraform requires more than just the terraform CLI. A well-equipped development environment is crucial for maximizing productivity, ensuring code quality, and preventing costly mistakes. This tutorial serves as your complete recipe for setting up a top-notch Terraform development environment. I’ll guide you through installing and configuring essential tools. By the end of this tutorial, you will have a streamlined workflow, enabling you to focus on building infrastructure rather than managing complex configurations. We use a cookbook-style approach for easy understanding.</p><h3>Ingredients:</h3><ul><li>Linux utilities (curl, jq, tar, unzip, git)</li><li>tenv: <a href="https://github.com/tofuutils/tenv">version manager for Terraform</a></li><li>terraform CLI: <a href="https://developer.hashicorp.com/terraform/cli">HashiCorp’s Terraform CLI</a></li><li>terraform-docs: <a href="https://github.com/terraform-docs/terraform-docs">tool for generating module documentation</a></li><li>TFLint: <a href="https://github.com/terraform-linters/tflint">terraform linter</a></li><li>Trivy: <a href="https://github.com/aquasecurity/trivy">security scanner for IaC and dependencies</a></li><li>venv: <a href="https://docs.python.org/3/library/venv.html">virtual environments for Python</a></li><li>Pre-commit: <a href="https://pre-commit.com/">git hook manager</a></li><li>Pre-commit-terraform: <a href="https://github.com/antonbabenko/pre-commit-terraform">terraform git hooks</a></li><li>Checkov: <a href="https://github.com/bridgecrewio/checkov">static analysis for IaC</a></li><li>VSCode: <a href="https://marketplace.visualstudio.com/items?itemName=4ops.terraform">code editor with Terraform extension</a></li></ul><h3>Preparation Steps:</h3><h3>1. Know Your Kitchen, VSCode.</h3><p>First things first, every chef needs a well-equipped kitchen. In our case, Visual Studio Code is our kitchen, the place where we’ll craft all our infrastructure recipes. But a bare kitchen isn’t enough. We need the right tools and appliances to prepare delicious dishes. That’s where the <a href="https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform">Terraform extension by Hashicorp</a> comes in. The extension provides syntax highlighting, code completion, among other features.</p><pre># Follow the VSCode installation guide (https://code.visualstudio.com/docs/setup/linux) for other instalation methods.<br>sudo apt-get install curl<br><br>curl -L -o vscode.deb  https://go.microsoft.com/fwlink/?LinkID=760868<br><br>sudo apt install ./vscode.deb<br><br>code <br># After VSCode launch, use Quick Open (Ctrl+P), paste the command &quot;ext install HashiCorp.terraform&quot; and press enter.<br># Or install the extension @id:HashiCorp.terraform using the VSCode GUI.</pre><h3>2. Equip Your Kitchen with tenv.</h3><blockquote><em>Manage multiple Terraform versions like a pro. Simplifies the management of multiple Terraform versions, ensuring compatibility with different projects.</em></blockquote><p>Grab your Terraform version manager, tenv. Every good chef needs a well-organized kitchen. When it comes to managing different versions of Terraform, tenv will keep your environment neatly organized and easily accessible. It also supports OpenTofu, Terragrunt, and Atmos. Let&#39;s get it installed:</p><pre>TENV_LATEST=$(curl -s https://api.github.com/repos/tofuutils/tenv/releases/latest | jq -r &#39;.assets[] | select(.name | endswith(&quot;Linux_x86_64.tar.gz&quot;)) | .browser_download_url&#39;)<br><br>curl -L -O $TENV_LATEST<br><br>mkdir ~/.tenv<br><br>tar xvzf $(echo $TENV_LATEST | grep -o -E &quot;tenv_v.*&quot;) -C ~/.tenv<br><br>export PATH=&quot;$HOME/.tenv:$PATH&quot;<br><br>tenv completion bash &gt; ~/.tenv/tenv_completion.bash<br><br>echo -e &#39;\n# tenv and terraform tools\nexport PATH=&quot;$HOME/.tenv:$PATH&quot;\nsource $HOME/.tenv/tenv_completion.bash&#39; &gt;&gt; ~/.bashrc</pre><p>The lines added to .bashrc ensure that tenv is always available when we start cooking terraform modules.</p><h3>3. Grab Your Trusty terraform CLI Using tenv.</h3><p>It’s time to grab our most essential infrastructure cooking utensil, our pan: the terraform CLI. This is the workhorse of our infrastructure kitchen - the pan we&#39;ll use to cook up all our infrastructure recipes. We&#39;ll use tenv to fetch and install the perfect pan for the job. If you wish, use <a href="https://opentofu.org/">Opentofu</a>, which is an &quot;more open&quot; source altenative.</p><pre>tenv terraform install<br><br>terraform -install-autocomplete</pre><p>This is like reaching into our neatly organized tools rack and selecting the perfect terraform CLI pan.</p><h3>4. Compile Your Infrastructure Recipe Notebook With terraform-docs.</h3><blockquote><em>Automatically generate documentation for your terraform modules (inputs, outputs, etc.).</em></blockquote><p>A good chef keeps a detailed recipe notebook, documenting each dish’s ingredients, instructions, and variations. In the world of infrastructure as code, terraform-docs is our tool to maintain recipe documents. It automatically generates documentation for our Terraform modules, neatly organizing inputs, outputs, and other important details. This ensures that anyone (including our future selves) can easily understand and use our infrastructure recipes. Let’s add it to our kitchen:</p><pre>TDOC_LATEST=$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | jq -r &#39;.assets[] | select(.name | endswith(&quot;linux-amd64.tar.gz&quot;)) | .browser_download_url&#39;)<br><br>curl -L -O $TDOC_LATEST<br><br>tar xzf $(echo $TDOC_LATEST | grep -o -E &quot;terraform-docs-.+&quot;) -C ~/.tenv terraform-docs<br><br>terraform-docs completion bash &gt; ~/.tenv/terraform-docs_completion.bash<br><br>echo -e &#39;\nsource $HOME/.tenv/terraform-docs_completion.bash&#39; &gt;&gt; ~/.bashrc</pre><h3>5. Employ TFLint Quality Control.</h3><blockquote><em>A linter for Terraform code. Catch syntax errors, enforce standards, and keep your Terraform configs clean.</em></blockquote><p>Maintaining quality control is crucial. In the Terraform kitchen, TFLint scans our Terraform code for syntax errors and potential issues, ensuring our code is sound. Let&#39;s add this to our kitchen:</p><pre>TFLINT_LATEST=$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | jq -r &#39;.assets[] | select(.name | endswith(&quot;tflint_linux_amd64.zip&quot;)) | .browser_download_url&#39;)<br><br>curl -L -O $TFLINT_LATEST<br><br>unzip -o $(echo $TFLINT_LATEST | grep -o -E &quot;tflint_linux.+&quot;) -d ~/.tenv</pre><p>The <a href="https://github.com/zidenis/terraform-module-template-aws/blob/main/.tflint.hcl">.tflint.hcl</a> file is the configuration file for TFLint. Its purpose is to define the rules, plugins, and configurations that TFLint will use when analyzing your Terraform code. This allows you to enforce best practices, identify issues, and customize the linter’s behavior to align with your project requirements. The configuration I currently use for terraform AWS resources is like the bellow example.</p><h4>Sample <a href="https://github.com/zidenis/terraform-module-template-aws/blob/main/.tflint.hcl">.tflint.hcl</a> Configuration</h4><pre>tflint {<br>  required_version = &quot;~&gt; 0.54.0&quot;<br>}<br><br>plugin &quot;terraform&quot; {<br>  enabled = true<br>  preset  = &quot;all&quot;<br>}<br><br>plugin &quot;aws&quot; {<br>  enabled = true<br>  version = &quot;0.36.0&quot;<br>  source  = &quot;github.com/terraform-linters/tflint-ruleset-aws&quot;<br>  deep_check = true<br>}<br><br>rule &quot;aws_resource_missing_tags&quot; {<br>  enabled = true<br>  tags = [<br>    &quot;env&quot;<br>  ]<br>}</pre><h3>6. Double Strain Your Infrastructure Code With Trivy And Checkov.</h3><blockquote><em>Trivy scan your IaC files, container images, and dependencies for vulnerabilities.</em></blockquote><blockquote><em>Checkov detects misconfigurations, security risks, and compliance violations in Terraform and other IaC templates.</em></blockquote><p>Ensuring the safety of your code is paramount. You wouldn’t want any unwanted bits sneaking into your dishes. Just as a chef uses strainers to remove impurities, we use Trivy and Checkov to filter out potential vulnerabilities and misconfigurations from our infrastructure code. Think of them as two different types of strainers, each catching different kinds of unwanted elements. Let&#39;s add them:</p><pre>TRIVY_LATEST=$(curl -s https://api.github.com/repos/aquasecurity/trivy/releases/latest | jq -r &#39;.assets[] | select(.name | endswith(&quot;Linux-64bit.tar.gz&quot;)) | .browser_download_url&#39;)<br><br>curl -L -O $TRIVY_LATEST<br><br>tar xzf $(echo $TRIVY_LATEST | grep -o -E &quot;trivy_.+&quot;) -C ~/.tenv trivy<br><br># We are going to install checkov using python pip and venv<br>sudo apt install python3-pip python3.12-venv<br><br>python3 -m venv ~/.venv<br><br>source ~/.venv/bin/activate<br><br>pip install checkov</pre><p>Now, with both Trivy and Checkov in our kitchen, we can confidently cook a safe and secure code. This double-straining approach provides a more comprehensive security check, catching both specific vulnerabilities and broader misconfigurations.</p><h3>7. Set Up Your pre-commit Kitchen Workflow Checklist</h3><blockquote><em>Ensures consistent code quality by running checks (e.g., linting, formatting, security scans) before committing code.</em></blockquote><p>In a busy kitchen, chefs rely on checklists and workflows to ensure every step is followed and no crucial task is missed. pre-commit acts as our kitchen workflow checklist, ensuring we systematically employ all our quality control and tools (like TFLint, Trivy, and Checkov) before we &quot;serve&quot; (commit) our infrastructure code.</p><p>pre-commit uses git hooks, which are scripts that run automatically at specific points in the Git workflow. In this case, we&#39;re going to use pre-commit hooks, which run before each git commit. This ensures that our code is always checked before it&#39;s added to the project&#39;s history. Let&#39;s set up our kitchen workflow checklist:</p><pre>source ~/.venv/bin/activate<br><br>pip install pre-commit</pre><p>Now that we have pre-commit installed, we’ll configure it to use our quality control tools. The <a href="https://github.com/zidenis/terraform-module-template-aws/blob/main/.pre-commit-config.yaml">.pre-commit-config.yaml</a> file is the configuration file for the Pre-commit framework that define the pre-commit hook.</p><h4>Sample <a href="https://github.com/zidenis/terraform-module-template-aws/blob/main/.pre-commit-config.yaml">.pre-commit-config.yaml</a> Configuration.</h4><pre>repos:<br>  - repo: https://github.com/antonbabenko/pre-commit-terraform<br>    rev: v1.96.2<br>    hooks:<br>      - id: terraform_validate<br>      - id: terraform_fmt<br>      - id: terraform_tflint<br>        args:<br>          - --args=--config=__GIT_WORKING_DIR__/.tflint.hcl<br>      - id: terraform_trivy<br>      - id: terraform_checkov<br>        name: &quot;Terraform validate with Checkov&quot;<br>        args:<br>          - --args=--quiet<br>      - id: terraform_docs<br><br>  - repo: https://github.com/pre-commit/pre-commit-hooks<br>    rev: v5.0.0<br>    hooks:<br>      - id: detect-aws-credentials<br>        name: &quot;Pre-commit detect AWS credentials&quot;<br>      - id: detect-private-key<br>        name: &quot;Pre-commit detect private keys&quot;<br>      - id: end-of-file-fixer<br>        name: &quot;Pre-commit fix end of files&quot;<br>      - id: trailing-whitespace<br>        name: &quot;Pre-commit remove trailing whitespaces&quot;</pre><p>Beyond quality and safety, presentation matters too! Just as chefs ensure consistent dish presentation, we also use terraform fmt and others pre-commit hooks to format our code in a consistent way. This makes our code easier to read, understand, and maintain, both for ourselves and our colleagues.</p><p>Now that our kitchen is equipped, it’s time to gather the ingredients for our infrastructure main dish: the Terraform root module.</p><h3>8. Our Main Infrastructure Dish: The Terraform Root Module.</h3><p>Just like any good recipe, it requires the right ingredients, organized in the right way. HashiCorp suggests a <a href="https://developer.hashicorp.com/terraform/language/modules/develop/structure">standard module structure</a>, which we’ll follow to ensure a well-structured and maintainable code. Here is an example:</p><pre>root-module/<br>├── README.md<br>├── main.tf<br>├── variables.tf<br>├── outputs.tf<br>├── providers.tf<br>├── modules/<br>│   ├── child-module-A/<br>│   │   ├── README.md<br>│   │   ├── main.tf<br>│   │   ├── variables.tf<br>│   │   ├── outputs.tf<br>│   ├── child-module-B/<br>│   ├── .../<br>├── .pre-commit-config.yaml<br>└── .tflint.hcl</pre><p>With our main dish structure defined, let’s dive into a sample recipe specifically for AWS dishes.</p><h4>A Sample Recipe for AWS</h4><blockquote><em>A template that serves as a foundation for creating Terraform modules.</em></blockquote><p><a href="https://github.com/zidenis/terraform-module-template-aws">Here</a> is a handy module template to bootstrap your AWS resources. It serves as a foundation starting point for various AWS infrastructure creations, and includes essential ingredients for a robust and secure AWS setup, including:</p><ul><li>An S3 Bucket for State Storage. It includes server-side encryption, versioning, and lifecycle rules for noncurrent object transition and expiration, ensuring the safety and management of our stored data. It also blocks public access, preventing unwanted access.</li><li>A DynamoDB Table for State Locking. This acts as a coordination system in our kitchen, preventing conflicts when we have multiple chefs.</li></ul><h4>Template usage example</h4><pre>aws configure # You will need the AWS CLI installed. Set up AWS credentials with privileges to provision resources. Remember to use temporary credentials or store permanent credentials outside the git repository.<br><br>git clone https://github.com/zidenis/terraform-module-template-aws.git my-terraform-module<br><br>cd my-terraform-module<br><br>git remote remove origin # We remove the original remote to start our own module<br><br># Do not run this script if your intention is to develop the module locally.<br>chmod +x backend_bootstrap.sh; ./backend_bootstrap.sh # optionally, use this bash script to set up the remote backend. <br><br>source ~/.venv/bin/activate<br><br>pre-commit install --install-hooks # set up your git repository to run pre-commit hooks automatically<br><br>pre-commit run -a # optionally, run pre-commit hooks against all the files.</pre><p>You can now start developing your specific module, using the provided structure and backend setup as a solid foundation. Using pre-commit, you can run all the quality and security checks we set up earlier, ensuring a perfect and secure final dish.</p><h4>pre-commit usage example</h4><pre>source ~/.venv/bin/activate<br><br>echo &quot;# cooking a new module&quot; &gt;&gt;  main.tf<br><br>git add main.tf<br><br>git commit -m &quot;Cooking a new module&quot;<br># [INFO] Initializing environment for https://github.com/antonbabenko/pre-commit-terraform.<br># [INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.<br># [INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.<br># [INFO] Once installed this environment will be reused.<br># [INFO] This may take a few minutes...<br># Terraform validate.......................................................Passed<br># Terraform fmt............................................................Passed<br># Terraform validate with tflint...........................................Passed<br># Terraform validate with trivy............................................Passed<br># Terraform validate with Checkov..........................................Passed<br># Terraform docs...........................................................Passed<br># Pre-commit detect AWS credentials........................................Passed<br># Pre-commit detect private keys...........................................Passed<br># Pre-commit fix end of files..............................................Passed<br># Pre-commit remove trailing whitespaces...................................Passed</pre><h3>Conclusion</h3><p>By following this recipe, you’ve equipped your development environment with essential tools to write, validate, and secure Terraform modules effectively. This tutorial was designed to install the latest versions of the tools, but remember to regularly update your tools and configurations for optimal performance and compliance.</p><p>Are there any additional tools or configurations you’d like to explore to complement the setup? are you using Generative AI to develop your terraform modules? please, tell me how. While Generative AI has the potential to streamline Terraform development by automating certain tasks like code generation or identifying potential issues. However, at this stage, I think it’s likely not a core component for most users setting up a development environment. This is something that I plan to investigate.</p><p>Let me know your thoughts and suggestions to improve this guide further. Happy coding!</p><h3>Tools versions at the time of writing</h3><pre>tenv version<br># tenv version v3.2.11<br><br>terraform version<br># Terraform v1.10.3<br># on linux_amd64<br><br>terraform-docs version<br># terraform-docs version v0.19.0 af31cc6 linux/amd64<br><br>tflint --version<br># TFLint version 0.54.0<br># + ruleset.terraform (0.10.0-bundled)<br><br>trivy --version<br># Version: 0.58.0<br><br>checkov --version<br># 3.2.343<br><br>pre-commit --version<br>#pre-commit 4.0.1</pre><h3>Cleanup</h3><p>Clean up downloaded archives.</p><pre>rm $(echo $TENV_LATEST | grep -o -E &quot;tenv_v.*&quot;)<br><br>rm $(echo $TDOC_LATEST | grep -o -E &quot;terraform-docs-.+&quot;)<br><br>rm $(echo $TFLINT_LATEST | grep -o -E &quot;tflint_linux.+&quot;)<br><br>rm $(echo $TRIVY_LATEST | grep -o -E &quot;trivy_.+&quot;)<br><br>rm vscode.deb</pre><p><em>Originally published at </em><a href="https://gist.github.com/zidenis/93f8f93429e443c72243889b18bccad1"><em>http://github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83ff6e4c94c7" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/terraform-cookbook-development-environment-recipe-83ff6e4c94c7">Terraform Cookbook: Development Environment Recipe</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Steps for Creating Templates and Virtual Machines on Proxmox using Linux Distro’s Cloud Images]]></title>
            <link>https://medium.com/@zidenis/5-steps-for-creating-templates-and-virtual-machines-on-proxmox-using-linux-distros-cloud-images-3c7c6ca062d6?source=rss-3ffa1b746888------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c7c6ca062d6</guid>
            <category><![CDATA[proxmox]]></category>
            <category><![CDATA[qemu]]></category>
            <category><![CDATA[virtualization]]></category>
            <category><![CDATA[cloud-init]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[zidenis]]></dc:creator>
            <pubDate>Fri, 25 Aug 2023 12:44:38 GMT</pubDate>
            <atom:updated>2023-08-25T12:44:38.621Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o89GNCsJsYHIZoihln8Oog.png" /></figure><p>This tutorial guides you through the process of creating Templates and Virtual Machines on Proxmox using cloud-based images from various Linux distributions. We provide clear instructions for Alma Linux 9, Amazon Linux 2, CentOS 9, Fedora 38, Oracle Linux 9, RHEL 9, Rocky Linux 9, and Ubuntu 23.04 Lynx Lobster.</p><p><strong>Note</strong>: The instructions have been tested on Proxmox 8.0.4.</p><p>Let’s begin by choosing the cloud-based image. If you already have your preferred Linux distribution, skip to the 1st step.</p><p>To assist in making informed choices when selecting a Linux distribution for your virtual machines, we’ve compiled a table showcasing key characteristics of each cloud image. This table provides a snapshot of important attributes, including kernel version, Python version, number of processes initialized after boot, number of packages installed, free memory after boot, VM disk size, root partition disk size, used size on the root partition, free size on the root partition, root filesystem type, and whether LVM is enabled. By understanding these characteristics, you can tailor your choices to the requirements of your specific use case, ensuring optimal performance and resource utilization. Please note that an official cloud image for Amazon Linux 2023 is currently unavailable to the public.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*A4xMUaS2-6AIXSDq.png" /></figure><h3>1. Downloading the images</h3><p>Start by downloading the necessary images for the distributions you intend to utilize. These images will lay the groundwork for creating templates and virtual machines in the subsequent sections.</p><pre>ssh user@your-proxmox-server<br><br>su - root<br><br>export IMAGES_PATH=&quot;/mnt/pve/nfs-data/images/&quot; # defines the path where the images will be stored and change the path to it.<br><br>cd ${IMAGES_PATH}<br><br># Alma Linux 9<br># https://wiki.almalinux.org/cloud/Generic-cloud.html<br>wget https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2<br><br>wget https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/CHECKSUM -O SHA256SUMS <br><br>sha256sum -c SHA256SUMS --ignore-missing<br><br># Download instructions for others distributions images are presented bellow.<br><br>## Amazon Linux 2<br>## https://cdn.amazonlinux.com/os-images/latest/<br>## Amazon Linux 2023 not yet available as cloud image <br># wget https://cdn.amazonlinux.com/os-images/2.0.20230727.0/kvm/amzn2-kvm-2.0.20230727.0-x86_64.xfs.gpt.qcow2<br><br>## Centos 9<br>## https://cloud.centos.org/centos/9-stream/x86_64/images/<br># wget https://cloud.centos.org/centos/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2<br><br>## Fedora 38<br>## https://alt.fedoraproject.org/cloud/<br># wget https://download.fedoraproject.org/pub/fedora/linux/releases/38/Cloud/x86_64/images/Fedora-Cloud-Base-38-1.6.x86_64.qcow2<br><br>## Oracle Linux 9<br>## https://yum.oracle.com/oracle-linux-templates.html<br># wget https://yum.oracle.com/templates/OracleLinux/OL9/u2/x86_64/OL9U2_x86_64-kvm-b197.qcow<br>## Can&#39;t find Oracle CHECKUM file and signature. Just the SHA256 on downloads page<br># echo &quot;840345cb866837ac7cc7c347cd9a8196c3a17e9c054c613eda8c2a912434c956 OL9U2_x86_64-kvm-b197.qcow&quot; &gt; SHA256SUMS-Oracle9<br>## Converting image to qcow2 format<br># qemu-img convert -O qcow2 -o compat=0.10 OL9U2_x86_64-kvm-b197.qcow OL9U2_x86_64-kvm-b197.qcow2<br># rm OL9U2_x86_64-kvm-b197.qcow<br><br>## Red Hat 9<br>## https://access.redhat.com/downloads/content/479/ver=/rhel---9/9.2/x86_64/product-software<br>## Needs to be logged in and get a personal link to download RHEL 9 cloud image<br><br>## Rocky Linux 9<br>## https://rockylinux.org/alternative-images<br># wget https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2<br><br>## Ubuntu 23.04 Lunar Lobster<br>## https://cloud-images.ubuntu.com/<br># wget https://cloud-images.ubuntu.com/lunar/current/lunar-server-cloudimg-amd64.img </pre><h3>2. Configuring VM and Cloud-init Settings</h3><p>Set up the environment variables to define base config for for both virtual machines (VMs) and Cloud-init settings. These variables encompass VM configuration details such as CPU model, cores, memory, and resource pool. Moreover, we establish Cloud-init settings, specifying user information, SSH key, network parameters, and more. Cloud-init is an open-source tool used for initializing and configuring virtual machines in cloud environments, enabling automated provisioning of virtual machine settings. By configuring these variables, you ensure uniform settings across the VMs and templates you create.</p><p>Define the VM configuration:</p><pre>export QEMU_CPU_MODEL=&quot;host&quot; # Specifies the CPU model to be used for the VM according your environment and the desired CPU capabilities.<br>export VM_CPU_SOCKETS=1<br>export VM_CPU_CORES=2<br>export VM_MEMORY=4098<br>export VM_RESOURCE_POOL=&quot;CustomResourcePool&quot; # Assigns the VM to a specific resource pool for management.</pre><p>Define the Cloud-init configuration. The specified user will be created, and its public key will be defined as an authorized key, enabling remote access using the user’s private key.</p><pre>export CLOUD_INIT_USER=&quot;user&quot; # Specifies the username to be created using Cloud-init.<br>export CLOUD_INIT_SSHKEY=&quot;/home/user/.ssh/id_rsa.pub&quot; # Provides the path to the SSH public key for the user.<br>export CLOUD_INIT_IP=&quot;dhcp&quot;<br>export CLOUD_INIT_NAMESERVER=&quot;1.1.1.1&quot;<br>export CLOUD_INIT_SEARCHDOMAIN=&quot;example.com&quot;</pre><p>Choose the Linux distribution you are working with:</p><pre>export TEMPLATE_ID=1001<br>export VM_NAME=&quot;alma9&quot;<br>export VM_DISK_IMAGE=&quot;${IMAGES_PATH}/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2&quot;<br>## Disk image for others distributions<br># export VM_DISK_IMAGE=&quot;${IMAGES_PATH}/amzn2-kvm-2.0.20230727.0-x86_64.xfs.gpt.qcow2&quot;<br># export VM_DISK_IMAGE=&quot;${IMAGES_PATH}/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2&quot;<br># export VM_DISK_IMAGE=&quot;${IMAGES_PATH}/Fedora-Cloud-Base-38-1.6.x86_64.qcow2&quot;<br># export VM_DISK_IMAGE=&quot;${IMAGES_PATH}/OL9U2_x86_64-kvm-b197.qcow2&quot;<br># export VM_DISK_IMAGE=&quot;${IMAGES_PATH}/rhel-9.2-x86_64-kvm.qcow2&quot;<br># export VM_DISK_IMAGE=&quot;${IMAGES_PATH}/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2&quot;<br># export VM_DISK_IMAGE=&quot;${IMAGES_PATH}/lunar-server-cloudimg-amd64.img&quot;</pre><h3>3. Creating a VM as the base for the Template</h3><p>In this section, we guide you through the creation of a virtual machine that will serve as the foundation for the template. Utilizing the defined environment variables, we configure the VM settings and integrate Cloud-init specifications.</p><pre># Create VM. Change the cpu model <br>qm create ${TEMPLATE_ID} --name ${VM_NAME} --cpu ${QEMU_CPU_MODEL} --sockets ${VM_CPU_SOCKETS} --cores ${VM_CPU_CORES} --memory ${VM_MEMORY} --numa 1 --net0 virtio,bridge=vmbr0 --ostype l26 --agent 1 --pool ${VM_RESOURCE_POOL} --scsihw virtio-scsi-single<br><br># Import Disk<br>qm set ${TEMPLATE_ID} --scsi0 local-lvm:0,import-from=${VM_DISK_IMAGE}<br><br># Add Cloud-Init CD-ROM drive. This enables the VM to receive customization instructions during boot.<br>qm set ${TEMPLATE_ID} --ide2 local-lvm:cloudinit --boot order=scsi0<br><br># Cloud-init network-data<br>qm set ${TEMPLATE_ID} --ipconfig0 ip=${CLOUD_INIT_IP} --nameserver ${CLOUD_INIT_NAMESERVER} --searchdomain ${CLOUD_INIT_SEARCHDOMAIN}<br><br># Cloud-init user-data<br>qm set ${TEMPLATE_ID} --ciupgrade 1 --ciuser ${CLOUD_INIT_USER} --sshkeys ${CLOUD_INIT_SSHKEY}<br><br># Cloud-init regenerate ISO image, ensuring that the VM will properly initialize with the desired parameters.<br>qm cloudinit update ${TEMPLATE_ID}</pre><h3>4. Converting the base VM to Template</h3><p>By executing the provided commands, the VM is transformed into a reusable template. The template can be cloned to produce consistent virtual machines, reducing setup time and ensuring uniformity across your environment.</p><pre>qm set ${TEMPLATE_ID} --name &quot;${VM_NAME}-Template&quot;<br><br>qm template ${TEMPLATE_ID}</pre><h3>5. Create a new VM by cloning the Template</h3><p>Concluding the tutorial by cloning the template to create a new virtual machine.</p><pre>export VM_ID=$(pvesh get /cluster/nextid)<br><br>qm clone ${TEMPLATE_ID} ${VM_ID}  --name ${VM_NAME}<br><br>qm start ${VM_ID}</pre><p>To access the cloned VM, utilize its IP address along with the user’s private key for SSH authentication. Please note that some distributions, such as Amazon Linux 2 and Ubuntu 23.04, might not display the guest’s IP directly on the Proxmox GUI due to the absence of the qemu-guest-agent package.</p><pre>ssh user@192.168.0.123 -i ~/.ssh/id_rsa</pre><p><em>Originally published at </em><a href="https://gist.github.com/zidenis/dfc05d9fa150ae55d7c87d870a0306c5"><em>http://github.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c7c6ca062d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>