About the integration
With the Latitude.sh Terraform provider you can:- Create and update projects
- Create and update servers
- Create and update SSH keys
- Use data sources and outputs to retrieve data.
Getting started
1
Install Terraform CLI
Install the Terraform CLI. This guide explains how to do this for your operating system.
2
Create API token
Create a Latitude.sh API token.
Here is how to create an
API token.
3
Export API token
Export the API token as a variable
Example integration
We will start by creating a project, getting theid
of the project we just created, then adding our ssh key to that project, and finally creating a server that deploys to our new project and uses the SSH key we just added.
1
Create project directory
Create a directory for your Terraform project.
2
Create main.tf
Create a file named
main.tf
with the following content:3
Initialize project
Run the following command in your terminal to Initialize the project.You should see a success message after initializing the project that will contain something like this:
Terraform has been successfully initialized! You may now begin working with Terraform. Try running “terraform plan” to see
any changes that are required for your infrastructure. All Terraform commands
should now work. If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
4
Create configuration files
Now we are finally ready to start creating infrastructure with Terraform. While you can add your codified resources to Create the following filesOptional if you have an SSH key in hand. If not, remove the
main.tf
, as your infrastructure grows, it gets hard and dangerous to manage things from a single file, so it is usually best to split your files from the beginning.Create a file named variables.tf
with the following content. This is optional but useful for this guide.variables.tf
outputs.tf
project.tf
server.tf
ssh_keys
from server.tf
and the ssh section from variables.tf
and ignore the next file.ssh_key.tf
Run the plan
Now that we have all our files organized and referenced, we can create the infrastructure defined in them. Let’s start by reviewing the changes that will be made.1
Review the plan
Run this on your terminal:If you decide to use an SSH key, Terraform will ask for your public SSH key. Terraform will list every action it will take after we apply our plan. Review to make sure everything is how you want it to be.
2
Apply the plan
Apply the plan:Paste your public SSH key again when requested and type yes on the prompt.