Introduction
Assuming that you already know about Terraform, this article covers specifically how to get started with Terraform for ZEDEDA. For further details about our Terraform implementation, see ZEDEDA Terraform Provider.
Prerequisites
- Depending on which objects the terraform config will manage, the corresponding token has to be created by a user who has CRUD permissions on those specific objects.
Use the ZEDEDA Cloud Terraform Provider
- Install Terraform on your local system.
- Create a directory for your Terraform files. For example:
mkdir terraform-docker-container
- Navigate to the directory for your Terraform files. For example:
cd terraform-docker-container
- In your directory, create a file called main.tf, otherwise known as the plan. For example:
touch main.tf
- In the terraform plan file, specify the desired version of the provider:
terraform { required_providers { zedcloud = { source = "zededa/zedcloud" version = "2.2.7" } } }
- Continue to add the rest of the resources that you want to deploy to ZEDEDA Cloud. See a terraform provider ZEDEDA Cloud main.tf example.
- Provide values for the following ENV variables:
export TF_VAR_zedcloud_url="zedcontrol.zededa.net" export TF_VAR_zedcloud_token=
- Initialize the project:
terraform init
- Provision the project:
terraform apply
Most Common Terraform Commands
The following commands are likely the ones you’ll use most frequently.
-
terraform init
Initializes a working directory containing Terraform configuration files. This command downloads necessary providers, modules, and sets up the backend. -
terraform plan
Creates an execution plan by comparing the current state with the configuration files. It shows what actions Terraform will take without making any changes. -
terraform apply
Applies the changes required to reach the desired state of the configuration. This command creates, updates, or deletes resources as defined by your plan. -
terraform destroy
Removes all resources managed by the Terraform configuration. It’s useful for cleaning up environments you no longer need. -
terraform validate
Checks the syntax and configuration of your Terraform files for any errors, ensuring they are valid before attempting to apply them. -
terraform fmt
Formats your Terraform code in the standard style. It helps maintain a consistent code layout across your configuration files. -
terraform state
A set of subcommands to inspect and modify the Terraform state. For example:
terraform state list: Lists all resources in the state file.
terraform state show <resource>: Displays detailed information about a specific resource. -
terraform import
Brings existing infrastructure resources into Terraform management by associating them with a resource defined in your configuration. -
terraform output
Displays the values of output variables from your Terraform state. This is especially useful for getting connection strings, IP addresses, and other outputs after applying your configuration.
Next Steps
This is a series of articles. You will likely follow them in this order.
- Terraform Quickstart - You are here!
- ZEDEDA Terraform Provider
- Renaming ZEDEDA Terraform objects
- Terraform for Edge Node Clusters: A Use Case