Giter Club home page Giter Club logo

harvester-terraform's Introduction

Testing Terraform provider for Harvester

Alt text

Harvester is an HCI open source project based in Linux, Kubernetes, Kubevirt, and Longhorn developed by SUSE. It is an excelent platform for Edge, Cloud Native Data Centers, development environments, or labs. If you want to know more, go and check https://harvesterhci.io/ , SUSE´s blog or SUSE's Harvester Product Page.

On Harvester's GitHub repo, you can find the code for a Terraform provider that can be used to manage Harvester as Infrastructure-as-Code (IaC). You can also find the module on Terraform's registry.

In case you want to have a better understanding of what it is needed to set up a Harvester lab take a look to this blog post: Getting Hands on with Harvester HCI

The code in this repo has been created as part of a blog post that fully describes the process of using Terraform and Harvester and can be reviewed here: Managing Harvester with Terraform

Prerequisites

This repo, what to expect

This repo is meant to help people to learn the basics of the Harvester Terraform module. You can review the Terraform provider documentation if you are looking for more examples. I'm not a Terraform expert, and there are probably many things to improve, so feel free to send PRs to improve the repo.

How to use this repo

git clone https://github.com/avaleror/harvester-terraform.git
cd /whateverpath/harvester-terraform
vim versions.tf #update the path for your Harvester Kubeconfig
vim networks.tf #Add the network parameters for your cluster, otherwise the network and the VM will be created, but the VM won't have an IP
terraform init
terraform plan -out "tfplan"
terraform apply "tfplan"

Just wait a few minutes, and you'll have a VM deployed in Harvester.

Useful links

You can find a fair amount of information about Harvester, Terraform, and the Harvester module in these links:

The repo structure

$ tree
.
├── LICENSE
├── README.md
├── images.tf
├── network.tf
├── pictures
│   ├── harvester_logo.png
├── providers.tf
├── terraform.tfstate
├── terraform.tfvars_example
├── variables.tf
└── vms.tf

There is no standard structure when it comes to a Terraform repo; however, it is good practice to have separated files for different items or vars. This way, it is easier to understand what happens and which resources you need.

In many Terraform repos, you'll find a "main.tf" file but not in this one; you can use as many .tf files as you want to keep the repo clean and tidy. However, when Terraform executes the "terraform plan ..." command, it will parse all the .tf files together.

  • First of all, it is important to create and maintain a .gitignore file; in case you don't know what this is, please read this article https://git-scm.com/docs/gitignore. There is where you define the files that won't be uploaded to git. Once you run Terraform, it creates several files (like "terraform.tfstate" where it keeps track of the changes made by the modules) and a folder called ".terraform" (where downloaded modules are stored after running "terraform init"). You can also use a ".tfvars" file to assign values to different vars, and may you may need to store sensitive information like passwords, tokens, etc. As you can imagine, keeping all those files and folders listed in the .gitignore file is crucial to avoid uploading unnecessary or sensitive content to the git repo.

  • In "providers.tf" we define which Terraform modules are needed to complete the tasks and the concrete versions. Also, in this file, you can define extra args or information required by the different modules. In this example, we provide as an argument the path for the Kubeconfig local file needed to access Harvester.

  • In Terraform repos is usual to find a file called "variables.tf" where you define the variables needed to run the Terraform jobs; there, you can also initialize the value for those vars with a default value. The default values can be overridden using a ".tfvars" file with your configuration values. Check file "terraform.tfvars_example" for some example values.

  • In "images.tf" file, we define the OS image we want to create in Harvester.

  • In "network.tf" we define which of the existing networks will be used for our virtual machine. If you want to create a custom network, just replace the "data" block with a "resource" block with your new network definition.

  • Finally, "vms.tf" contains the definition of the VM that is going to be created in Harvester. There is where we control VM-specific parameters (CPU, disks, etc.) and link to the OS image and network definitions described above.

The output

An openSUSE 15 SP4 image will be downloaded, a VM will be deployed using that image for the OS disk, and the network interface will be connected to the defined VLAN. Deployment time OS configuration relies on the well-known cloud-init model, and you can see an example within the "vms.tf" file. Since we are using KubeVirt on top of Kubernetes, all created objects need a namespace to be deployed. We used the "default" namespace to keep things simple, but you can just play with the Terraform variables and select your own namespace definition.

Cleanup

This command will destroy all the resources created after you confirm with "yes".

terraform destroy

harvester-terraform's People

Contributors

avaleror avatar juanbrny avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.