Terraform is an infrastructure as code tool that lets you build, change, and version infrastructure. This includes low-level components like compute instances, storage, and networking; and high-level components. OpenTofu is a fork of Terraform that is open-source, community-driven, and managed by the Linux Foundation. Installation of the CLITerraformIn order to start using Terraform it is necessary to install its client. There are several ways to install it also depending on the local platform where it needs to be installed, these can be consulted in the Terraform documentation. One convenient way to install the client can be also via conda :
OpenTofuIn order to start using OpenTofu it is necessary to install its client. There are several ways to install it also depending on the local platform where it needs to be installed, these can be consulted in the OpenTofu documentation. One convenient way to install the client can be also via conda :
Get StartedPre-requisites
Write configuration filesThe set of files used to describe infrastructure in Terraform is known as a Terraform configuration. Each Terraform configuration must be in its own working directory. Create a directory for your configuration and change directory into it:
Create the main configuration file to define the infrastructure:
Open the
where the explanation of the blocks is: Terraform BlockThe ProvidersThe For more information about the Terraform Openstack provider it is possible to consult the terraform-provider-openstack documentation . ResourcesThe More information can be found in the Terraform documentation. Run Terraform or OpenTofuCloud AuthenticationIn order to run Terraform is required to have the Openstack application credentials .
Each file can be used in alternative to the other. openrc fileIf using the openrc file it is enough to source it, e.g. :
and this will export the required environment variables:
in this case the provider block in the terraform can be kept as:
since the required information are taken from the environment variables. clouds.yamlIf using the clouds.yaml file, this need to be be installed under : In this case the provider block in the terraform need to be modified in this way to specify the cloud :
TerraformInitialize and apply terraform configurationThe first step once created the terraform configuration files is to initialize the directory :
Once initialized it is possible to see any changes that are required for your infrastructure by running :
Finally the actual infrastructure can be created by running:
The status can be then seen via:
Destroy the infrastructureThe created infrastructure can be easily destroyed by running:
OpenTofuInitialize and apply OpenTofu configurationThe first step once created the terraform configuration files is to initialize the directory :
Once initialized it is possible to see any changes that are required for your infrastructure by running :
Finally the actual infrastructure can be created by running:
The status can be then seen via:
Destroy the infrastructureThe created infrastructure can be easily destroyed by running:
References |