forked from UpCloudLtd/terraform-provider-upcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.tf
110 lines (89 loc) · 2.2 KB
/
server.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# set the provider version
terraform {
required_providers {
upcloud = {
source = "UpCloudLtd/upcloud"
version = "~> 2.0"
}
}
}
provider "upcloud" {
# Your UpCloud credentials are read from the environment variables:
# export UPCLOUD_USERNAME="Username of your UpCloud API user"
# export UPCLOUD_PASSWORD="Password of your UpCloud API user"
}
# create a server
resource "upcloud_server" "ubuntu" {
hostname = "ubuntu.example.tld"
zone = "de-fra1"
firewall = false
# choose a simple plan
plan = "1xCPU-1GB"
# use flexible plan:
# cpu = "2"
# mem = "1024"
# add a public IP address
network_interface {
type = "public"
}
# add the utility network
network_interface {
type = "utility"
}
template {
storage = "Ubuntu Server 20.04 LTS (Focal Fossa)"
# use size allotted by the 1xCPU-1GB plan:
size = 25
# UUID also works:
# storage = "01000000-0000-4000-8000-000030200200"
backup_rule {
interval = "daily"
time = "0100"
retention = 8
}
}
# attach an extra storage device (configured below)
storage_devices {
storage = upcloud_storage.datastorage.id
# defaults if not specified:
# address = "virtio"
# type = "disk"
}
# login details
login {
# create a new sudo user called "terraform"
user = "terraform"
keys = [
"<YOUR PUBLIC SSH KEY HERE>",
]
# create a password (set to false if using SSH key only)
create_password = true
# remove password_delivery if using SSH key only
password_delivery = "sms"
}
# Allow terraform to connect to the server
connection {
# the server public IP address
host = self.network_interface[0].ip_address
type = "ssh"
# the user created above
user = "terraform"
private_key = "<PATH TO YOUR PRIVATE SSH KEY>"
}
}
# create a storage for data
resource "upcloud_storage" "datastorage" {
title = "/data"
size = 10
# zone needs to match server's zone:
zone = "de-fra1"
tier = "maxiops"
# backup_rule {
# interval = "daily"
# time = "0100"
# retention = 8
# }
}
output "Public_ip" {
value = upcloud_server.ubuntu.network_interface[0].ip_address
}