project_id and region_id fields directly in each resource instead of data source lookups. Existing v0 configurations can be migrated to v2. Provider installation and authentication are covered in the Terraform overview.
Workflow
Add resource configuration tomain.tf, then run:
yes when prompted. The full attribute reference for each resource is on the Terraform Registry.
SSH keys
An SSH key is required to access Linux instances and Bare Metal servers.ssh-keygen -t ed25519, then paste the .pub file contents into public_key. To share the key with all users in the project, set shared_in_project = true.
Security groups
Security groups control inbound and outbound traffic to instances. Each group contains rules added as separate resources.directionacceptsingress(inbound) oregress(outbound).ethertypeacceptsIPv4orIPv6.protocolacceptstcp,udp,icmp,icmpv6,ospf,vrrp, orany. To allow all protocols, omitprotocol,port_range_min, andport_range_max.port_range_minandport_range_maxdefine the port range. Set both to the same value to allow a single port.group_idreferences the parent security group.
interfaces or the top-level security_groups block.
Networking
The following resources configure private networks, subnets, and IP addresses.Network and subnet
The following configuration creates a private network and a subnet within it.type accepts vxlan (default) or vlan. Bare Metal servers require vlan. To add static routes, add host_routes blocks with destination (CIDR) and nexthop (IP).
Reserved fixed IP
A reserved fixed IP persists independently of instances and can be reattached to a new resource after it is destroyed.type accepts:
| Value | Description |
|---|---|
external | Public IP from the default external network |
subnet | IP from a specific subnet — also specify network_id and subnet_id |
any_subnet | IP from any subnet of a network — also specify network_id |
ip_address | Specific IP address — also specify network_id, subnet_id, ip_address |
port | Wrap an existing port — also specify port_id |
is_vip = true to use the IP as a Virtual IP shared between multiple instances.
Floating IP
A floating IP provides a stable public address that can be moved between resources.port_id and fixed_ip_address to allocate an unattached floating IP for later use.
Volumes
The following configuration creates a boot volume from an image.source accepts image, snapshot, or new-volume. When using snapshot, type_name defaults to the source snapshot’s volume type. type_name accepts: standard, ssd_hiiops, ssd_local, ssd_lowlatency, cold, ultra.
To create a standalone data volume (not from an image):
Virtual Machines
The following examples create Virtual Machine instances with different network configurations.Instance with a public interface
The following configuration creates an instance with a public IPv4 interface.type accepts external, subnet, any_subnet, or reserved_fixed_ip. For subnet, also specify network_id and subnet_id. For reserved_fixed_ip, specify port_id. ip_family accepts ipv4, ipv6, or dual.
Key optional fields on gcore_cloud_instance:
| Field | Description |
|---|---|
security_groups | List of security group IDs applied to all interfaces |
user_data | base64-encoded cloud-init script |
username / password_wo | Create a user at boot (Linux); set Admin password (Windows) |
vm_state | active to start, stopped to keep the instance off |
tags | Map of key-value labels |
Instance with two interfaces
The following configuration attaches a public interface and a private subnet interface to an instance.interfaces array accepts multiple entries. The order determines attachment order on the instance. Each entry requires type; additional fields depend on the type:
external— public interface. Specifyip_family:ipv4,ipv6, ordual.subnet— private subnet interface. Specifynetwork_idandsubnet_id.any_subnet— picks any subnet in the network. Specifynetwork_id.reserved_fixed_ip— attaches a pre-reserved IP. Specifyport_id.
Instance with floating IP
This configuration attaches a reserved IP with a floating IP to the instance.floating_ip.source = "new" and omit existing_floating_id.
Windows instance
The following configuration creates a Windows Server instance with a public interface.password_wo requires Terraform 1.11 or later (write-only argument). Increment password_wo_version to change the password after the instance is created. Use user_data with a base64-encoded PowerShell script to add additional users.
Bare Metal servers
The following examples provision Bare Metal servers with different interface configurations.Server with a public interface
The following configuration provisions a Bare Metal server with a public IPv4 interface.- Specify
flavor— the Bare Metal flavor ID. Available flavors are region-specific; check the Portal or API for the target region. - Specify
image_id— the Bare Metal image ID. Use the Images API or the Portal to look up available images for the target region. - Specify
ssh_key_name— the name of an SSH key resource in the same project. - Configure
interfaces. Interfacetypeacceptsexternal,subnet,any_subnet, orreserved_fixed_ip. Forsubnet, also specifynetwork_idandsubnet_id.ip_familyacceptsipv4,ipv6, ordual. - (optional) Specify
name. - (optional) Specify
region_idorregion_name. - (optional) Specify
project_idorproject_name. - (optional) Specify
app_configto set parameters for a marketplace application template. - (optional) Specify
metadataas a map of key-value labels.
Server with two interfaces
Private networks for Bare Metal requiretype = "vlan" on the network resource. The configuration below attaches both a public interface and a private VLAN interface to the server.
interfaces array to attach additional networks. Interface order determines attachment order on the server.
Windows Bare Metal server
The following configuration provisions a Bare Metal server running Windows Server.type for Bare Metal accepts the same values as for instances: external, subnet, any_subnet, reserved_fixed_ip. Use port_group to group interfaces into trunks on servers that support bonding.
Load Balancers
A load balancer consists of a balancer resource, one or more listeners, and one or more pools. The following configuration creates a TCP load balancer with a health monitor and a backend member.protocol accepts HTTP, HTTPS, TCP, UDP, TERMINATED_HTTPS, or PROMETHEUS. For TERMINATED_HTTPS, specify secret_id with the ID of a PKCS12 certificate stored in Secrets Manager.
Pool lb_algorithm accepts ROUND_ROBIN, LEAST_CONNECTIONS, or SOURCE_IP. Pool members are identified by either subnet_id (IP-based routing) or instance_id (instance-aware routing).
Health monitor type accepts HTTP, HTTPS, PING, TCP, TLS-HELLO, UDP-CONNECT, or K8S.
To add a floating IP to the load balancer VIP:
gcore_cloud_reserved_fixed_ip first and reference it with vip_port_id on the load balancer.
Kubernetes clusters
The following examples create managed Kubernetes clusters with different network configurations.Cluster in a private network
The following configuration creates a Kubernetes cluster with a private network and a single node pool.| Field | Description |
|---|---|
flavor_id | Flavor for worker nodes |
servergroup_policy | Placement policy: affinity, anti-affinity, soft-anti-affinity |
min_node_count / max_node_count | Autoscaler range. Set both equal to disable autoscaling |
boot_volume_type | standard, ssd_hiiops, cold, or ultra |
is_public_ipv4 | Assign public IPv4 to each node (default: false) |
auto_healing_enabled | Automatically replace unhealthy nodes |
Cluster with Cilium CNI
This configuration uses Cilium with Direct Server Return (DSR) mode, which preserves the client’s source IP — useful for logging, security, and latency-sensitive workloads.cni.cloud_k8s_cluster_provider accepts calico (default) or cilium. Cilium lb_mode accepts snat, dsr, or hybrid. routing_mode accepts tunnel (default) or native.