Setting up a Project
Add the Katapult Provider to a new Terraform Project
We can begin setting up a new Terraform project by creating a new directory and adding a main.tf
file to it. This file will contain the configuration for our project.
mkdir my-terraform-project
cd my-terraform-project
touch main.tf
Next, we need to add the Katapult provider to our project. We can do this by adding the following code to our main.tf
file:
terraform {
required_providers {
katapult = {
source = "krystal/katapult"
version = "~> 0.0"
}
}
}
provider "katapult" {
api_key = var.api_key
organization = var.organization
data_center = var.data_center
}
Manage Variables
You can pass these variables to Terraform in a number of ways, such as using environment variables, a .tfvars
file, or by passing them directly to the terraform
command.
What Variables do I need?
You will need the following variables to use the Katapult provider:
api_key
- Your Katapult API keyorganization
- Your Katapult organization Subdomain.data_center
- The Permalink of the data center you want to use.
These are the available data center permalinks:
uk-lon-01
- London, United Kingdomnl-ams-01
- Amsterdam, Netherlandsus-nyc-01
- New York City, United States of Americaus-azp-01
- Phoenix, United States of America
Pass Variables to Terraform
- Using a .tfvars file
- Using Environment Variables
- Passing Variables Directly
Using a .tfvars
file.
Create a file, for example variables.tfvars
, and define your variables in it:api_key = "your-api-key"
organization = "your-organization"
data_center = "your-data-center"
Then, you can pass the variables to Terraform using the -var-file
flag:
terraform apply -var-file=variables.tfvars
Using Environment Variables
The Katapult provider will check for the following environment variables:
KATAPULT_API_KEY
KATAPULT_DATA_CENTER
KATAPULT_ORGANIZATION
You can set these variables in your shell or in a .env
file. For example, you can create a .env
file with the following content:
KATAPULT_API_KEY="your-api-key"
KATAPULT_ORGANIZATION="your-organization"
KATAPULT_DATA_CENTER="your-data-center"
Terraform will also automatically look for environment variables with the TF_VAR_
prefix.
Matching the variable names in your .tf
file. For example, you can set environment variables with the names matching your variables:
export TF_VAR_api_key="your-api-key"
export TF_VAR_organization="your-organization"
export TF_VAR_data_center="your-data-center"
Passing Variables Directly
You can pass variables directly to theterraform
command using the -var
flag:terraform apply -var="api_key=your-api-key" -var="organization=your-organization" -var="data_center=your-data-center"
Remember to replace "your-api-key"
, "your-organization"
, and "your-data-center"
with your actual values.
Initialize the Project
Now that we have our provider and variables set up, we can initialize our project by running the following command:
terraform init
This command will download the Katapult provider and any other dependencies required for our project.