{"id":13930216,"url":"https://github.com/jordibalcellss/terraform-lxd","last_synced_at":"2025-07-19T12:32:02.431Z","repository":{"id":204571357,"uuid":"700566605","full_name":"jordibalcellss/terraform-lxd","owner":"jordibalcellss","description":"Terraform module for LXD","archived":false,"fork":false,"pushed_at":"2023-10-30T23:40:03.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-08T18:26:50.016Z","etag":null,"topics":["centos","linux-containers","lxc","lxd","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jordibalcellss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-04T20:48:13.000Z","updated_at":"2023-11-07T01:19:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"f296acea-4499-44b9-ade2-5257dabc891a","html_url":"https://github.com/jordibalcellss/terraform-lxd","commit_stats":null,"previous_names":["jordibalcellss/terraform-lxd"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordibalcellss%2Fterraform-lxd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordibalcellss%2Fterraform-lxd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordibalcellss%2Fterraform-lxd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordibalcellss%2Fterraform-lxd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jordibalcellss","download_url":"https://codeload.github.com/jordibalcellss/terraform-lxd/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226607615,"owners_count":17658483,"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":["centos","linux-containers","lxc","lxd","terraform"],"created_at":"2024-08-07T18:05:15.536Z","updated_at":"2024-11-26T19:30:57.177Z","avatar_url":"https://github.com/jordibalcellss.png","language":"HCL","funding_links":[],"categories":["terraform"],"sub_categories":[],"readme":"# terraform-lxd\n\nA Terraform module for [Linux Containers](https://github.com/canonical/lxd/)\n(LXD) utilizing\n[terraform-provider-lxd](https://github.com/terraform-lxd/terraform-provider-lxd).\n\n## Description\n\nThe module allows creating and provisioning instance fleets using\ndifferent mechanisms after implementing a manageable underlying infrastructure.\n\nIt is composed of two modules actually:\n\n* `lxd-common`: creates a storage pool, a volume and an installation image. The\nmodule call was appended to `provider.tf` for the sake of simplicity.\n* `lxd`: runs per instance (or instance group) and adds volumes, prepares the\ncloud-init image/s, renders the required templates and creates the instances.\n\n## Requirements\n\n### A host server\n\nA preconfigured host server prepared for LXD. During development I put\ntogether an Ansible playbook available from\n[ansible-host-server](https://github.com/jordibalcellss/ansible-host-server/)\nand tested under CentOS 7.\n\n### Terraform\n\n[Terraform](https://www.terraform.io/) manual installation is quite\nstraightforward\n\n```\nwget https://releases.hashicorp.com/terraform/1.5.7/terraform_1.5.7_linux_amd64.zip\nunzip terraform_1.5.7_linux_amd64.zip\nsudo mv terraform /usr/local/bin/terraform\n```\n\n## Configuration\n\n`main.tf` holds the specification for our deployment. The files under\n`examples/` can be renamed and used to that purpose straight away.\n\n### Input variables\n\n| Name | Type | Description | Default |\n| - | - | - | - |\n| hostname | `string` | | `guest` |\n| domain | `string` | Search domain | `local` |\n| memory | `string` | Memory in megabytes | `128MB` |\n| vcpu | `number` | Number of virtual cores | `1` |\n| method | `string` | Address assign method, eiher `static` or `dhcp` | `dhcp` |\n| address | `string` | IP address in CIDR notation | `\"\"` |\n| gateway | `string` | Default gateway | `\"\"` |\n| dns_1 | `string` | Primary nameserver | `\"\"` |\n| dns_2 | `string` | Secondary nameserver | `\"\"` |\n| deploy_account | `string` | Deployment account username | `deploy` |\n| deploy_account_pwd | `string` | Deployment account password | `\"\"` |\n| port | `number` | LXD daemon port | `\"\"` |\n| trust_pwd | `string` | LXD daemon trust password | `\"\"` |\n| host_server | `string` | Host server IP address | `\"\"` |\n\n### Implementing\n\nThe infrastructure can be planned, applied and destroyed by means of\n\n```\nterraform init\nterraform plan\nterraform apply -auto-approve\nterraform destroy -auto-approve\n```\n\nDuring creation Terraform will use `cloud-init` to create a privileged\ndeployment account inside the instances and provide the SSH key found in\n`keys/id_rsa.pub`, so as to prepare the guest systems to be accessed by\nfurther provisioning systems.\n\n## Examples\n\n### Single statically addressed instance\n\n```hcl\nmodule \"guest01\" {\n  source = \"./lxd\"\n  depends_on = [module.common]\n  image_fingerprint = \"${module.common.image_fingerprint}\"\n  hostname = \"guest01\"\n  method = \"static\"\n  address = \"10.12.0.111/24\"\n  gateway = \"10.12.0.1\"\n}\n```\n\n### Multiple instances with random hostnames\n\n```hcl\nvariable \"instances\" { default = 3 }\n\nresource \"random_string\" \"hostname\" {\n  length = 4\n  special = false\n  upper = false\n  count = \"${var.instances}\"\n}\n\nmodule \"guests\" {\n  source = \"./lxd\"\n  depends_on = [module.common]\n  image_fingerprint = \"${module.common.image_fingerprint}\"\n  hostname = \"${random_string.hostname[count.index].result}\"\n  count = \"${var.instances}\"\n}\n```\n\nWhich created three instances\n\n```\n[deploy@host ~]$ lxc list\n+------+---------+--------------------+------+-----------+-----------+\n| NAME |  STATE  |        IPV4        | IPV6 |   TYPE    | SNAPSHOTS |\n+------+---------+--------------------+------+-----------+-----------+\n| jisf | RUNNING | 10.12.0.234 (eth0) |      | CONTAINER | 0         |\n+------+---------+--------------------+------+-----------+-----------+\n| wpxk | RUNNING | 10.12.0.233 (eth0) |      | CONTAINER | 0         |\n+------+---------+--------------------+------+-----------+-----------+\n| xnch | RUNNING | 10.12.0.231 (eth0) |      | CONTAINER | 0         |\n+------+---------+--------------------+------+-----------+-----------+\n```\n\nPlease, browse the `examples/` folder for further scripts.\n\n## References\n\n* [terraform-lxd/lxd (Terraform Registry)](https://registry.terraform.io/providers/terraform-lxd/lxd/latest/docs/)\n* [Canonical LXD documentation](https://documentation.ubuntu.com/lxd/en/latest/)\n* [cloud-init](https://cloudinit.readthedocs.io/en/latest/reference/)\n* [ruanbekker/terraform-lxd-example](https://github.com/ruanbekker/terraform-lxd-example/)\n* [Managing LXC/LXD Linux Containers with Terraform](https://number1.co.za/managing-lxc-lxd-linux-containers-with-terraform/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordibalcellss%2Fterraform-lxd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjordibalcellss%2Fterraform-lxd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordibalcellss%2Fterraform-lxd/lists"}