Terraform is a declarative command-line utility used to manage the infrastructure of Terraform partner providers. With this tool, you can manage our Cloud service.
To work with Terraform, you create a configuration file where you specify the changes you want to make to your Cloud resources, for example, to create a Virtual Machine or a Managed Kubernetes cluster. Then you run the Terraform command to make changes. The utility reads the configuration file and sends the necessary API requests. The required Cloud settings are then applied.
1. Download a Terraform package suitable for your OS from the official Terraform website.
2. Create a new folder and name it the same as the downloaded package.
3. Unzip the Terraform archive in the new folder.
4. Add the directory of the unzipped Terraform archive to the PATH environment variable.
5. Create a configuration file in the Terraform folder and name it main.tf.
6. Find out the latest version of the Terraform provider on the page and generate a permanent API token using the guide, if you don’t have one yet.
7. Add the following code to main.tf:
Enter your values instead:
8. Open the command line, access the Terraform folder and run the following command:
terraform init
You’ll get the output:
This means Terraform has been successfully downloaded and installed, and you can start working with it.
If you have already worked with Terraform, you can use this abridged guide on how to manage Gcore Cloud resources:
1. Go to the Terraform documentation, click Resources, and copy the necessary code to main.tf.
2. Customize values in the code.
3. Run the following command to preview the expected changes:
terraform plan
4. Run the following command to apply these changes:
terraform apply
You can also use our step-by-step guides below.
1. Open the main.tf file where you configured the Gcore provider for Terraform.
2. Copy the code below to the file and customize the highlighted values:
3. Configure your Bare Metal server.
Specify "flavor_id".
Configure “interface”.
Select the interface "type": "external", "subnet", "any_subnet", or "reserved_fixed_ip".
(optional) Add is_parent = "true" to ensure the interface cannot be detached and is always connected first.
(optional) Specify "order" to set the order in which interfaces will be attached.
(optional) Specify "app_config" to set parameters for the application template from the marketplace.
(optional) Specify the "image_id" or "apptemplate_id".
(optional) Specify the "keypair_name".
(optional) Specify the "name" of the server.
(optional) Specify the "region_id" and "region_name".
(optional) Specify the "project_id" and "project_name".
(optional) Specify the "metadata_map": "key" and "value".
(optional) Specify "username" and/or "password".
4. Save changes in the file.
5. Run the following command from the Terraform directory to preview the changes:
terraform plan
If the code contains an error, the output will show it.
6. Run the following command to apply the changes:
terraform apply
Terraform will ask you to confirm the action. Enter "yes".
1. Open the main.tf file where you configured the Gcore provider for Terraform.
2. Copy the code to the file and customize the highlighted values:
3. Configure resources required for the Virtual Machine: a reserved IP address, network, subnetwork, volume.
4. Configure the Virtual Machine.
Specify "flavor_id".
Select the interface "type": "external", "subnet", "any_subnet", or "reserved_fixed_ip".
Configure "volume".
(optional) Add "allow_app_ports = true" to allow application ports for Virtual Machines created from marketplace templates.
(optional) Specify "configuration" to set parameters for the application template from the marketplace: "key" and "value".
(optional) Specify the "keypair_name".
(optional) Specify the "metadata_map": "key" and "value".
(optional) Specify the "name" of the Virtual Machine.
(optional) Specify "username" and "password".
(optional) Specify the "region_id" and "region_name".
(optional) Specify the "project_id" and "project_name".
(optional) Specify the "security_group" to add firewalls.
5. Save changes in the file.
6. Run the following command from the Terraform directory to preview the expected changes:
terraform plan
If the code contains an error, the output will describe it.
7. Run the following command to apply the changes:
terraform apply
Terraform will ask you to confirm the action. Enter "yes".
1. Open the main.tf file where you configured the Gcore provider for Terraform.
2. Copy the code below to the file and customize the highlighted values:
3. Configure the cluster.
Specify “name”.
Specify the “fixed_network” of the cluster.
Specify the “fixed_subnet” and make sure the subnet has a router.
Specify the “keypair”.
(optional) Specify the “region_id” and “region_name”.
(optional) Specify the “project_id” and “project_name”.
(optional) Add auto_healing_enabled = "true"
to allow automatic recovery of failed nodes.
(optional) Add external_dns_enabled = "true"
if you want to enable external DNS.
Configure the pool, a set of cluster nodes with the same specifications.
4. Save changes in the file.
5. Run the following command from the Terraform directory to preview the expected changes:
terraform plan
If the code contains an error, the output will show it.
6. Run the following command to apply the changes:
terraform apply
Terraform will ask you to confirm the action. Enter “yes”.
1. Open the main.tf file where you configured the Gcore provider for Terraform.
2. Copy the code below to the file and customize the highlighted values:
3. Configure the pool.
Specify the “cluster_id” within which you want to create the pool.
Specify the “name” of your pool.
Specify “flavor_id”.
Specify the “min_node_count” for autoscaling.
Specify the “max_node_count” for autoscaling.
Specify the “node_count”. This is the initial number of nodes to be deployed.
(optional) Specify the “docker_volume_size” in GB.
(optional) Select “docker_volume_type”: “standard”, “ssd_hiiops”, “cold”, or “ultra”.
(optional) Specify the “region_id” and “region_name”.
(optional) Specify the “project_id” and “project_name”.
4. Save changes in the file.
5. Run the following command from the Terraform directory to preview the expected changes:
terraform plan
If the code contains an error, the output will show it.
6. Run the following command to apply the changes:
terraform apply
Terraform will ask you to confirm the action. Enter “yes”.
This section explains how to create a Load Balancer with a pool, listener, and member.
1. Open the main.tf file where you configured the Gcore provider for Terraform.
2. Copy the code below to the file and customize the highlighted values:
3. Configure the Load Balancer.
Specify the “name” of your Load Balancer.
Specify “flavor”.
(optional) Specify the “region_id” and “region_name”.
(optional) Specify the “project_id” and “project_name”.
(optional) Specify the “vip_port_id” or “vip_network_id”.
(optional) Specify the “vip_subnet_id”.
4. Configure the listener.
Specify “name”.
Select “protocol”: “HTTP”, “HTTPS”, “TCP”, “UDP”, or “TERMINATED_HTTPS”. If you select “TERMINATED_HTTPS”, specify the “secret_id”.
Specify the “protocol_port”.
Specify the “loadbalancer_id”.
(optional) Add insert_x_forward = "true"
to identify an original IP address of a client connecting to a web server via a load
(optional) Specify the “region_id” and “region_name”.
(optional) Specify the “project_id” and “project_name”.
5. Configure the pool.
Specify “name”.
Select “protocol”: “HTTP”, “HTTPS”, “TCP”, or “UDP”.
Select “lb_algorithm”: “ROUND_ROBIN”, “LEAST_CONNECTIONS”, or “SOURCE_IP”.
(optional) Add “health_monitor”.
(optional) Specify the “listener_id”.
(optional) Specify the “loadbalancer_id”.
(optional) Specify the “region_id” and “region_name”.
(optional) Specify the “project_id” and “project_name”.
(optional) Add “session_persistence”.
6. Configure the member.
Specify the IP “address”.
Specify the “pool_id”.
Specify the “protocol_port”.
Specify the “instance_id” or “subnet_id”.
(optional) Specify member “weight” from 0 to 256.
7. Save changes in the file.
8. Run the following command from the Terraform directory to preview the expected changes:
terraform plan
If the code contains an error, the output will show it.
9. Run the following command to apply the changes:
terraform apply
Terraform will ask you to confirm the action. Enter “yes”.
1. Open the main.tf file where you configured the Gcore provider for Terraform.
2. Copy the code below to the file and customize the highlighted values:
3. Configure the network.
Specify “name”.
(optional) Add create_router = "false"
to remove the external router from the network. Otherwise, the external router will be added by default.
(optional) Add type = "vlan"
. Otherwise, a “vxlan” network will be created by default.
(optional) Specify the “region_id” and “region_name”.
(optional) Specify the “project_id” and “project_name”.
4. If you don’t need a subnetwork, skip to Step 6. To create a subnetwork, add the code below and customize the highlighted values:
5. Configure the subnetwork.
Specify the “name” of the subnetwork.
Specify the “cidr”.
Specify the “network_id” within which you want to create the subnet.
(optional) Add connect_to_network_router = "true"
if you want your subnetwork to be accessible for public networks through an external router. If not, add connect_to_network_router = "false"
. The default value is “true”.
(optional) Add the “gateway_ip” of an external router, if any.
(optional) Specify “dns_nameservers”.
(optional) Add “host_routes”.
(optional) Add “enable_dhcp = false” to disable DHCP. Otherwise, DHCP will be enabled by default. For IPv6 networks, you can only enable or disable DHCP when creating a subnetwork. Changing this setting later is only possible via recreating the IPv6 subnetwork.
(optional) Specify the “region_id” and “region_name”.
(optional) Specify the “project_id” and “project_name”.
6. Save changes in the file.
7. Run the following command from the Terraform directory to preview the expected changes:
terraform plan
If the code contains an error, the output will show it.
8. Run the following command to apply the changes:
terraform apply
Terraform will ask you to confirm the action. Enter “yes”.
1. Open the main.tf file where you configured the Gcore provider for Terraform.
2. Copy the code below to the file and customize the highlighted values:
3. Configure the server group.
Specify “name”.
Select the policy: use "affinity"
to run your servers on one physical server or "anti-affinity" to run your servers on different physical servers.
(optional) Specify the “region_id” and “region_name”.
(optional) Specify the “project_id” and “project_name”.
4. Save changes in the file.
5. Run the following command from the Terraform directory to preview the expected changes:
terraform plan
If the code contains an error, the output will show it.
6. Run the following command to apply the changes:
terraform apply
Terraform will ask you to confirm the action. Enter “yes”.
1. Open the main.tf file where you configured the Gcore provider for Terraform.
2. Copy the code below to the file and customize the highlighted values:
3. Configure the snapshot.
Specify “name”.
Specify the “volume_id”.
(optional) Add a “description”.
(optional) Specify the “region_id” and “region_name”.
(optional) Specify the “project_id” and “project_name”.
4. Save changes in the file.
5. Run the following command from the Terraform directory to preview the expected changes:
terraform plan
If the code contains an error, the output will describe it.
6. Run the following command to apply the changes:
terraform apply
Terraform will ask you to confirm the action. Enter “yes”.
1. Open the main.tf file where you configured the Gcore provider for Terraform.
2. Copy the code below to the file and customize:
3. Configure the volume.
Specify “name”.
Specify the “snapshot_id” or “image_id”.
(optional) Specify the “size” of your volume in GB.
(optional) Select the “type_name”: “standard”, “ssd_hiiops”, “cold”, or “ultra”.
(optional) Specify the “region_id” and “region_name”.
(optional) Specify the “project_id” and “project_name”.
4. Save changes in the file.
5. Run the following command from the Terraform directory to preview the expected changes:
terraform plan
If the code contains an error, the output will show it.
6. Run the following command to apply the changes:
terraform apply
Terraform will ask you to confirm the action. Enter “yes”.
1. Open the main.tf file where you configured the Gcore provider for Terraform.
2. Copy the code below to the file and customize the highlighted values:
3. Configure the reserved IP address.
Specify the “type": “subnet”, “any_subnet”, “external”, or “ip_address”.
Specify if you want to use the reserved IP address as a virtual IP (VIP) address (“is_vip = true”) or not (“is_vip = false”). For more details, refer to this article: Create and configure a virtual IP address.
(optional) Add “allowe_access_pairs” to assign one VIP to multiple machines. Specify the “ip_address” and “mac_address”.
(optional) Specify the “network_id” and/or “subnet_id” to attach the IP address to a specific network or subnetwork.
(optional) Specify the “region_id” and “region_name”.
(optional) Specify the “project_id” and “project_name”.
4. Save changes in the file.
5. Run the following command from the Terraform directory to preview the expected changes:
terraform plan
If the code contains an error, the output will describe it.
6. Run the following command to apply the changes:
terraform apply
Terraform will ask you to confirm the action. Enter “yes”.
Was this article helpful?
Discover our offerings, including virtual instances starting from 3.7 euro/mo, bare metal servers, AI Infrastructure, load balancers, Managed Kubernetes, Function as a Service, and Centralized Logging solutions.