T O P

Need help with user_data..

Need help with user_data..

stabguy13

Looks like it's getting base64 encoded. The documentation for hcloud_server doesn't mention whether it expects base64. Also, the templatefile data source is deprecated. Use the function. [templatefile](https://www.terraform.io/docs/language/functions/templatefile.html)


TemporaryFigure

I know, but if I do it like this: ​ resource "hcloud_server" "fileshare" { name = "hcloud-server-fileshare" image = var.os_type server_type = var.server_type location = var.location ssh_keys = [hcloud_ssh_key.default.id] backups = true keep_disk = true user_data = file("user_data.yml") labels = { type = "hcloud" } } This is the plan output: # hcloud_server.fileshare will be created + resource "hcloud_server" "fileshare" { + backup_window = (known after apply) + backups = true + datacenter = (known after apply) + delete_protection = false + firewall_ids = (known after apply) + id = (known after apply) + image = "ubuntu-20.04" + ipv4_address = (known after apply) + ipv6_address = (known after apply) + ipv6_network = (known after apply) + keep_disk = true + labels = { + "type" = "hcloud" } + location = "nbg1" + name = "hcloud-server-fileshare" + rebuild_protection = false + server_type = "cpx31" + ssh_keys = (known after apply) + status = (known after apply) + user_data = "an7n7pEwaZ2gW6YOV7WgFQWnQ8E=" } ​ .... Not even a single error


stabguy13

Both hash values appear to match (I'm not at a computer to confirm). Have you tried decoding them? Also, what is the exact error you are seeing?


TemporaryFigure

But i'm not supposed to see a has right? Im supposed to see the output of the file


TemporaryFigure

Ok sir forgive me for my stupidity.. appearantly there is something wrong with my original cloud\_init file. I tested a minimal touch file version and that worked.. Sorry to bother you, thanks for thinking along. Have a good weekend!


stabguy13

No worries! Take care!


aayo-gorkhali

Use template function instead: resource "aws_instance" "${ResourceName}" { ami = "${AMIID}" instance_type = "${InstanceType}" subnet_id = "${Subnets}" vpc_security_group_ids = ["${SecurityGroups}"] key_name = "${KeyPairName}" user_data = templatefile("./scripts/userdata/${userdata}", { myhost = "${ResourceName}" challenge = var.challenge )}