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
- macOS
- Linux
The fastest way to install on Windows is with Chocolatey. Run the following from an elevated PowerShell session:Verify the installation:Expected output:If Chocolatey is not available, download the binary manually:
- Open developer.hashicorp.com/terraform/install.
- Under Windows, select AMD64 and click Download.
- Extract the ZIP archive to a permanent folder, for example
C:\tools\terraform\. - Add that folder to the PATH:
- Open Start and search for Edit the system environment variables.
- Click Environment Variables.
- Under User variables, select Path and click Edit.
- Click New and paste the path
C:\tools\terraform\. - Click OK to save.
- Open a new PowerShell window and run
terraform versionto verify.
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 An 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
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:
- Windows
- macOS
- Linux
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.
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.