A round trip
# Define Hetzner cloud provider
terraform {
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
}
}
required_version = ">= 0.13"
}
# Configure the Hetzner Cloud API token
provider "hcloud" {
token = "your_api_token_goes_here"
}
# Create a server
resource "hcloud_server" "helloServer" {
name = "hello"
image = "debian-13"
server_type = "cx23"
}$ terraform init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hetznercloud/hcloud...
- Installing hetznercloud/hcloud v1.46.1...
- Installed hetznercloud/hcloud v1.46.1 (signed by a HashiCorp partner, key ID 5219EACB3A77198B)
...
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. ...$ terraform plan
Terraform used the selected providers to generate the following execution plan. Resource actions ...
+ create
Terraform will perform the following actions:
# hcloud_server.helloServer will be created
+ resource "hcloud_server" "helloServer" {
+ allow_deprecated_images = false
+ backup_window = (known after apply)
...
}
Plan: 1 to add, 0 to change, 0 to destroy.terraform apply ... Plan: 1 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes hcloud_server.helloServer: Creating... hcloud_server.helloServer: Still creating... [10s elapsed] hcloud_server.helloServer: Creation complete after 14s [id=45822789] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
| Resource list | Selected resource's properties |
|---|---|
$ terraform state list hcloud_server.helloServer |
$ terraform state show hcloud_server.helloServer resource "hcloud_server" "helloServer" { firewall_ids = [] id = "166290307" image = "debian-13" ipv4_address = "2.29.10.236" ipv6_address = "2a01:4f9:c015:5ae7::1" ipv6_network = "2a01:4f9:c015:5ae7::/64" location = "hel1" name = "hello" primary_disk_size = 40 server_type = "cx23" status = "running" ... } |
