create base qcow2 image and one test stacj with one compute, net and pool

This commit is contained in:
Antoine 2020-08-06 00:34:05 +02:00
parent 9bc7773864
commit 5c964ae09d
Signed by: antoine
GPG Key ID: 098FB66FC0475E70
9 changed files with 86 additions and 147 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
.terraform
*.tfstate.backup
base/images/*
!base/images/.gitkeep

45
base/libvirtd.tf Normal file
View File

@ -0,0 +1,45 @@
# https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/website/docs/r
terraform {
required_version = ">= 0.12"
required_providers {
null = "~> 2.1"
template = "~> 2.1"
libvirt = ">= 0.0.0"
}
backend "etcdv3" {
endpoints = ["https://100.64.0.19:2379"]
lock = true
prefix = "/terraform-state/"
cacert_path = "/home/antoine/virtualization/kubernetes-the-hard-way/certs/ca.pem"
cert_path = "/home/antoine/virtualization/kubernetes-the-hard-way/certs/kubernetes.pem"
key_path = "/home/antoine/virtualization/kubernetes-the-hard-way/certs/kubernetes-key.pem"
}
}
provider "libvirt" {
uri = "qemu+tcp://dx30.localdomain/system"
}
resource "libvirt_pool" "pool_1" {
name = "pool_1"
type = "dir"
path = "/var/lib/libvirt/pool/pool_1"
}
resource "libvirt_volume" "centos7_qcow2" {
name = "centos7.qcow2"
pool = libvirt_pool.pool_1.name
source = "./images/CentOS-7-x86_64-GenericCloud.qcow2"
format = "qcow2"
}
resource "libvirt_volume" "debian_buster_qcow2" {
name = "debian-buster.qcow2"
pool = libvirt_pool.pool_1.name
source = "./images/debian-10-openstack-amd64.qcow2"
format = "qcow2"
}

@ -1 +1 @@
Subproject commit 29eadc7b92bef861bf699822b751520ba2764253
Subproject commit 6e6f8cb6470380c8b4c07910d98f744bad8852a3

View File

@ -1,38 +0,0 @@
# https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/website/docs/r
terraform {
required_version = ">= 0.12"
required_providers {
libvirt = ">= 0.0.0"
}
}
provider "libvirt" {
uri = "qemu+tcp://127.0.0.1/system"
# uri = "qemu+ssh://root@192.168.100.10/system"
}
resource "libvirt_pool" "pool_1" {
name = "pool_1"
type = "dir"
path = "/var/lib/libvirt/pool"
}
# -------- volume disk --------
# https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/website/docs/r/volume.html.markdown
resource "libvirt_volume" "centos7_qcow2" {
name = "centos7.qcow2"
pool = "default"
source = "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2"
format = "qcow2"
}
resource "libvirt_volume" "debian_buster_qcow2" {
name = "debian-buster.qcow2"
pool = "default"
source = "https://cdimage.debian.org/cdimage/openstack/current/debian-10.4.3-20200610-openstack-amd64.qcow2"
format = "qcow2"
}

View File

@ -1,79 +0,0 @@
{
"version": 4,
"terraform_version": "0.12.28",
"serial": 203,
"lineage": "e57b8df5-87bd-3954-0ba8-9cbedff9b460",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "libvirt_pool",
"name": "pool_1",
"provider": "provider.libvirt",
"instances": [
{
"schema_version": 0,
"attributes": {
"allocation": 69478645760,
"available": null,
"capacity": 73445531648,
"id": "3a205457-1e97-455a-8fe6-9ed621f7ba99",
"name": "pool_1",
"path": "/var/lib/libvirt/pool",
"type": "dir",
"xml": []
},
"private": "bnVsbA=="
}
]
},
{
"mode": "managed",
"type": "libvirt_volume",
"name": "centos7_qcow2",
"provider": "provider.libvirt",
"instances": [
{
"schema_version": 0,
"attributes": {
"base_volume_id": null,
"base_volume_name": null,
"base_volume_pool": null,
"format": "qcow2",
"id": "/var/lib/libvirt/pool/default/centos7.qcow2",
"name": "centos7.qcow2",
"pool": "default",
"size": 8589934592,
"source": "https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2",
"xml": []
},
"private": "bnVsbA=="
}
]
},
{
"mode": "managed",
"type": "libvirt_volume",
"name": "debian_buster_qcow2",
"provider": "provider.libvirt",
"instances": [
{
"schema_version": 0,
"attributes": {
"base_volume_id": null,
"base_volume_name": null,
"base_volume_pool": null,
"format": "qcow2",
"id": "/var/lib/libvirt/pool/default/debian-buster.qcow2",
"name": "debian-buster.qcow2",
"pool": "default",
"size": 2147483648,
"source": "https://cdimage.debian.org/cdimage/openstack/current/debian-10.4.3-20200610-openstack-amd64.qcow2",
"xml": []
},
"private": "bnVsbA=="
}
]
}
]
}

View File

@ -6,7 +6,7 @@ resource "libvirt_domain" "db1" {
name = "db1"
memory = "1024"
vcpu = 1
running = "false"
running = "true"
autostart = "true"
boot_device {
@ -14,12 +14,11 @@ resource "libvirt_domain" "db1" {
}
network_interface {
network_name = "default"
# network_name = libvirt_network.private_network.name
network_name = libvirt_network.private_network.name
}
disk {
volume_id = libvirt_volume.debian_buster_qcow2.id
volume_id = libvirt_volume.my_root_debian.id
}
# disk {
@ -40,11 +39,3 @@ resource "libvirt_domain" "db1" {
autoport = "true"
}
}
resource "libvirt_volume" "debian_buster_qcow2" {
name = "debian-buster.qcow2"
pool = "default"
source = "https://cdimage.debian.org/cdimage/openstack/current/debian-10.4.3-20200610-openstack-amd64.qcow2"
format = "qcow2"
}

View File

@ -9,21 +9,47 @@ terraform {
libvirt = ">= 0.0.0"
}
backend "etcdv3" {
endpoints = ["https://100.64.0.19:2379"]
lock = true
prefix = "/terraform-state/stack"
cacert_path = "/home/antoine/virtualization/kubernetes-the-hard-way/certs/ca.pem"
cert_path = "/home/antoine/virtualization/kubernetes-the-hard-way/certs/kubernetes.pem"
key_path = "/home/antoine/virtualization/kubernetes-the-hard-way/certs/kubernetes-key.pem"
}
}
provider "libvirt" {
uri = "qemu+tcp://127.0.0.1/system"
# uri = "qemu+ssh://root@192.168.100.10/system"
uri = "qemu+tcp://dx30.localdomain/system"
}
data "template_file" "user_data" {
template = "${file("${path.module}/cloud_init.cfg")}"
}
variable "pool_1" {
type = string
default = "pool_1"
description = "already created pool name, set with variable because libvirt provider dont' wotk with data resource"
}
variable "debian_buster_qcow2" {
type = string
default = "debian-buster.qcow2"
description = "already created debian vol, set with variable because libvirt provider dont' wotk with data resource"
}
variable "centos7_qcow2" {
type = string
default = "centos7.qcow2"
description = "already created centos vol, set with variable because libvirt provider dont' wotk with data resource"
}
# Use CloudInit to add the instance
resource "libvirt_cloudinit_disk" "commoninit" {
name = "commoninit.iso"
pool = "default"
pool = var.pool_1
user_data = data.template_file.user_data.rendered
}

View File

@ -1,8 +0,0 @@
{
"version": 4,
"terraform_version": "0.12.28",
"serial": 121,
"lineage": "67fe8f67-1e0d-4c6e-4440-3eac0ca3aadd",
"outputs": {},
"resources": []
}

View File

@ -6,20 +6,19 @@
resource "libvirt_volume" "my_root_centos" {
name = "my-root-centos"
base_volume_name = "centos7.qcow2"
# base_volume_id = libvirt_volume.centos7_qcow2.id
pool = var.pool_1
base_volume_name = var.centos7_qcow2
}
resource "libvirt_volume" "my_root_debian" {
name = "my-root-debian"
base_volume_name = "debian-buster.qcow2"
# base_volume_id = libvirt_volume.debian_buster_qcow2.id
pool = var.pool_1
base_volume_name = var.debian_buster_qcow2
}
resource "libvirt_volume" "external_disk_1" {
name = "external-disk-1"
# 10Gb
size = 10737418240
pool = "pool_1"
# pool = libvirt_pool.pool_1.name
pool = var.pool_1
}