Terraform replaces manual steps in the Gcore Customer Portal with repeatable configuration files, allowing the same configuration to provision identical infrastructure every time. Getting started requires only a Gcore account, an API token, and a terminal — no prior Terraform experience required.Documentation Index
Fetch the complete documentation index at: https://gcore.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Step 1. Install Terraform
Terraform is a command-line tool for Windows, macOS, and Linux. After installation, all interaction happens through a terminal window — there is no application to launch. The fastest way to install Terraform is through a package manager; if one is not available, download the binary manually from the tabs below.- Windows (Chocolatey)
- Windows (manual)
- macOS (Homebrew)
- Linux (apt)
Chocolatey is a free package manager for Windows. If Chocolatey is already installed, run the following from an elevated PowerShell session:Verify the installation:Expected output:If Chocolatey is not installed, use the manual binary method below.
Step 2. Create a project directory
Each Terraform project lives in its own directory. Terraform stores the infrastructure state per directory, so different projects must stay in separate folders. Create a new directory and navigate into it:Step 3. Get a Gcore API token
The Gcore provider v2 authenticates with a permanent API token. To generate one:- Open the Customer Portal and go to Profile > API Tokens.
- Click Create API token.
- Set an expiration date and assign the required permissions.
- Copy the token — it is shown only once.
Step 4. Configure the Gcore provider
Create a file namedmain.tf in the project directory. This file declares which provider Terraform should use and how to authenticate.
YOUR_API_KEY with the token copied in Step 3.
Provider block fields
| Field | Purpose |
|---|---|
required_version | Minimum Terraform CLI version this configuration requires. |
required_providers | Declares external providers Terraform must download. |
source = "G-Core/gcore" | Registry address of the Gcore provider (namespace/name). |
version | Provider version constraint. The = prefix pins to an exact release — required for pre-release versions since ~> does not apply to them. |
provider "gcore" | Configures the provider instance — here, the API key for authentication. |
Use an exact version pin (
=) for pre-release versions, as the ~> constraint does not apply to them. Check Terraform Registry for the current version number.Keep the API key out of source files
Hardcoding credentials in.tf files is a security risk. Use an environment variable instead:
- PowerShell
- Bash / Zsh
GCORE_API_KEY is set, remove the api_key line from the provider block:
.terraform/ and *.tfstate to .gitignore when working with version control to avoid committing provider binaries and state files that may contain sensitive data.
Step 5. Initialize the provider
Runterraform init from the project directory. This command downloads the Gcore provider plugin from Terraform Registry and prepares the working directory.
| Item | Purpose |
|---|---|
.terraform/ | Contains the downloaded provider binary. Not committed to version control. |
.terraform.lock.hcl | Records the exact provider version installed. Commit this file to lock the version for the whole team. |
Step 6. Add a resource or data source
A resource creates or manages infrastructure — a virtual machine, a network, a DNS record. A data source reads existing infrastructure without changing it. The following example reads an existing Gcore project by name — a safe first step that queries the API without touching any infrastructure:main.tf after the provider block.
The output block at the bottom prints the result after terraform apply. It references the data source as data.gcore_cloud_project.default.id — gcore_cloud_project is the type, default is the local name from the block above, and id is the attribute to read.
Step 7. Preview changes
Runterraform plan to see what Terraform intends to do. No changes are applied at this step — it is safe to run at any time.
+ prefix marks a new output value being recorded — the project ID will be saved to state on apply.
Step 8. Apply the configuration
Runterraform apply to execute the plan. Terraform prints the same summary as plan, asks for confirmation, then applies:
Terraform state
Afterterraform apply, a terraform.tfstate file appears in the project directory. This is the state file — Terraform’s record of what resources it manages and their current attributes.
On each subsequent terraform apply, Terraform compares the desired state described in .tf files against the recorded state and applies only the difference, so running the same configuration multiple times always produces the same result.