Giter Club home page Giter Club logo

tf-vm-ovh's Introduction

tf-vm-ovh

This terraform module allow you to create an OVH virtual machine with its disks, networks and DNS records

It can manage either newly disk(s) or existing one(s).

You can select over public / private (vRack) networks.

If you have OVH managed DNS, you can also add a public record for your VM in your managed zone.

Providers to enable

Providers to enable are defined in the OVH documentation:

# Define providers and set versions
terraform {
required_version    = ">= 0.14.0" # Takes into account Terraform versions from 0.14.0
  required_providers {
    openstack = {
      source  = "terraform-provider-openstack/openstack"
      version = "~> 1.42.0"
    }

    ovh = {
      source  = "ovh/ovh"
      version = ">= 0.13.0"
    }
  }
}

# Configure the OpenStack provider hosted by OVHcloud
provider "openstack" {
  auth_url    = "https://auth.cloud.ovh.net/v3/" # Authentication URL
  domain_name = "default" # Domain name - Always at 'default' for OVHcloud
  alias       = "ovh" # An alias
}

provider "ovh" {
  alias              = "ovh"
  endpoint           = "ovh-eu"
  application_key    = "<your_access_key>"
  application_secret = "<your_application_secret>"
  consumer_key       = "<your_consumer_key>"
}

APIs to enable

Name Url
OVH domain name OVH token generation page
Openstack compute OpenRC file

Sample

Simple VM

module "vm" {
  source = "git::https://github.com/reneca/tf-vm-ovh.git?ref=main"
  providers = {
    openstack = openstack.ovh
    ovh       = ovh.ovh
  }

  name         = "dummy"
  ssh_key_path = "~/.ssh/id_ecdsa.pub"
}

VM of another type in another region

The type and region can be overloaded to spawn a different VM type in a different region

module "vm" {
  source = "git::https://github.com/reneca/tf-vm-ovh.git?ref=main"
  providers = {
    openstack = openstack.ovh
    ovh       = ovh.ovh
  }

  name         = "dummy"
  metadata = {
    this = "that"
  }
  ssh_key_path = "~/.ssh/id_ecdsa.pub"
  type         = "b2-7"
  region       = "BHS5"
}

VM with multiple disks

With the module you can create disk for the current instance. In that case the disk size indicate its size in Go.

If the instance need to be link to an external created disk, put a size of 0 and indicate the disk name as the storage key.

The type of storage can also be specified to create high-speed storage (classic by default)

module "vm" {
  source = "git::https://github.com/reneca/tf-vm-ovh.git?ref=main"
  providers = {
    openstack = openstack.ovh
    ovh       = ovh.ovh
  }

  name = "dummy"
  storage = {
    # Clasic storage
    "stock" = {
      size = 10
    }
    # Already existing storage, link the VM to it
    "external" = {
      size = 0
    }
    # High speed storage
    "sonic" = {
      size = 10
      type = "high-speed"
    }
  }
}

VM with custom network

You can select the network or the security-groups of your VM. OVH don't handle security-groups on private vRack network.

The "Ext-Net" is to have a public interface, and the other network is for vRack (need to be define before)

There is a vRack module to deploy a private vRack network with its subnets. (See the module for the declaration)

module "vm" {
  source = "git::https://github.com/reneca/tf-vm-ovh.git?ref=main"
  providers = {
    openstack = openstack.ovh
    ovh       = ovh.ovh
  }

  name       = "dummy"
  network = {
    public = {
      name = "Ext-Net"
    }
    private = {
      name = "${module.dev-net.net_name}"
    }
  }
  depends_on = [module.dev-net.subnets]
}

The IPv4 can also be define on the private network:

module "vm" {
  source = "git::https://github.com/reneca/tf-vm-ovh.git?ref=main"
  providers = {
    openstack = openstack.ovh
    ovh       = ovh.ovh
  }

  name       = "dummy"
  network = {
    public = {
      name = "Ext-Net"
    }
    private = {
      name = "${module.dev-net.net_name}"
      ipv4 = "10.0.0.1"
    }
  }
  depends_on = [module.dev-net.subnets]
}

And if you want to use multiple security group with only a public network interface

module "vm" {
  source = "git::https://github.com/reneca/tf-vm-ovh.git?ref=main"
  providers = {
    openstack = openstack.ovh
    ovh       = ovh.ovh
  }

  name            = "dummy"
  security_groups = ["default", "custom"]
}

VM with its associate DNS record

To create an associated DNS record for the VM, the dns_zone can be specified with an OVH domain name (managed by OVH).

With the following sample, the VM will have 4 DNS records:

  • dummy.example.fr IN A <vm_ipv4_address>
  • dummy.example.fr IN AAAA <vm_ipv6_address>
  • dummy.example.com IN A <vm_ipv4_address>
  • dummy.example.com IN AAAA <vm_ipv6_address>
module "vm" {
  source = "git::https://github.com/reneca/tf-vm-ovh.git?ref=main"
  providers = {
    openstack = openstack.ovh
    ovh       = ovh.ovh
  }

  name     = "dummy"
  dns_zone = ["example.fr", "example.com"]
}

Module specifications

Requirements

Name Version
terraform >= 0.14.0
openstack ~> 1.42.0
ovh >= 0.13.0

Providers

Name Version
openstack ~> 1.42.0
ovh >= 0.13.0

Modules

No modules.

Resources

Name Type
openstack_blockstorage_volume_v2.volume resource
openstack_compute_instance_v2.instance resource
openstack_compute_keypair_v2.ssh_keypair resource
openstack_compute_volume_attach_v2.ext_volume_attach resource
openstack_compute_volume_attach_v2.int_volume_attach resource
ovh_domain_zone_record.ipv4_zone_record resource
ovh_domain_zone_record.ipv6_zone_record resource
openstack_blockstorage_volume_v2.volume data source
openstack_compute_availability_zones_v2.zones data source

Inputs

Name Description Type Default Required
dns_ttl TTL of the DNS VM record (IPV4 and IPV6) number 3600 no
dns_zone Zone of your DNS (domain.ext) set(string) [] no
image Name of the VM image string "Debian 11" no
metadata Metadata key/value pairs to make available from within the instance map(any) {} no
name Name of your dev VM instance string n/a yes
network Network list of the instance map(object({ name = string, ipv4 = optional(string) }))
{
"public": {
"name": "Ext-Net"
}
}
no
region Region where you want to deploy the VM instance string null no
security_groups An array of one or more security group names to associate with the server (not working with OVH vRack) list(string)
[
"default"
]
no
ssh_key_path Path of your SSH key string "id_ecdsa.pub" no
storage Additional storage for the VM map(object({ type = optional(string), size = number })) {} no
type Type of your VM instance string "s1-2" no
user_data The user data to provide when launching the instance string null no

Outputs

Name Description
dns_names DNS names of the spawned instance
dns_zone_name DNS zone => name of the spawned instance
public_ipv4 IPV4s of the spawned instance
public_ipv6 IPV6s of the spawned instance
region Region where the instance was spawned

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.