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 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>"
}
Name | Url |
---|---|
OVH domain name | OVH token generation page |
Openstack compute | OpenRC file |
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"
}
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"
}
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"
}
}
}
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"]
}
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"]
}
Name | Version |
---|---|
terraform | >= 0.14.0 |
openstack | ~> 1.42.0 |
ovh | >= 0.13.0 |
Name | Version |
---|---|
openstack | ~> 1.42.0 |
ovh | >= 0.13.0 |
No modules.
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 |
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) })) |
{ |
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) |
[ |
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 |
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 |