Merge branch 'fix_tags' into 'main'

remove tags from deployement

See merge request ataxya/tsunami!2
This commit is contained in:
Ataxya 2022-07-04 22:34:31 +00:00
commit db27c24ddd
3 changed files with 38 additions and 15 deletions

View File

@ -1,18 +1,32 @@
# Tsunami
**Netbox + XO + Terraform + Ansible = The best deployment kit** **Netbox + XO + Terraform + Ansible = The best deployment kit**
How to run:<br> ## Configuration
cp passwd.auto.tfvars.example passwd.auto.tfvars<br>
replace all variable to match your infrastructure
edit cloud_network_config.tftpl to replace eth0 (to be changed) [Install terraform](https://www.terraform.io/downloads)
create a prefix with IP you want to use on netbox <br> replace your variables:
edit variables.auto.tfvars ```bash
# copy password template
cp passwd.auto.tfvars.example passwd.auto.tfvars
# edit with your infra passwords
nano passwd.auto.tfvars
# set your template vm network interface
nano cloud_network_config.tftpl
# create a prefix with IP you want to use on netbox, and set your vm variables
nano variables.auto.tfvars
```
You can add your playbook in the folder playbooks/ and use them in variables.auto.tfvars You can add your playbook in the folder playbooks/ and use them in variables.auto.tfvars
then ## Run
terraform init<br> ```bash
terraform plan<br> terraform init
terraform plan
terraform apply terraform apply
```

15
main.tf
View File

@ -31,7 +31,7 @@ data "xenorchestra_template" "template" {
} }
resource "xenorchestra_vm" "bar" { resource "xenorchestra_vm" "vm_deployed" {
memory_max = var.ram * 1024 * 1024 * 1024 memory_max = var.ram * 1024 * 1024 * 1024
cpus = var.cpu cpus = var.cpu
cloud_config = templatefile("cloud_config.tftpl", { cloud_config = templatefile("cloud_config.tftpl", {
@ -58,10 +58,7 @@ resource "xenorchestra_vm" "bar" {
size = var.disk_size * 1024 * 1024 * 1024 size = var.disk_size * 1024 * 1024 * 1024
} }
tags = [ tags = var.vm_tags
"Debian",
"Best Distro",
]
// Override the default create timeout from 5 mins to 20. // Override the default create timeout from 5 mins to 20.
timeouts { timeouts {
@ -72,6 +69,8 @@ resource "xenorchestra_vm" "bar" {
# Generate inventory file # Generate inventory file
resource "local_file" "inventory" { resource "local_file" "inventory" {
count = var.playbook != "" ? 1 : 0
filename = "inventory" filename = "inventory"
content = <<EOF content = <<EOF
[all] [all]
@ -80,12 +79,16 @@ EOF
} }
resource "time_sleep" "wait_30_seconds" { resource "time_sleep" "wait_30_seconds" {
depends_on = [xenorchestra_vm.bar] count = var.playbook != "" ? 1 : 0
depends_on = [xenorchestra_vm.vm_deployed]
create_duration = "30s" create_duration = "30s"
} }
resource "null_resource" "run-ansible" { resource "null_resource" "run-ansible" {
count = var.playbook != "" ? 1 : 0
provisioner "local-exec" { provisioner "local-exec" {
command = "ansible-playbook -D -i inventory playbooks/${var.playbook} " command = "ansible-playbook -D -i inventory playbooks/${var.playbook} "
environment = { environment = {

6
var.tf
View File

@ -68,6 +68,7 @@ variable "template" {
variable "playbook" { variable "playbook" {
type = string type = string
default = ""
} }
variable "cpu" { variable "cpu" {
@ -93,3 +94,8 @@ variable "disk_size" {
variable "ssh_keys" { variable "ssh_keys" {
type = string type = string
} }
variable "vm_tags" {
type = list
default = []
}