Volumes
resource "hcloud_server" "helloServer" { server_type = "cx22" ... } resource "hcloud_volume" "volume01" { name = "volume1" size = 10 server_id = hcloud_server.helloServer.id automount = true format = "xfs" } |
df ... /mnt/HC_Volume_100723816 |
output "volume_id" { value=hcloud_volume.volume01.id description = "The volume's id" } |
# ls /dev/disk/by-id/*100723816 /dev/disk/by-id/scsi-0HC_Volume_100723816 |
terraform apply
...
hello_ip_addr="37.27.22.189"
volume_id="100723816" |
Desired
/dev/disk/by-id/scsi-0HC_Volume_100723816
/volume01 xfs discard,nofail,defaults 0 0 |
No. 15
Auto mounting a volume
Q: |
Follow Figure 1036, “A volume: The easy way ” adding an a auto mounted volume to an existing server. TipDue to a Cloud-init implementation quirk consider the auto mount workaround hint. |
resource "hcloud_server" "helloServer" { ... user_data = templatefile("tpl/userData.yml", { ... volume01Id = hcloud_volume.volume01.id }) } resource "hcloud_volume" "volume01" { server_id = hcloud_server.helloServer.id ... } |
Problem: Cyclic dependency helloServer <--> volume01 |
main.tf |
userData.yml.tpl |
---|---|
resource "hcloud_volume" "vol01" { size = 10 .... } resource "hcloud_server" "hello" { user_data = templatefile( "userData.yml.tpl", { # No cycle volId=hcloud_volume.vol01.id }) ... } resource "hcloud_volume_attachment" "main" { volume_id=hcloud_volume.vol01.id server_id=hcloud_server.hello.id } |
echo `/bin/ls /dev/disk/by-id/*${volId}` /vol01 xfs discard,nofail,defaults 0 0 >> /etc/fstab |
No. 16
Mount point's name specification
Q: |
In Auto mounting a volume the mount
point's name had been auto generated by
Cloud-init. Modify your setup and
define
|