{"id":13702487,"url":"https://github.com/wszychta/terraform-module.hcloud-user-data","last_synced_at":"2025-05-05T04:31:04.603Z","repository":{"id":41370657,"uuid":"357633612","full_name":"wszychta/terraform-module.hcloud-user-data","owner":"wszychta","description":"The purpose of this module is to provide ready to use user-data file for Hetzner cloud servers with multiple network managers.","archived":false,"fork":false,"pushed_at":"2023-02-01T20:41:12.000Z","size":42,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-13T09:40:57.712Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wszychta.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-13T17:18:45.000Z","updated_at":"2024-10-05T10:23:30.000Z","dependencies_parsed_at":"2023-02-17T10:15:29.804Z","dependency_job_id":null,"html_url":"https://github.com/wszychta/terraform-module.hcloud-user-data","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wszychta%2Fterraform-module.hcloud-user-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wszychta%2Fterraform-module.hcloud-user-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wszychta%2Fterraform-module.hcloud-user-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wszychta%2Fterraform-module.hcloud-user-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wszychta","download_url":"https://codeload.github.com/wszychta/terraform-module.hcloud-user-data/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252439524,"owners_count":21748023,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T21:00:36.422Z","updated_at":"2025-05-05T04:31:04.308Z","avatar_url":"https://github.com/wszychta.png","language":"HCL","funding_links":[],"categories":["Libraries"],"sub_categories":["HCL"],"readme":"# terraform-module.hcloud-user-data\n## Description\n\u003cb\u003eThe purpose of this module is to provide ready to use user-data file for Hetzner cloud servers with multiple network managers.\u003c/b\u003e\n\nAll actions taken to create user-data file are based on [Hetzner server configuration documentation](https://docs.hetzner.com/cloud/networks/server-configuration/), [Hetzner static ip documentation](https://docs.hetzner.com/cloud/servers/static-configuration/), [cloud-init documentation](https://cloudinit.readthedocs.io/en/latest/) and my own experience/experiments.\n\n## Supported features\n- Generating private networks configuration for instance after initial boot ( only dhcp - no support for static interface configuration ). This module use three different ways of managing networks\n  - `interfaces.d` config file - for images:\n    - `debian-10`\n    - `debian-11`\n  - `Netplan` config file - for images:\n    - `ubuntu-20.04`\n    - `ubuntu-22.04`\n  - `NetworkManager keyfile` script - for images:\n    - `fedora-36`\n    - `fedora-37`\n    - `centos-stream-8`\n    - `centos-stream-9`\n    - `rocky-8`\n    - `rocky-9`\n- Adding additional users with ssh keys and `sudo` configuration\n- Writing additional entries in `/etc/hosts` file\n- Writing additional files on instance (ex. cron jobs)\n- Running additional shell commands on initial boot (ex. docker instalation)\n- Adding additional packages to VM\n- Setting instance Timezone\n- Upgrading all packages\n- Rebooting after finishing all cloud-init tasks\n\n### Working Features for each image\n\n| System image    | Routing Configuration | DNS ip addresses | DNS search domains | `/etc/hosts` file writing | Creating additional users | Writing additional Files | Running additional commands | Upgrading packages | Rebooting instance |\n|:---------------:|:---------------------:|:----------------:|:------------------:|:-------------------------:|:-------------------------:|:------------------------:|:---------------------------:|:------------------:|:------------------:|\n| Ubuntu 20.04    | Yes                   | Yes              | Yes                | Yes                       | Yes                       | Yes                      | Yes                         | Yes                | Yes                |\n| Ubuntu 22.04    | Yes                   | Yes              | Yes                | Yes                       | Yes                       | Yes                      | Yes                         | Yes                | Yes                |\n| Debian 10       | Yes                   | Yes              | Yes                | Yes                       | Yes                       | Yes                      | Yes                         | Yes                | Yes                |\n| Debian 11       | Yes                   | Yes              | Yes                | Yes                       | Yes                       | Yes                      | Yes                         | Yes                | Yes                |\n| Fedora 36       | Yes                   | Yes              | Yes                | Yes                       | Yes                       | Yes                      | Yes                         | Yes                | Yes                |\n| Fedora 37       | Yes                   | Yes              | Yes                | Yes                       | Yes                       | Yes                      | Yes                         | Yes                | Yes                |\n| Centos Stream 8 | Yes                   | Yes              | Yes                | Yes                       | Yes                       | Yes                      | Yes                         | Yes                | Yes                |\n| Centos Stream 9 | Yes                   | Yes              | Yes                | Yes                       | Yes                       | Yes                      | Yes                         | Yes                | Yes                |\n| Rocky 8         | Yes                   | Yes              | Yes                | Yes                       | Yes                       | Yes                      | Yes                         | Yes                | Yes                |\n| Rocky 9         | Yes                   | Yes              | Yes                | Yes                       | Yes                       | Yes                      | Yes                         | Yes                | Yes                |\n\nPlease take a look at [Known Issues](https://github.com/wszychta/terraform-module.hcloud-user-data/tree/initial_commit#known-issues) section to read why some of the features are not working on described images.\n\n## Tested vms configuration\n\nI have tested this module on below instances types:\n- CX11\n- CPX11\n\n\u003cb\u003eThis module should also work on the rest of standard machines with Local SSD based on avaliable documentation.\u003c/b\u003e\n\nThis module will not work on:\n- Dedicated instances (CCXxx)\n\n## Usage example\n\nExample for Debian/Ubuntu with few packages installation:\n```terraform\nmodule \"cloud_config_file\" {\n  source            = \"git::git@github.com:wszychta/terraform-module.hcloud-user-data?ref=tags/2.2.0\"\n  server_type       = \"cpx11\"\n  server_image      = \"ubuntu-20.04\"\n  additional_users  = [\n    {\n      username = \"local\"\n      sudo_options = \"ALL=(ALL) NOPASSWD:ALL\"\n      ssh_public_keys = [\n        \"ssh-rsa ...................\"\n      ]\n    }\n  ]\n  additional_hosts_entries = [\n    {\n      ip = \"192.168.0.4\"\n      hostnames = [\n        \"host1.lab.net\",\n        \"host1\"\n      ]\n    },\n    {\n      ip = \"192.168.0.5\"\n      hostnames = [\n        \"host2.lab.net\",\n        \"host2\"\n      ]\n    },\n  ]\n  private_networks_settings = [\n    {\n      routes = {\n        \"192.168.0.1\" = [\n          \"192.168.0.0/24\",\n          \"192.168.1.0/24\"\n          \"0.0.0.0/0\" # To enable access to public network via NAT\n        ]\n      }\n      nameservers = {\n        addresses = [\n          \"192.168.0.3\"\n        ]\n        search = [\n          \"lab.net\",\n        ]\n      }\n    }\n  ]\n  additional_run_commands = [\n    \"echo 'test command'\"\n  ]\n  additional_run_commands = [\n    \"htop\",\n    \"telnet\",\n    \"nano\"\n  ]\n}\n```\n\n## Known Issues\n\nThere are no `Known Issues` known to me for now - please let me know if you will find any.\n\n### Internet Access with only private networks defined\nTo enable access to the internet from instance without public ip addresses there are several things to do:\n- Prepare NAT instance with public IP address or PFsense/Opnsense which will have rules for NAT-ing\n- Add in Hetzner Cloud Console or via hcloud/terraform tool route `0.0.0.0/0` to previously prepared NAT instance/router\n- Add route `0.0.0.0/0` to one of the interfaces defined in `private_networks_settings` - take a look at the example above\n- Add one or more DNS servers to `nameservers` in `private_networks_settings` (They can be public ones or private) - take a look at the example above\n\n## Variables\n\n| Variable name             | variable type  | default value   | Required variable | Description |\n|:-------------------------:|:---------------|:---------------:|:-----------------:|:-----------:|\n| server_type               | `string`       | `empty`         | \u003cb\u003eYes\u003c/b\u003e        | Hetzner server type (ex. cpx11) |\n| server_image              | `string`       | `empty`         | \u003cb\u003eYes\u003c/b\u003e        | Instance system image |\n| additional_users          |\u003cpre\u003elist(object({\u003cbr\u003e    username        = string\u003cbr\u003e    sudo_options    = string\u003cbr\u003e    ssh_public_keys = list(string)\u003cbr\u003e}))\u003c/pre\u003e| `[]` | \u003cb\u003eNo\u003c/b\u003e | List of additional users with their options |\n| private_networks_only     | `bool`         | `false`         | \u003cb\u003eNo\u003c/b\u003e         | Set to `true` when there are no public IP addresses defined for the instance |\n| private_networks_settings |\u003cpre\u003elist(object({\u003cbr\u003e    network_id    = string\u003cbr\u003e    ip            = string\u003cbr\u003e    alias_ips     = list(string)\u003cbr\u003e    routes        = map(list(string))\u003cbr\u003e    nameservers   = object({\u003cbr\u003e      addresses   = list(string)\u003cbr\u003e      search      = list(string)\u003cbr\u003e    })\u003cbr\u003e})\u003c/pre\u003e| `[]` | \u003cb\u003eNo\u003c/b\u003e | List of configuration for all private networks.\u003cbr\u003e\u003cb\u003eNote:\u003c/b\u003e Routes are defined as \u003cb\u003emap(list(string))\u003c/b\u003e where key is a \u003cb\u003egateway ip address\u003c/b\u003e and list contains all \u003cb\u003e network destinations\u003c/b\u003e.\u003cbr\u003e\u003cb\u003eExample:\u003c/b\u003e `\"192.168.0.1\" = [\"192.168.0.0/24\",\"192.168.1.0/24\"]` |\n| additional_write_files    |\u003cpre\u003elist(object({\u003cbr\u003e    content     = string\u003cbr\u003e    owner_user  = string\u003cbr\u003e    owner_group = string\u003cbr\u003e    destination = string\u003cbr\u003e    permissions = string\u003cbr\u003e}))\u003c/pre\u003e| `[]` | \u003cb\u003eNo\u003c/b\u003e | List of additional files to create on first boot.\u003cbr\u003e\u003cb\u003eNote:\u003c/b\u003e inside `content` value please provide \u003cu\u003e\u003ci\u003eplain text content of the file\u003c/i\u003e\u003c/u\u003e (not the path to the file).\u003cbr\u003eYou can use terraform to generate file from template or to read existing file from local machine |\n| additional_hosts_entries  |\u003cpre\u003elist(object({\u003cbr\u003e    ip        = string\u003cbr\u003e    hostnames    = string\u003cbr\u003e}))\u003c/pre\u003e| `[]` | \u003cb\u003eNo\u003c/b\u003e | List of entries for `/etc/hosts` file. There is possibility to define multiple hostnames per single ip address |\n| additional_run_commands   | `list(string)` | `[]`            | \u003cb\u003eNo\u003c/b\u003e         | List of additional commands to run on boot |\n| additional_packages       | `list(string)` | `[]`            | \u003cb\u003eNo\u003c/b\u003e         | List of additional pckages to install on first boot |\n| timezone                  | `string`       | `Europe/Berlin` | \u003cb\u003eNo\u003c/b\u003e         | Timezone for the VM |\n| upgrade_all_packages      | `bool`         | `true`          | \u003cb\u003eNo\u003c/b\u003e         | Set to false when there is no need to upgrade packages on first boot |\n| reboot_instance           | `bool`         | `true`          | \u003cb\u003eNo\u003c/b\u003e         | Set to false when there is no need for instance reboot after finishing cloud-init tasks |\n| yq_version                | `string`       |`v4.6.3`         | \u003cb\u003eNo\u003c/b\u003e         | Version of yq script used for merging netplan script |\n| yq_binary                 | `string`       |`yq_linux_amd64` | \u003cb\u003eNo\u003c/b\u003e         | Binary of yq script used for merging netplan script |\n\n## Outputs\n\n| Output name                          | Description |\n|:------------------------------------:|:------------|\n| result_file                          | Result cloud-config file which will be used by instance (depending on provided `server_image` variable) |\n| result_hosts_file                    | Result host entries file which will be injected into `/etc/hosts` file |\n| packages_install_script              | Result packages install script if there are no public network addresses defined for this instance |\n| result_interfacesd_file_map          | Result cloud-config for interfaces.d compatible instance |\n| interfaced_network_config_file       | Result interfaces.d network file |\n| interfaced_nameservers_file          | Result resolvconf file for interfaces.d compatible instance |\n| result_netplan_cloud_config_file_map | Result cloud-config for Netplan compatible instance |\n| netplan_network_file                 | Result netplan network file which will be merged to main netplan file |\n| netplan_network_merge_script         | Result netplan merge script file |\n| result_ifcfg_cloud_config_map        | Result cloud-config for ifcfg network compatible instance |\n| ifcfg_network_config_files_map       | Result ifcfg network config files map |\n| ifcfg_network_routes_files_map       | Result ifcfg network routes files map |\n| result_keyfile_cloud_config_map      | Result cloud-config for Network manager keyfile compatible instance |\n| keyfile_network_config_files_map     | Result Network manager keyfiles map |\n\n## Contributing\n### Bug Reports/Feature Requests\nPlease use the [issues tab](https://github.com/wszychta/terraform-module.hcloud-user-data/issues) to report any bugs or feature requests. \n\nI can't guarantee that I will work on every bug/feature, because this is my side project, but I will try to keep an eye on any created issue.\n\nSo if somebody will discover any error please look into [Developing](https://github.com/wszychta/terraform-module.hcloud-user-data/tree/initial_commit#developing) section\n\n### Supporting development\nIf you like this module and you haven't started working in Hetzner Cloud you can use my [PERSONAL REFERRAL LINK](https://hetzner.cloud/?ref=YQhSB5WwTzqt) to start working with Hetzner cloud.\nYou will get 20 Euro on start and after spending additional 10 Euro I will get the same amount of money.\n\n### Developing\nIf you have and idea how to improve this module please:\n1. Fork this module from `master` branch\n2. Work on your changes inside your fork\n3. Create Pull Request on this respository.\n4. In my spare time I will look at proposed changes\n\n## Copyright \nCopyright © 2023 Wojciech Szychta\n\n## License\nGNU GENERAL PUBLIC LICENSE Version 3","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwszychta%2Fterraform-module.hcloud-user-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwszychta%2Fterraform-module.hcloud-user-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwszychta%2Fterraform-module.hcloud-user-data/lists"}