summaryrefslogtreecommitdiff
path: root/docs/automation
diff options
context:
space:
mode:
Diffstat (limited to 'docs/automation')
-rw-r--r--docs/automation/cloud-init.rst47
-rw-r--r--docs/automation/index.rst5
-rw-r--r--docs/automation/terraform/index.rst12
-rw-r--r--docs/automation/terraform/terraformAWS.rst104
-rw-r--r--docs/automation/terraform/terraformAZ.rst488
-rw-r--r--docs/automation/terraform/terraformGoogle.rst708
-rw-r--r--docs/automation/terraform/terraformvSphere.rst400
-rw-r--r--docs/automation/terraform/terraformvyos.rst39
-rw-r--r--docs/automation/vyos-api.rst32
9 files changed, 1732 insertions, 103 deletions
diff --git a/docs/automation/cloud-init.rst b/docs/automation/cloud-init.rst
index bbc8967c..0b9ee207 100644
--- a/docs/automation/cloud-init.rst
+++ b/docs/automation/cloud-init.rst
@@ -8,8 +8,8 @@ VyOS cloud-init
Cloud and virtualized instances of VyOS are initialized using the
industry-standard cloud-init. Via cloud-init, the system performs tasks such as
-injecting SSH keys and configuring the network. In addition, the user can supply
-a custom configuration at the time of instance launch.
+injecting SSH keys and configuring the network. In addition, the user can
+supply a custom configuration at the time of instance launch.
**************
Config Sources
@@ -25,9 +25,9 @@ VyOS support three types of config sources.
network settings like IP addresses, routes, DNS. Available only in several
cloud and virtualization platforms.
-* User-data - User-data is specified by the user. This config source offers the
- ability to insert any CLI configuration commands into the configuration before
- the first boot.
+* User-data - User-data is specified by the user. This config source offers
+ the ability to insert any CLI configuration commands into the configuration
+ before the first boot.
*********
User-data
@@ -39,8 +39,8 @@ depending on cloud provider. Also, it can be compressed using gzip, which makes
sense with a long configuration commands list, because of the hard limit to
~16384 bytes for the whole user-data.
-The easiest way to configure the system via user-data is the Cloud-config syntax
-described below.
+The easiest way to configure the system via user-data is the Cloud-config
+syntax described below.
********************
Cloud-config modules
@@ -50,11 +50,12 @@ In VyOS, by default, enables only two modules:
* ``write_files`` - this module allows to insert any files into the filesystem
before the first boot, for example, pre-generated encryption keys,
- certificates, or even a whole ``config.boot`` file. The format is described in the cloudinit documentation `Cloud-init-write_files`_.
+ certificates, or even a whole ``config.boot`` file. The format is described
+ in the cloudinit documentation `Cloud-init-write_files`_.
-* ``vyos_userdata`` - the module accepts a list of CLI configuration commands in
- a ``vyos_config_commands`` section, which gives an easy way to configure the
- system during deployment.
+* ``vyos_userdata`` - the module accepts a list of CLI configuration commands
+ in a ``vyos_config_commands`` section, which gives an easy way to configure
+ the system during deployment.
************************
cloud-config file format
@@ -62,8 +63,8 @@ cloud-config file format
A cloud-config document is written in YAML. The file must begin
with ``#cloud-config`` line. The only supported top-level keys are
-``vyos_config_commands`` and ``write_files``. The use of these keys is described
-in the following two sections.
+``vyos_config_commands`` and ``write_files``. The use of these keys is
+described in the following two sections.
************************
@@ -81,13 +82,16 @@ Commands requirements:
* If command ends in a value, it must be inside single quotes.
* A single-quote symbol is not allowed inside command or value.
-The commands list produced by the ``show configuration commands`` command on a
-VyOS router should comply with all the requirements, so it is easy to get a
-proper commands list by copying it from another router.
+The commands list produced by the ``show configuration commands`` command
+on a VyOS router should comply with all the requirements, so it is easy
+to get a proper commands list by copying it from another router.
The configuration specified in the cloud-config document overwrites default
configuration values and values configured via Metadata.
+After the ``vyos_config_commands`` are executed, cloud-init will
+automatically perform a ``commit`` and ``save`` operation.
+
Here is an example cloud-config that appends configuration at the time of
first boot.
@@ -214,9 +218,8 @@ the method with KVM to attach the ISO as a CD drive follows.
--noautoconsole
-For more information on the NoCloud data source, visit its `page
-<https://cloudinit.readthedocs.io/en/latest/reference/datasources/nocloud.html>`_
-in the cloud-init documentation.
+For more information on the NoCloud data source, visit its
+page `nocloud`_ in the cloud-init documentation.
***************
Troubleshooting
@@ -227,8 +230,8 @@ valid YAML. Online resources such as https://www.yamllint.com/ provide
a simple tool for validating YAML.
cloud-init logs to /var/log/cloud-init.log. This file can be helpful in
-determining why the configuration varies from what you expect. You can fetch the
-most important data filtering output for ``vyos`` keyword:
+determining why the configuration varies from what you expect. You can fetch
+the most important data filtering output for ``vyos`` keyword:
.. code-block:: none
@@ -428,5 +431,5 @@ References
.. _cloud-init-docs: https://docs.vyos.io/en/equuleus/automation/cloud-init.html?highlight=cloud-init#vyos-cloud-init
.. _Cloud-init-Support: https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_cloud_init
.. _Cloud-init-write_files: https://cloudinit.readthedocs.io/en/latest/topics/examples.html#writing-out-arbitrary-files
-
+.. _nocloud: https://cloudinit.readthedocs.io/en/latest/reference/datasources/nocloud.html
.. start_vyoslinter
diff --git a/docs/automation/index.rst b/docs/automation/index.rst
index 48e83a96..fe70acce 100644
--- a/docs/automation/index.rst
+++ b/docs/automation/index.rst
@@ -2,11 +2,6 @@
VyOS Automation
###############
-
- * Nornir
- * startup scripts
-
-
.. toctree::
:maxdepth: 2
diff --git a/docs/automation/terraform/index.rst b/docs/automation/terraform/index.rst
index 9a51df91..42af58bd 100644
--- a/docs/automation/terraform/index.rst
+++ b/docs/automation/terraform/index.rst
@@ -2,17 +2,13 @@
VyOS Terraform
##############
-
- * Nornir
- * startup scripts
-
-
.. toctree::
:maxdepth: 1
:caption: Content
+ terraformvyos
terraformAWS
-# terraformAZ
-# terraformvSphere
-# terraformGoogle
+ terraformAZ
+ terraformvSphere
+ terraformGoogle
diff --git a/docs/automation/terraform/terraformAWS.rst b/docs/automation/terraform/terraformAWS.rst
index c81fe906..c705d55e 100644
--- a/docs/automation/terraform/terraformAWS.rst
+++ b/docs/automation/terraform/terraformAWS.rst
@@ -1,43 +1,11 @@
:lastproofread: 2024-01-11
-.. _vyos-terraform:
+.. _terraformAWS:
-Terraform for VyOS
-==================
+Deploying VyOS in the AWS cloud
+===============================
-VyOS supports development infrastructure via Terraform and provisioning via Ansible.
-Terraform allows you to automate the process of deploying instances on many cloud and virtual platforms.
-In this article, we will look at using terraforms to deploy vyos on platforms - AWS, AZURE, and vSphere.
-More detailed about what is Terraform you can write using the link_.
-
-Need to install_ Terraform
-
-Structure of files in the standard Terraform project:
-
-.. code-block:: none
-
- .
- ├── main.tf # The main script
- ├── version.tf # File for the changing version of Terraform.
- ├── variables.tf # The file of all variables in "main.tf"
- └── terraform.tfvars # The value of all variables (passwords, login, ip adresses and so on)
-
-
-General commands that we will use for running Terraform scripts
-
-
-.. code-block:: none
-
- #cd /<your folder> # go to the Terrafom project
- #terraform init # install all addons and provider (aws az and so on)
- #terraform plan # show wtah is changing
- #terraform apply # run script
- #yes # apply running
-
-
-Deploying vyos in the AWS cloud
--------------------------------
-With the help of terraforms, you can quickly deploy Vyos-based infrastructure in the AWS cloud. If necessary, the infrastructure can be removed using terraform.
+With the help of Terraform, you can quickly deploy VyOS-based infrastructure in the AWS cloud. If necessary, the infrastructure can be removed using terraform.
Also we will make provisioning using Ansible.
@@ -58,16 +26,16 @@ Step by step:
AWS
-1.1 Create an account with AWS and get your "access_key", "secret key"
+ 1 Create an account with AWS and get your "access_key", "secret key"
-1.2 Create a key pair_ and download your .pem key
+ 2 Create a key pair_ and download your .pem key
.. image:: /_static/images/keypairs.png
:width: 50%
:align: center
:alt: Network Topology Diagram
-1.3 Create a security group_ for the new VyOS instance and open all traffic
+ 3 Create a security group_ for the new VyOS instance and open all traffic
.. image:: /_static/images/sg.png
:width: 50%
@@ -83,36 +51,36 @@ AWS
Terraform
-2.1 Create a0 UNIX or Windows instance
+ 1 Create an UNIX or Windows instance
-2.2 Download and install Terraform
+ 2 Download and install Terraform
-2.3 Create the folder for example /root/awsterraform
+ 3 Create the folder for example /root/awsterraform
.. code-block:: none
mkdir /root/awsterraform
-2.4 Copy all files into your Terraform project "/root/awsterraform" (vyos.tf, var.tf, terraform.tfvars,version.tf), more detailed see `Structure of files Terrafom for AWS`_
+ 4 Copy all files into your Terraform project "/root/awsterraform" (vyos.tf, var.tf, terraform.tfvars,version.tf), more detailed see `Structure of files Terrafom for AWS`_
-2.5 Type the commands :
+ 5 Type the commands :
.. code-block:: none
- #cd /<your folder>
- #terraform init
+ cd /<your folder>
+ terraform init
Ansible
-3.1 Create a UNIX instance whenever you want (local, cloud, and so on)
+ 1 Create an UNIX instance whenever you want (local, cloud, and so on)
-3.2 Download and install Ansible
+ 2 Download and install Ansible
-3.3 Create the folder for example /root/aws/
+ 3 Create the folder for example /root/aws/
-3.4 Copy all files into your Ansible project "/root/aws/" (ansible.cfg, instance.yml, mykey.pem and "all"), more detailed see `Structure of files Ansible for AWS`_
+ 4 Copy all files into your Ansible project "/root/aws/" (ansible.cfg, instance.yml, mykey.pem and "all"), more detailed see `Structure of files Ansible for AWS`_
mykey.pem you have to get using step 1.2
@@ -120,14 +88,14 @@ mykey.pem you have to get using step 1.2
Start
-4.1 Type the commands on your Terrafom instance:
+Type the commands on your Terrafom instance:
.. code-block:: none
- #cd /<your folder>
- #terraform plan
- #terraform apply
- #yes
+ cd /<your folder>
+ terraform plan
+ terraform apply
+ yes
Start creating an AWS instance and check the result
@@ -265,14 +233,14 @@ Start creating an AWS instance and check the result
null_resource.SSHconnection2: Still creating... [40s elapsed]
null_resource.SSHconnection2: Still creating... [50s elapsed]
null_resource.SSHconnection2: Still creating... [1m0s elapsed]
- null_resource.SSHconnection2 (remote-exec): ok: [54.144.84.120]
+ null_resource.SSHconnection2 (remote-exec): ok: [54.xxx.xxx.xxx]
null_resource.SSHconnection2 (remote-exec): TASK [Configure general settings for the vyos hosts group] *********************
null_resource.SSHconnection2: Still creating... [1m10s elapsed]
- null_resource.SSHconnection2 (remote-exec): changed: [54.144.84.120]
+ null_resource.SSHconnection2 (remote-exec): changed: [54.xxx.xxx.xxx]
null_resource.SSHconnection2 (remote-exec): PLAY RECAP *********************************************************************
- null_resource.SSHconnection2 (remote-exec): 54.144.84.120 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
+ null_resource.SSHconnection2 (remote-exec): 54.xxx.xxx.xxx : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
null_resource.SSHconnection2: Creation complete after 1m16s [id=4902256962410024771]
@@ -280,7 +248,7 @@ Start creating an AWS instance and check the result
Outputs:
- my_IP = "54.144.84.120"
+ my_IP = "54.xxx.xxx.xxx"
@@ -289,17 +257,17 @@ If you need to delete the instance please type the command:
.. code-block:: none
- #terraform destroy
+ terraform destroy
Troubleshooting
---------------
-1. Ansible doesn't connect via SSH to your AWS instance: you have to check that your SSH key has copied into the path /root/aws/.
+ 1 Ansible doesn't connect via SSH to your AWS instance: you have to check that your SSH key has copied into the path /root/aws/.
Also, increase the time in the file instance.yml from 300 sec to 500 sec or more. (It depends on your location).
Make sure that you have opened access to the instance in the security group.
-2. Terraform doesn't connect via SSH to your Ansible instance: you have to check the correct login and password in the part of the file vyos. tf
+ 2 Terraform doesn't connect via SSH to your Ansible instance: you have to check the correct login and password in the part of the file VyOS. tf
.. code-block:: none
@@ -320,8 +288,8 @@ Structure of files Terrafom for AWS
.
├── vyos.tf # The main script
- ├── var.tf # File for the changing version of Terraform.
- ├── versions.tf # The file of all variables in "vyos.tf"
+ ├── var.tf # The file of all variables in "vyos.tf"
+ ├── versions.tf # File for the changing version of Terraform.
└── terraform.tfvars # The value of all variables (passwords, login, ip adresses and so on)
@@ -533,7 +501,7 @@ instance.yml
##############################################################################
# About tasks:
# "Wait 300 seconds, but only start checking after 60 seconds" - try to make ssh connection every 60 seconds until 300 seconds
- # "Configure general settings for the vyos hosts group" - make provisioning into AWS VyOS node
+ # "Configure general settings for the VyOS hosts group" - make provisioning into AWS VyOS node
# You have to add all necessary cammans of VyOS under the block "lines:"
##############################################################################
@@ -549,15 +517,15 @@ instance.yml
delay: 60
timeout: 300
- - name: "Configure general settings for the vyos hosts group"
+ - name: "Configure general settings for the VyOS hosts group"
vyos_config:
lines:
- - set system name-server 8.8.8.8
+ - set system name-server xxx.xxx.xxx.xxx
save:
true
-all
+group_vars/all
.. code-block:: none
diff --git a/docs/automation/terraform/terraformAZ.rst b/docs/automation/terraform/terraformAZ.rst
new file mode 100644
index 00000000..a0fea023
--- /dev/null
+++ b/docs/automation/terraform/terraformAZ.rst
@@ -0,0 +1,488 @@
+:lastproofread: 2024-03-03
+
+.. _terraformAZ:
+
+Deploying VyOS in the Azure cloud
+=================================
+
+With the help of Terraform, you can quickly deploy VyOS-based infrastructure in the Azure cloud. If necessary, the infrastructure can be removed using terraform.
+Also we will make provisioning using Ansible.
+
+In this case, we'll create the necessary files for Terraform and Ansible next using Terraform we'll create a single instance on the Azure cloud and make provisioning using Ansible.
+
+Preparation steps for deploying VyOS on Azure
+---------------------------------------------
+
+How to create a single instance and install your configuration using Terraform+Ansible+Azure
+Step by step:
+
+Azure
+
+ 1 Create an account with Azure
+
+Terraform
+
+
+ 1 Create an UNIX or Windows instance
+
+ 2 Download and install Terraform
+
+ 3 Create the folder for example /root/azvyos/
+
+.. code-block:: none
+
+ mkdir /root/azvyos
+
+ 4 Copy all files into your Terraform project "/root/azvyos" (vyos.tf, var.tf, terraform.tfvars), more detailed see `Structure of files Terrafom for Azure`_
+
+ 5 Login with Azure using the command
+
+.. code-block:: none
+
+ az login
+
+2.6 Type the commands :
+
+.. code-block:: none
+
+ cd /<your folder>
+ terraform init
+
+Ansible
+
+
+ 1 Create an UNIX instance whenever you want (local, cloud, and so on)
+
+ 2 Download and install Ansible
+
+ 3 Create the folder for example /root/az/
+
+ 4 Copy all files into your Ansible project "/root/az/" (ansible.cfg, instance.yml,"all"), more detailed see `Structure of files Ansible for Azure`_
+
+
+Start
+
+
+Type the commands on your Terrafom instance:
+
+.. code-block:: none
+
+ cd /<your folder>
+ terraform plan
+ terraform apply
+ yes
+
+After executing all the commands you will have your VyOS instance on the Azure cloud with your configuration, it's a very convenient desition.
+If you need to delete the instance please type the command:
+
+.. code-block:: none
+
+ terraform destroy
+
+Structure of files Terrafom for Azure
+-------------------------------------
+
+.. code-block:: none
+
+ .
+ ├── vyos.tf # The main script
+ ├── var.tf # File for the changing version of Terraform.
+ └── terraform.tfvars # The value of all variables (passwords, login, ip adresses and so on)
+
+File contents of Terrafom for Azure
+-----------------------------------
+
+vyos.tf
+
+.. code-block:: none
+
+
+ ##############################################################################
+ # HashiCorp Guide to Using Terraform on Azure
+ # This Terraform configuration will create the following:
+ # Resource group with a virtual network and subnet
+ # An VyOS server without ssh key (only login+password)
+ ##############################################################################
+
+ # Chouse a provider
+
+ provider "azurerm" {
+ features {}
+ }
+
+ # Create a resource group. In Azure every resource belongs to a
+ # resource group.
+
+ resource "azurerm_resource_group" "azure_vyos" {
+ name = "${var.resource_group}"
+ location = "${var.location}"
+ }
+
+ # The next resource is a Virtual Network.
+
+ resource "azurerm_virtual_network" "vnet" {
+ name = "${var.virtual_network_name}"
+ location = "${var.location}"
+ address_space = ["${var.address_space}"]
+ resource_group_name = "${var.resource_group}"
+ }
+
+ # Build a subnet to run our VMs in.
+
+ resource "azurerm_subnet" "subnet" {
+ name = "${var.prefix}subnet"
+ virtual_network_name = "${azurerm_virtual_network.vnet.name}"
+ resource_group_name = "${var.resource_group}"
+ address_prefixes = ["${var.subnet_prefix}"]
+ }
+
+ ##############################################################################
+ # Build an VyOS VM from the Marketplace
+ # To finde nessesery image use the command:
+ #
+ # az vm image list --offer vyos --all
+ #
+ # Now that we have a network, we'll deploy an VyOS server.
+ # An Azure Virtual Machine has several components. In this example we'll build
+ # a security group, a network interface, a public ip address, a storage
+ # account and finally the VM itself. Terraform handles all the dependencies
+ # automatically, and each resource is named with user-defined variables.
+ ##############################################################################
+
+
+ # Security group to allow inbound access on port 22 (ssh)
+
+ resource "azurerm_network_security_group" "vyos-sg" {
+ name = "${var.prefix}-sg"
+ location = "${var.location}"
+ resource_group_name = "${var.resource_group}"
+
+ security_rule {
+ name = "SSH"
+ priority = 100
+ direction = "Inbound"
+ access = "Allow"
+ protocol = "Tcp"
+ source_port_range = "*"
+ destination_port_range = "22"
+ source_address_prefix = "${var.source_network}"
+ destination_address_prefix = "*"
+ }
+ }
+
+ # A network interface.
+
+ resource "azurerm_network_interface" "vyos-nic" {
+ name = "${var.prefix}vyos-nic"
+ location = "${var.location}"
+ resource_group_name = "${var.resource_group}"
+
+ ip_configuration {
+ name = "${var.prefix}ipconfig"
+ subnet_id = "${azurerm_subnet.subnet.id}"
+ private_ip_address_allocation = "Dynamic"
+ public_ip_address_id = "${azurerm_public_ip.vyos-pip.id}"
+ }
+ }
+
+ # Add a public IP address.
+
+ resource "azurerm_public_ip" "vyos-pip" {
+ name = "${var.prefix}-ip"
+ location = "${var.location}"
+ resource_group_name = "${var.resource_group}"
+ allocation_method = "Dynamic"
+ }
+
+ # Build a virtual machine. This is a standard VyOS instance from Marketplace.
+
+ resource "azurerm_virtual_machine" "vyos" {
+ name = "${var.hostname}-vyos"
+ location = "${var.location}"
+ resource_group_name = "${var.resource_group}"
+ vm_size = "${var.vm_size}"
+
+ network_interface_ids = ["${azurerm_network_interface.vyos-nic.id}"]
+ delete_os_disk_on_termination = "true"
+
+ # To finde an information about the plan use the command:
+ # az vm image list --offer vyos --all
+
+ plan {
+ publisher = "sentriumsl"
+ name = "vyos-1-3"
+ product = "vyos-1-2-lts-on-azure"
+ }
+
+ storage_image_reference {
+ publisher = "${var.image_publisher}"
+ offer = "${var.image_offer}"
+ sku = "${var.image_sku}"
+ version = "${var.image_version}"
+ }
+
+ storage_os_disk {
+ name = "${var.hostname}-osdisk"
+ managed_disk_type = "Standard_LRS"
+ caching = "ReadWrite"
+ create_option = "FromImage"
+ }
+
+ os_profile {
+ computer_name = "${var.hostname}"
+ admin_username = "${var.admin_username}"
+ admin_password = "${var.admin_password}"
+ }
+
+ os_profile_linux_config {
+ disable_password_authentication = false
+ }
+ }
+
+ data "azurerm_public_ip" "example" {
+ depends_on = ["azurerm_virtual_machine.vyos"]
+ name = "vyos-ip"
+ resource_group_name = "${var.resource_group}"
+ }
+ output "public_ip_address" {
+ value = data.azurerm_public_ip.example.ip_address
+ }
+
+ # IP of AZ instance copied to a file ip.txt in local system
+
+ resource "local_file" "ip" {
+ content = data.azurerm_public_ip.example.ip_address
+ filename = "ip.txt"
+ }
+
+ #Connecting to the Ansible control node using SSH connection
+
+ resource "null_resource" "nullremote1" {
+ depends_on = ["azurerm_virtual_machine.vyos"]
+ connection {
+ type = "ssh"
+ user = "root"
+ password = var.password
+ host = var.host
+ }
+
+ # Copying the ip.txt file to the Ansible control node from local system
+
+ provisioner "file" {
+ source = "ip.txt"
+ destination = "/root/az/ip.txt"
+ }
+ }
+
+ resource "null_resource" "nullremote2" {
+ depends_on = ["azurerm_virtual_machine.vyos"]
+ connection {
+ type = "ssh"
+ user = "root"
+ password = var.password
+ host = var.host
+ }
+
+ # Command to run ansible playbook on remote Linux OS
+
+ provisioner "remote-exec" {
+
+ inline = [
+ "cd /root/az/",
+ "ansible-playbook instance.yml"
+ ]
+ }
+ }
+
+
+var.tf
+
+.. code-block:: none
+
+ ##############################################################################
+ # Variables File
+ #
+ # Here is where we store the default values for all the variables used in our
+ # Terraform code.
+ ##############################################################################
+
+ variable "resource_group" {
+ description = "The name of your Azure Resource Group."
+ default = "my_resource_group"
+ }
+
+ variable "prefix" {
+ description = "This prefix will be included in the name of some resources."
+ default = "vyos"
+ }
+
+ variable "hostname" {
+ description = "Virtual machine hostname. Used for local hostname, DNS, and storage-related names."
+ default = "vyos_terraform"
+ }
+
+ variable "location" {
+ description = "The region where the virtual network is created."
+ default = "centralus"
+ }
+
+ variable "virtual_network_name" {
+ description = "The name for your virtual network."
+ default = "vnet"
+ }
+
+ variable "address_space" {
+ description = "The address space that is used by the virtual network. You can supply more than one address space. Changing this forces a new resource to be created."
+ default = "10.0.0.0/16"
+ }
+
+ variable "subnet_prefix" {
+ description = "The address prefix to use for the subnet."
+ default = "10.0.10.0/24"
+ }
+
+ variable "storage_account_tier" {
+ description = "Defines the storage tier. Valid options are Standard and Premium."
+ default = "Standard"
+ }
+
+ variable "storage_replication_type" {
+ description = "Defines the replication type to use for this storage account. Valid options include LRS, GRS etc."
+ default = "LRS"
+ }
+
+ # The most chippers size
+
+ variable "vm_size" {
+ description = "Specifies the size of the virtual machine."
+ default = "Standard_B1s"
+ }
+
+ variable "image_publisher" {
+ description = "Name of the publisher of the image (az vm image list)"
+ default = "sentriumsl"
+ }
+
+ variable "image_offer" {
+ description = "Name of the offer (az vm image list)"
+ default = "vyos-1-2-lts-on-azure"
+ }
+
+ variable "image_sku" {
+ description = "Image SKU to apply (az vm image list)"
+ default = "vyos-1-3"
+ }
+
+ variable "image_version" {
+ description = "Version of the image to apply (az vm image list)"
+ default = "1.3.3"
+ }
+
+ variable "admin_username" {
+ description = "Administrator user name"
+ default = "vyos"
+ }
+
+ variable "admin_password" {
+ description = "Administrator password"
+ default = "Vyos0!"
+ }
+
+ variable "source_network" {
+ description = "Allow access from this network prefix. Defaults to '*'."
+ default = "*"
+ }
+
+ variable "password" {
+ description = "pass for Ansible"
+ type = string
+ sensitive = true
+ }
+ variable "host"{
+ description = "IP of my Ansible"
+ }
+
+terraform.tfvars
+
+.. code-block:: none
+
+ password = "" # password for Ansible SSH
+ host = "" # IP of my Ansible
+
+
+Structure of files Ansible for Azure
+------------------------------------
+
+.. code-block:: none
+
+ .
+ ├── group_vars
+ └── all
+ ├── ansible.cfg
+ └── instance.yml
+
+
+File contents of Ansible for Azure
+----------------------------------
+
+ansible.cfg
+
+.. code-block:: none
+
+ [defaults]
+ inventory = /root/az/ip.txt
+ host_key_checking= False
+ remote_user=vyos
+
+
+instance.yml
+
+
+.. code-block:: none
+
+ ##############################################################################
+ # About tasks:
+ # "Wait 300 seconds, but only start checking after 60 seconds" - try to make ssh connection every 60 seconds until 300 seconds
+ # "Configure general settings for the VyOS hosts group" - make provisioning into Azure VyOS node
+ # You have to add all necessary cammans of VyOS under the block "lines:"
+ ##############################################################################
+
+
+ - name: integration of terraform and ansible
+ hosts: all
+ gather_facts: 'no'
+
+ tasks:
+
+ - name: "Wait 300 seconds, but only start checking after 60 seconds"
+ wait_for_connection:
+ delay: 60
+ timeout: 300
+
+ - name: "Configure general settings for the VyOS hosts group"
+ vyos_config:
+ lines:
+ - set system name-server xxx.xxx.xxx.xxx
+ save:
+ true
+
+
+group_vars/all
+
+.. code-block:: none
+
+ ansible_connection: ansible.netcommon.network_cli
+ ansible_network_os: vyos.vyos.vyos
+
+ # user and password gets from terraform variables "admin_username" and "admin_password" in the file /root/azvyos/var.tf
+ ansible_user: vyos
+ ansible_ssh_pass: Vyos0!
+
+Sourse files for Azure from GIT
+-------------------------------
+
+All files about the article can be found here_
+
+.. _here: https://github.com/vyos/vyos-automation/tree/main/TerraformCloud/Azure_terraform_ansible_single_vyos_instance-main
+
+
diff --git a/docs/automation/terraform/terraformGoogle.rst b/docs/automation/terraform/terraformGoogle.rst
new file mode 100644
index 00000000..7cdd1211
--- /dev/null
+++ b/docs/automation/terraform/terraformGoogle.rst
@@ -0,0 +1,708 @@
+:lastproofread: 2024-03-25
+
+.. _terraformgoogle:
+
+Deploying VyOS in the google cloud
+==================================
+
+With the help of Terraform, you can quickly deploy VyOS-based infrastructure in the google cloud. If necessary, the infrastructure can be removed using terraform.
+Also we will make provisioning using Ansible.
+
+In this case, we'll create the necessary files for Terraform and Ansible next using Terraform we'll create a single instance on the google cloud and make provisioning using Ansible.
+
+Preparation steps for deploying VyOS on google
+----------------------------------------------
+
+How to create a single instance and install your configuration using Terraform+Ansible+google
+Step by step:
+
+google cloud
+
+
+ 1 Create an account with google cloud and a new project
+
+.. image:: /_static/images/project.png
+ :width: 50%
+ :align: center
+ :alt: Network Topology Diagram
+
+ 2 Create a service aacount and download your key (.JSON)
+
+.. image:: /_static/images/service.png
+ :width: 50%
+ :align: center
+ :alt: Network Topology Diagram
+
+.. image:: /_static/images/key.png
+ :width: 50%
+ :align: center
+ :alt: Network Topology Diagram
+
+The .JSON file download automaticly after creating and will look like:
+
+.. image:: /_static/images/json.png
+ :width: 50%
+ :align: center
+ :alt: Network Topology Diagram
+
+
+Terraform
+
+
+ 1 Create an UNIX or Windows instance
+
+ 2 Download and install Terraform
+
+ 3 Create the folder for example /root/google
+
+.. code-block:: none
+
+ mkdir /root/google
+
+ 4 Copy all files into your Terraform project "/root/google" (vyos.tf, var.tf, terraform.tfvars, .JSON), more detailed see `Structure of files Terrafom for google cloud`_
+
+ 5 Type the commands :
+
+
+.. code-block:: none
+
+ cd /<your folder>
+ terraform init
+
+
+Ansible
+
+
+ 1 Create an UNIX instance whenever you want (local, cloud, and so on)
+
+ 2 Download and install Ansible
+
+ 3 Create the folder for example /root/google/
+
+ 4 Copy all files into your Ansible project "/root/google/" (ansible.cfg, instance.yml, mykey.json and "all"), more detailed see `Structure of files Ansible for google cloud`_
+
+mykey.json you have to get using step 2 of the google cloud
+
+
+Start
+
+
+Type the commands on your Terrafom instance:
+
+.. code-block:: none
+
+ cd /<your folder>
+ terraform plan
+ terraform apply
+ yes
+
+
+Start creating a google cloud instance and check the result
+-----------------------------------------------------------
+
+.. code-block:: none
+
+ # terraform apply
+
+ Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ + create
+
+ Terraform will perform the following actions:
+
+ # google_compute_firewall.tcp_22[0] will be created
+ + resource "google_compute_firewall" "tcp_22" {
+ + creation_timestamp = (known after apply)
+ + destination_ranges = (known after apply)
+ + direction = (known after apply)
+ + enable_logging = (known after apply)
+ + id = (known after apply)
+ + name = "vyos-tcp-22"
+ + network = "default"
+ + priority = 1000
+ + project = "vyosproject"
+ + self_link = (known after apply)
+ + source_ranges = [
+ + "0.0.0.0/0",
+ ]
+ + target_tags = [
+ + "vyos-deployment",
+ ]
+
+ + allow {
+ + ports = [
+ + "22",
+ ]
+ + protocol = "tcp"
+ }
+ }
+
+ # google_compute_firewall.udp_500_4500[0] will be created
+ + resource "google_compute_firewall" "udp_500_4500" {
+ + creation_timestamp = (known after apply)
+ + destination_ranges = (known after apply)
+ + direction = (known after apply)
+ + enable_logging = (known after apply)
+ + id = (known after apply)
+ + name = "vyos-udp-500-4500"
+ + network = "default"
+ + priority = 1000
+ + project = "vyosproject"
+ + self_link = (known after apply)
+ + source_ranges = [
+ + "0.0.0.0/0",
+ ]
+ + target_tags = [
+ + "vyos-deployment",
+ ]
+
+ + allow {
+ + ports = [
+ + "500",
+ + "4500",
+ ]
+ + protocol = "udp"
+ }
+ }
+
+ # google_compute_instance.default will be created
+ + resource "google_compute_instance" "default" {
+ + can_ip_forward = true
+ + cpu_platform = (known after apply)
+ + current_status = (known after apply)
+ + deletion_protection = false
+ + effective_labels = (known after apply)
+ + guest_accelerator = (known after apply)
+ + id = (known after apply)
+ + instance_id = (known after apply)
+ + label_fingerprint = (known after apply)
+ + machine_type = "n2-highcpu-4"
+ + metadata = {
+ + "enable-oslogin" = "FALSE"
+ + "serial-port-enable" = "TRUE"
+ + "user-data" = ""
+ }
+ + metadata_fingerprint = (known after apply)
+ + min_cpu_platform = (known after apply)
+ + name = "vyos"
+ + project = "vyosproject"
+ + self_link = (known after apply)
+ + tags_fingerprint = (known after apply)
+ + terraform_labels = (known after apply)
+ + zone = "us-west1-a"
+
+ + boot_disk {
+ + auto_delete = true
+ + device_name = (known after apply)
+ + disk_encryption_key_sha256 = (known after apply)
+ + kms_key_self_link = (known after apply)
+ + mode = "READ_WRITE"
+ + source = (known after apply)
+
+ + initialize_params {
+ + image = "projects/sentrium-public/global/images/vyos-1-3-5-20231222143039"
+ + labels = (known after apply)
+ + provisioned_iops = (known after apply)
+ + provisioned_throughput = (known after apply)
+ + size = (known after apply)
+ + type = (known after apply)
+ }
+ }
+
+ + network_interface {
+ + internal_ipv6_prefix_length = (known after apply)
+ + ipv6_access_type = (known after apply)
+ + ipv6_address = (known after apply)
+ + name = (known after apply)
+ + network = "default"
+ + network_ip = (known after apply)
+ + nic_type = "GVNIC"
+ + stack_type = (known after apply)
+ + subnetwork = "default"
+ + subnetwork_project = (known after apply)
+
+ + access_config {
+ + nat_ip = (known after apply)
+ + network_tier = (known after apply)
+ }
+ }
+ }
+
+ # local_file.ip will be created
+ + resource "local_file" "ip" {
+ + content = (known after apply)
+ + content_base64sha256 = (known after apply)
+ + content_base64sha512 = (known after apply)
+ + content_md5 = (known after apply)
+ + content_sha1 = (known after apply)
+ + content_sha256 = (known after apply)
+ + content_sha512 = (known after apply)
+ + directory_permission = "0777"
+ + file_permission = "0777"
+ + filename = "ip.txt"
+ + id = (known after apply)
+ }
+
+ # null_resource.SSHconnection1 will be created
+ + resource "null_resource" "SSHconnection1" {
+ + id = (known after apply)
+ }
+
+ # null_resource.SSHconnection2 will be created
+ + resource "null_resource" "SSHconnection2" {
+ + id = (known after apply)
+ }
+
+ Plan: 6 to add, 0 to change, 0 to destroy.
+
+ Changes to Outputs:
+ + public_ip_address = (known after apply)
+ ╷
+ │ Warning: Quoted references are deprecated
+ │
+ │ on vyos.tf line 126, in resource "null_resource" "SSHconnection1":
+ │ 126: depends_on = ["google_compute_instance.default"]
+ │
+ │ In this context, references are expected literally rather than in quotes. Terraform 0.11 and earlier required quotes, but quoted references are now deprecated and will be removed in a
+ │ future version of Terraform. Remove the quotes surrounding this reference to silence this warning.
+ │
+ │ (and one more similar warning elsewhere)
+ ╵
+
+ Do you want to perform these actions?
+ Terraform will perform the actions described above.
+ Only 'yes' will be accepted to approve.
+
+ Enter a value: yes
+
+ google_compute_firewall.udp_500_4500[0]: Creating...
+ google_compute_firewall.tcp_22[0]: Creating...
+ google_compute_instance.default: Creating...
+ google_compute_firewall.udp_500_4500[0]: Still creating... [10s elapsed]
+ google_compute_firewall.tcp_22[0]: Still creating... [10s elapsed]
+ google_compute_instance.default: Still creating... [10s elapsed]
+ google_compute_firewall.tcp_22[0]: Creation complete after 16s [id=projects/vyosproject/global/firewalls/vyos-tcp-22]
+ google_compute_firewall.udp_500_4500[0]: Creation complete after 16s [id=projects/vyosproject/global/firewalls/vyos-udp-500-4500]
+ google_compute_instance.default: Creation complete after 20s [id=projects/vyosproject/zones/us-west1-a/instances/vyos]
+ null_resource.SSHconnection1: Creating...
+ null_resource.SSHconnection2: Creating...
+ null_resource.SSHconnection1: Provisioning with 'file'...
+ null_resource.SSHconnection2: Provisioning with 'remote-exec'...
+ null_resource.SSHconnection2 (remote-exec): Connecting to remote host via SSH...
+ null_resource.SSHconnection2 (remote-exec): Host: 10.***.***.104
+ null_resource.SSHconnection2 (remote-exec): User: root
+ null_resource.SSHconnection2 (remote-exec): Password: true
+ null_resource.SSHconnection2 (remote-exec): Private key: false
+ null_resource.SSHconnection2 (remote-exec): Certificate: false
+ null_resource.SSHconnection2 (remote-exec): SSH Agent: false
+ null_resource.SSHconnection2 (remote-exec): Checking Host Key: false
+ null_resource.SSHconnection2 (remote-exec): Target Platform: unix
+ local_file.ip: Creating...
+ local_file.ip: Creation complete after 0s [id=7d568c3b994a018c942a3cdb952ccbf3c729d0ca]
+ null_resource.SSHconnection2 (remote-exec): Connected!
+ null_resource.SSHconnection1: Creation complete after 4s [id=5175298735911137161]
+
+ null_resource.SSHconnection2 (remote-exec): PLAY [integration of terraform and ansible] ************************************
+
+ null_resource.SSHconnection2 (remote-exec): TASK [Wait 300 seconds, but only start checking after 60 seconds] **************
+ null_resource.SSHconnection2: Still creating... [10s elapsed]
+ null_resource.SSHconnection2: Still creating... [20s elapsed]
+ null_resource.SSHconnection2: Still creating... [30s elapsed]
+ null_resource.SSHconnection2: Still creating... [40s elapsed]
+ null_resource.SSHconnection2: Still creating... [50s elapsed]
+ null_resource.SSHconnection2: Still creating... [1m0s elapsed]
+ null_resource.SSHconnection2: Still creating... [1m10s elapsed]
+ null_resource.SSHconnection2 (remote-exec): ok: [104.***.***.158]
+
+ null_resource.SSHconnection2 (remote-exec): TASK [Configure general settings for the vyos hosts group] *********************
+ null_resource.SSHconnection2: Still creating... [1m20s elapsed]
+ null_resource.SSHconnection2 (remote-exec): changed: [104.***.***.158]
+
+ null_resource.SSHconnection2 (remote-exec): PLAY RECAP *********************************************************************
+ null_resource.SSHconnection2 (remote-exec): 104.***.***.158 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
+
+ null_resource.SSHconnection2: Creation complete after 1m22s [id=3355727070503709742]
+
+ Apply complete! Resources: 6 added, 0 changed, 0 destroyed.
+
+ Outputs:
+
+ public_ip_address = "104.***.***.158"
+
+
+
+After executing all the commands you will have your VyOS instance on the google cloud with your configuration, it's a very convenient desition.
+If you need to delete the instance please type the command:
+
+.. code-block:: none
+
+ terraform destroy
+
+
+Troubleshooting
+---------------
+
+ 1 Increase the time in the file instance.yml from 300 sec to 500 sec or more. (It depends on your location).
+Make sure that you have opened access to the instance in the security group.
+
+ 2 Terraform doesn't connect via SSH to your Ansible instance: you have to check the correct login and password in the part of the file VyOS.tf
+
+.. code-block:: none
+
+ connection {
+ type = "ssh"
+ user = "root" # open root access using login and password on your Ansible
+ password = var.password # check password in the file terraform.tfvars isn't empty
+ host = var.host # check the correct IP address of your Ansible host
+ }
+
+
+Make sure that Ansible is pinging from Terrafom.
+
+Structure of files Terrafom for google cloud
+--------------------------------------------
+
+.. code-block:: none
+
+ .
+ ├── vyos.tf # The main script
+ ├── ***.JSON # The credential file from google cloud
+ ├── var.tf # The file of all variables in "vyos.tf"
+ └── terraform.tfvars # The value of all variables (passwords, login, ip adresses and so on)
+
+
+
+File contents of Terrafom for google cloud
+------------------------------------------
+
+vyos.tf
+
+.. code-block:: none
+
+
+ ##############################################################################
+ # Build an VyOS VM from the Marketplace
+ #
+ # After deploying the GCP instance and getting an IP address, the IP address is copied into the file
+ #"ip.txt" and copied to the Ansible node for provisioning.
+ ##############################################################################
+
+ terraform {
+ required_providers {
+ google = {
+ source = "hashicorp/google"
+ }
+ }
+ }
+
+ provider "google" {
+ project = var.project_id
+ request_timeout = "60s"
+ credentials = file(var.gcp_auth_file)
+ }
+
+ locals {
+ network_interfaces = [for i, n in var.networks : {
+ network = n,
+ subnetwork = length(var.sub_networks) > i ? element(var.sub_networks, i) : null
+ external_ip = length(var.external_ips) > i ? element(var.external_ips, i) : "NONE"
+ }
+ ]
+ }
+
+ resource "google_compute_instance" "default" {
+ name = var.goog_cm_deployment_name
+ machine_type = var.machine_type
+ zone = var.zone
+
+ metadata = {
+ enable-oslogin = "FALSE"
+ serial-port-enable = "TRUE"
+ user-data = var.vyos_user_data
+ }
+ boot_disk {
+ initialize_params {
+ image = var.image
+ }
+ }
+
+ can_ip_forward = true
+
+ dynamic "network_interface" {
+ for_each = local.network_interfaces
+ content {
+ network = network_interface.value.network
+ subnetwork = network_interface.value.subnetwork
+ nic_type = "GVNIC"
+ dynamic "access_config" {
+ for_each = network_interface.value.external_ip == "NONE" ? [] : [1]
+ content {
+ nat_ip = network_interface.value.external_ip == "EPHEMERAL" ? null : network_interface.value.external_ip
+ }
+ }
+ }
+ }
+ }
+
+ resource "google_compute_firewall" "tcp_22" {
+ count = var.enable_tcp_22 ? 1 : 0
+
+ name = "${var.goog_cm_deployment_name}-tcp-22"
+ network = element(var.networks, 0)
+
+ allow {
+ ports = ["22"]
+ protocol = "tcp"
+ }
+
+ source_ranges = ["0.0.0.0/0"]
+
+ target_tags = ["${var.goog_cm_deployment_name}-deployment"]
+ }
+
+ resource "google_compute_firewall" "udp_500_4500" {
+ count = var.enable_udp_500_4500 ? 1 : 0
+
+ name = "${var.goog_cm_deployment_name}-udp-500-4500"
+ network = element(var.networks, 0)
+
+ allow {
+ ports = ["500", "4500"]
+ protocol = "udp"
+ }
+
+ source_ranges = ["0.0.0.0/0"]
+
+ target_tags = ["${var.goog_cm_deployment_name}-deployment"]
+ }
+
+ output "public_ip_address" {
+ value = google_compute_instance.default.network_interface[0].access_config[0].nat_ip
+ }
+
+ ##############################################################################
+ #
+ # IP of google instance copied to a file ip.txt in local system Terraform
+ # ip.txt looks like:
+ # cat ./ip.txt
+ # ххх.ххх.ххх.ххх
+ ##############################################################################
+
+ resource "local_file" "ip" {
+ content = google_compute_instance.default.network_interface[0].access_config[0].nat_ip
+ filename = "ip.txt"
+ }
+
+ #connecting to the Ansible control node using SSH connection
+
+ ##############################################################################
+ # Steps "SSHconnection1" and "SSHconnection2" need to get file ip.txt from the terraform node and start remotely the playbook of Ansible.
+ ##############################################################################
+
+ resource "null_resource" "SSHconnection1" {
+ depends_on = ["google_compute_instance.default"]
+ connection {
+ type = "ssh"
+ user = "root"
+ password = var.password
+ host = var.host
+ }
+
+ #copying the ip.txt file to the Ansible control node from local system
+
+ provisioner "file" {
+ source = "ip.txt"
+ destination = "/root/google/ip.txt" # The folder of your Ansible project
+ }
+ }
+
+ resource "null_resource" "SSHconnection2" {
+ depends_on = ["google_compute_instance.default"]
+ connection {
+ type = "ssh"
+ user = "root"
+ password = var.password
+ host = var.host
+ }
+
+ #command to run Ansible playbook on remote Linux OS
+
+ provisioner "remote-exec" {
+ inline = [
+ "cd /root/google/",
+ "ansible-playbook instance.yml" # more detailed in "File contents of Ansible for google cloud"
+ ]
+ }
+ }
+
+
+var.tf
+
+.. code-block:: none
+
+ variable "image" {
+ type = string
+ default = "projects/sentrium-public/global/images/vyos-1-3-5-20231222143039"
+ }
+
+ variable "project_id" {
+ type = string
+ }
+
+ variable "zone" {
+ type = string
+ }
+
+ ##############################################################################
+ # You can choose more chipper type than n2-highcpu-4
+ ##############################################################################
+
+ variable "machine_type" {
+ type = string
+ default = "n2-highcpu-4"
+ }
+
+ variable "networks" {
+ description = "The network name to attach the VM instance."
+ type = list(string)
+ default = ["default"]
+ }
+
+ variable "sub_networks" {
+ description = "The sub network name to attach the VM instance."
+ type = list(string)
+ default = ["default"]
+ }
+
+ variable "external_ips" {
+ description = "The external IPs assigned to the VM for public access."
+ type = list(string)
+ default = ["EPHEMERAL"]
+ }
+
+ variable "enable_tcp_22" {
+ description = "Allow SSH traffic from the Internet"
+ type = bool
+ default = true
+ }
+
+ variable "enable_udp_500_4500" {
+ description = "Allow IKE/IPSec traffic from the Internet"
+ type = bool
+ default = true
+ }
+
+ variable "vyos_user_data" {
+ type = string
+ default = ""
+ }
+
+ // Marketplace requires this variable name to be declared
+ variable "goog_cm_deployment_name" {
+ description = "VyOS Universal Router Deployment"
+ type = string
+ default = "vyos"
+ }
+
+ # GCP authentication file
+ variable "gcp_auth_file" {
+ type = string
+ description = "GCP authentication file"
+ }
+
+ variable "password" {
+ description = "pass for Ansible"
+ type = string
+ sensitive = true
+ }
+ variable "host"{
+ description = "The IP of my Ansible"
+ type = string
+ }
+
+
+terraform.tfvars
+
+.. code-block:: none
+
+ ##############################################################################
+ # Must be filled in
+ ##############################################################################
+
+ zone = "us-west1-a"
+ gcp_auth_file = "/root/***/***.json" # path of your .json file
+ project_id = "" # the google project
+ password = "" # password for Ansible SSH
+ host = "" # IP of my Ansible
+
+
+Structure of files Ansible for google cloud
+-------------------------------------------
+
+.. code-block:: none
+
+ .
+ ├── group_vars
+ └── all
+ ├── ansible.cfg
+ └── instance.yml
+
+
+File contents of Ansible for google cloud
+-----------------------------------------
+
+ansible.cfg
+
+.. code-block:: none
+
+ [defaults]
+ inventory = /root/google/ip.txt
+ host_key_checking= False
+ remote_user=vyos
+
+instance.yml
+
+.. code-block:: none
+
+ ##############################################################################
+ # About tasks:
+ # "Wait 300 seconds, but only start checking after 60 seconds" - try to make ssh connection every 60 seconds until 300 seconds
+ # "Configure general settings for the VyOS hosts group" - make provisioning into google cloud VyOS node
+ # You have to add all necessary cammans of VyOS under the block "lines:"
+ ##############################################################################
+
+
+ - name: integration of terraform and ansible
+ hosts: all
+ gather_facts: 'no'
+
+ tasks:
+
+ - name: "Wait 300 seconds, but only start checking after 60 seconds"
+ wait_for_connection:
+ delay: 60
+ timeout: 300
+
+ - name: "Configure general settings for the VyOS hosts group"
+ vyos_config:
+ lines:
+ - set system name-server xxx.xxx.xxx.xxx
+ save:
+ true
+
+
+group_vars/all
+
+.. code-block:: none
+
+ ansible_connection: ansible.netcommon.network_cli
+ ansible_network_os: vyos.vyos.vyos
+ ansible_user: vyos
+ ansible_ssh_pass: vyos
+
+Sourse files for google cloud from GIT
+--------------------------------------
+
+All files about the article can be found here_
+
+
+.. _here: https://github.com/vyos/vyos-automation/tree/main/TerraformCloud/Google_terraform_ansible_single_vyos_instance-main \ No newline at end of file
diff --git a/docs/automation/terraform/terraformvSphere.rst b/docs/automation/terraform/terraformvSphere.rst
new file mode 100644
index 00000000..5d39261b
--- /dev/null
+++ b/docs/automation/terraform/terraformvSphere.rst
@@ -0,0 +1,400 @@
+:lastproofread: 2024-03-03
+
+.. _terraformvSphere:
+
+Deploying VyOS in the vSphere infrastructure
+============================================
+
+With the help of Terraform, you can quickly deploy VyOS-based infrastructure in the vSphere.
+Also we will make provisioning using Ansible.
+
+In this case, we'll create the necessary files for Terraform and Ansible next using Terraform we'll create a single instance on the vSphere cloud and make provisioning using Ansible.
+
+Preparation steps for deploying VyOS on vSphere
+-----------------------------------------------
+
+How to create a single instance and install your configuration using Terraform+Ansible+vSphere
+Step by step:
+
+
+vSphere
+
+
+ 1 Collect all data in to file "terraform.tfvars" and create resources for example "terraform"
+
+
+Terraform
+
+
+ 1 Create an UNIX or Windows instance
+
+ 2 Download and install Terraform
+
+ 3 Create the folder for example /root/vsphereterraform
+
+.. code-block:: none
+
+ mkdir /root/vsphereterraform
+
+
+ 4 Copy all files into your Terraform project "/root/vsphereterraform" (vyos.tf, var.tf, terraform.tfvars,version.tf), more detailed see `Structure of files Terrafom for vSphere`_
+
+ 5 Type the commands :
+
+.. code-block:: none
+
+ cd /<your folder>
+ terraform init
+
+
+Ansible
+
+
+ 1 Create an UNIX instance whenever you want (local, cloud, and so on)
+
+ 2 Download and install Ansible
+
+ 3 Create the folder for example /root/vsphereterraform/
+
+ 4 Copy all files into your Ansible project "/root/vsphereterraform/" (ansible.cfg, instance.yml,"all"), more detailed see `Structure of files Ansible for vSphere`_
+
+
+Start
+
+
+Type the commands on your Terrafom instance:
+
+.. code-block:: none
+
+ cd /<your folder>
+ terraform plan
+ terraform apply
+ yes
+
+
+After executing all the commands you will have your VyOS instance on the vSphere with your configuration, it's a very convenient desition.
+If you need to delete the instance please type the command:
+
+.. code-block:: none
+
+ terraform destroy
+
+
+Structure of files Terrafom for vSphere
+---------------------------------------
+
+.. code-block:: none
+
+ .
+ ├── vyos.tf # The main script
+ ├── versions.tf # File for the changing version of Terraform.
+ ├── var.tf # File for the changing version of Terraform.
+ └── terraform.tfvars # The value of all variables (passwords, login, ip adresses and so on)
+
+
+File contents of Terrafom for vSphere
+-------------------------------------
+
+vyos.tf
+
+.. code-block:: none
+
+ provider "vsphere" {
+ user = var.vsphere_user
+ password = var.vsphere_password
+ vsphere_server = var.vsphere_server
+ allow_unverified_ssl = true
+ }
+
+ data "vsphere_datacenter" "datacenter" {
+ name = var.datacenter
+ }
+
+ data "vsphere_datastore" "datastore" {
+ name = var.datastore
+ datacenter_id = data.vsphere_datacenter.datacenter.id
+ }
+
+ data "vsphere_compute_cluster" "cluster" {
+ name = var.cluster
+ datacenter_id = data.vsphere_datacenter.datacenter.id
+ }
+
+ data "vsphere_resource_pool" "default" {
+ name = format("%s%s", data.vsphere_compute_cluster.cluster.name, "/Resources/terraform") # set as you need
+ datacenter_id = data.vsphere_datacenter.datacenter.id
+ }
+
+ data "vsphere_host" "host" {
+ name = var.host
+ datacenter_id = data.vsphere_datacenter.datacenter.id
+ }
+
+ data "vsphere_network" "network" {
+ name = var.network_name
+ datacenter_id = data.vsphere_datacenter.datacenter.id
+ }
+
+ # Deployment of VM from Remote OVF
+ resource "vsphere_virtual_machine" "vmFromRemoteOvf" {
+ name = var.remotename
+ datacenter_id = data.vsphere_datacenter.datacenter.id
+ datastore_id = data.vsphere_datastore.datastore.id
+ host_system_id = data.vsphere_host.host.id
+ resource_pool_id = data.vsphere_resource_pool.default.id
+ network_interface {
+ network_id = data.vsphere_network.network.id
+ }
+ wait_for_guest_net_timeout = 2
+ wait_for_guest_ip_timeout = 2
+
+ ovf_deploy {
+ allow_unverified_ssl_cert = true
+ remote_ovf_url = var.url_ova
+ disk_provisioning = "thin"
+ ip_protocol = "IPv4"
+ ip_allocation_policy = "dhcpPolicy"
+ ovf_network_map = {
+ "Network 1" = data.vsphere_network.network.id
+ "Network 2" = data.vsphere_network.network.id
+ }
+ }
+ vapp {
+ properties = {
+ "password" = "12345678",
+ "local-hostname" = "terraform_vyos"
+ }
+ }
+ }
+
+ output "ip" {
+ description = "default ip address of the deployed VM"
+ value = vsphere_virtual_machine.vmFromRemoteOvf.default_ip_address
+ }
+
+ # IP of vSphere instance copied to a file ip.txt in local system
+
+ resource "local_file" "ip" {
+ content = vsphere_virtual_machine.vmFromRemoteOvf.default_ip_address
+ filename = "ip.txt"
+ }
+
+ #Connecting to the Ansible control node using SSH connection
+
+ resource "null_resource" "nullremote1" {
+ depends_on = ["vsphere_virtual_machine.vmFromRemoteOvf"]
+ connection {
+ type = "ssh"
+ user = "root"
+ password = var.ansiblepassword
+ host = var.ansiblehost
+
+ }
+
+ # Copying the ip.txt file to the Ansible control node from local system
+
+ provisioner "file" {
+ source = "ip.txt"
+ destination = "/root/vsphere/ip.txt"
+ }
+ }
+
+ resource "null_resource" "nullremote2" {
+ depends_on = ["vsphere_virtual_machine.vmFromRemoteOvf"]
+ connection {
+ type = "ssh"
+ user = "root"
+ password = var.ansiblepassword
+ host = var.ansiblehost
+ }
+
+ # Command to run ansible playbook on remote Linux OS
+
+ provisioner "remote-exec" {
+
+ inline = [
+ "cd /root/vsphere/",
+ "ansible-playbook instance.yml"
+ ]
+ }
+ }
+
+
+versions.tf
+
+.. code-block:: none
+
+ # Copyright (c) HashiCorp, Inc.
+ # SPDX-License-Identifier: MPL-2.0
+
+ terraform {
+ required_providers {
+ vsphere = {
+ source = "hashicorp/vsphere"
+ version = "2.4.0"
+ }
+ }
+ }
+
+var.tf
+
+.. code-block:: none
+
+ # Copyright (c) HashiCorp, Inc.
+ # SPDX-License-Identifier: MPL-2.0
+
+ variable "vsphere_server" {
+ description = "vSphere server"
+ type = string
+ }
+
+ variable "vsphere_user" {
+ description = "vSphere username"
+ type = string
+ }
+
+ variable "vsphere_password" {
+ description = "vSphere password"
+ type = string
+ sensitive = true
+ }
+
+ variable "datacenter" {
+ description = "vSphere data center"
+ type = string
+ }
+
+ variable "cluster" {
+ description = "vSphere cluster"
+ type = string
+ }
+
+ variable "datastore" {
+ description = "vSphere datastore"
+ type = string
+ }
+
+ variable "network_name" {
+ description = "vSphere network name"
+ type = string
+ }
+
+ variable "host" {
+ description = "name if yor host"
+ type = string
+ }
+
+ variable "remotename" {
+ description = "the name of you VM"
+ type = string
+ }
+
+ variable "url_ova" {
+ description = "the URL to .OVA file or cloude store"
+ type = string
+ }
+
+ variable "ansiblepassword" {
+ description = "Ansible password"
+ type = string
+ }
+
+ variable "ansiblehost" {
+ description = "Ansible host name or IP"
+ type = string
+ }
+
+terraform.tfvars
+
+.. code-block:: none
+
+ vsphere_user = ""
+ vsphere_password = ""
+ vsphere_server = ""
+ datacenter = ""
+ datastore = ""
+ cluster = ""
+ network_name = ""
+ host = ""
+ url_ova = ""
+ ansiblepassword = ""
+ ansiblehost = ""
+ remotename = ""
+
+
+Structure of files Ansible for vSphere
+--------------------------------------
+
+.. code-block:: none
+
+ .
+ ├── group_vars
+ └── all
+ ├── ansible.cfg
+ └── instance.yml
+
+
+File contents of Ansible for vSphere
+------------------------------------
+
+ansible.cfg
+
+.. code-block:: none
+
+ [defaults]
+ inventory = /root/vsphere/ip.txt
+ host_key_checking= False
+ remote_user=vyos
+
+
+instance.yml
+
+.. code-block:: none
+
+ ##############################################################################
+ # About tasks:
+ # "Wait 300 seconds, but only start checking after 60 seconds" - try to make ssh connection every 60 seconds until 300 seconds
+ # "Configure general settings for the VyOS hosts group" - make provisioning into vSphere VyOS node
+ # You have to add all necessary cammans of VyOS under the block "lines:"
+ ##############################################################################
+
+
+ - name: integration of terraform and ansible
+ hosts: all
+ gather_facts: 'no'
+
+ tasks:
+
+ - name: "Wait 300 seconds, but only start checking after 60 seconds"
+ wait_for_connection:
+ delay: 60
+ timeout: 300
+
+ - name: "Configure general settings for the VyOS hosts group"
+ vyos_config:
+ lines:
+ - set system name-server 8.8.8.8
+ save:
+ true
+
+
+group_vars/all
+
+.. code-block:: none
+
+ ansible_connection: ansible.netcommon.network_cli
+ ansible_network_os: vyos.vyos.vyos
+
+ # user and password gets from terraform variables "admin_username" and "admin_password"
+ ansible_user: vyos
+ # get from vyos.tf "vapp"
+ ansible_ssh_pass: 12345678
+
+
+Sourse files for vSphere from GIT
+---------------------------------
+
+All files about the article can be found here_
+
+.. _here: https://github.com/vyos/vyos-automation/tree/main/TerraformCloud/Vsphere_terraform_ansible_single_vyos_instance-main
+
diff --git a/docs/automation/terraform/terraformvyos.rst b/docs/automation/terraform/terraformvyos.rst
new file mode 100644
index 00000000..42dc7492
--- /dev/null
+++ b/docs/automation/terraform/terraformvyos.rst
@@ -0,0 +1,39 @@
+:lastproofread: 2024-03-03
+
+.. _terraformvyos:
+
+Terraform for VyOS
+==================
+
+VyOS supports development infrastructure via Terraform and provisioning via Ansible.
+Terraform allows you to automate the process of deploying instances on many cloud and virtual platforms.
+In this article, we will look at using terraforms to deploy VyOS on platforms - AWS, Azure, and vSphere.
+For more details about Terraform please have a look here link_.
+
+Need to install_ Terraform
+
+Structure of files in the standard Terraform project:
+
+.. code-block:: none
+
+ .
+ ├── main.tf # The main script
+ ├── version.tf # File for the changing version of Terraform.
+ ├── variables.tf # The file of all variables in "main.tf"
+ └── terraform.tfvars # The value of all variables (passwords, login, ip adresses and so on)
+
+
+General commands that we will use for running Terraform scripts
+
+
+.. code-block:: none
+
+ cd /<your folder> # go to the Terrafom project
+ terraform init # install all addons and provider (aws az and so on)
+ terraform plan # show what is changing
+ terraform apply # run script
+ yes # apply running
+
+
+.. _link: https://developer.hashicorp.com/terraform/intro
+.. _install: https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli \ No newline at end of file
diff --git a/docs/automation/vyos-api.rst b/docs/automation/vyos-api.rst
index 8fad05ca..60247fae 100644
--- a/docs/automation/vyos-api.rst
+++ b/docs/automation/vyos-api.rst
@@ -125,6 +125,38 @@ For example, get the addresses of a ``dum0`` interface.
"error": null
}
+To check existence of a configuration path, use the ``exists`` operation.
+
+For example, check an existing path:
+
+.. code-block:: none
+
+ curl -k --location --request POST 'https://vyos/retrieve' \
+ --form data='{"op": "exists", "path": ["service","https","api"]}' \
+ --form key='MY-HTTPS-API-PLAINTEXT-KEY'
+
+ response:
+ {
+ "success": true,
+ "data": true,
+ "error": null
+ }
+
+versus a non-existent path:
+
+.. code-block:: none
+
+ curl -k --location --request POST 'https://vyos/retrieve' \
+ --form data='{"op": "exists", "path": ["service","non","existent","path"]}' \
+ --form key='MY-HTTPS-API-PLAINTEXT-KEY'
+
+ response:
+ {
+ "success": true,
+ "data": false,
+ "error": null
+ }
+
/reset
======