# Generate Terraform file from Gandi DNS records
[](https://pypi.org/project/gandi-2-terraform/)
[](https://pypi.org/project/gandi-2-terraform/)
[](https://github.com/marcaurele/gandi-2-terraform/actions)
> [!IMPORTANT]
> This repository has been archived as I moved all my domains out of Gandi.net and will not use their services anymore. Therefore I will not be able to keep updating the code if their API changes.
> [!WARNING]
> This project is archived on pypi.org too and will not receive any further update. The final version is `1.3.3`.
This tool aims to simplify managing DNS recods using Terrafom by making the initial import through a single operation.
It fetches DNS records from one or multiple domains you own with [Gandi.net](https://gandi.et) and generates TF files with the corresponding records' resources using `gandi_livedns_record` and defining each record in a set (see the example output). It will output all the `terraform import` command to execute for the records.
## Install
```console
$ pip install gandi-2-terraform
$ gandi2tf --help
```
### Usage
You need to provide the Gandi API key as an environment variable `GANDI_KEY` (same as for the TF provider).
```console
$ export GANDI_KEY=A1b2C3d4E5f6
```
When no argument is given, it will fetch all available domains for the given API key:
```console
$ gandi-2tf
```
Or it can generate the tf configuration file for a single domain:
```console
$ gandi-2tf example.com
```
Fetching the domains only owned by a single organization:
```console
$ gandi-2tf --organization-id 04303337-a1b0-4b96-8bd7-992005a072e9
```
### Options
* `--organization-id`: in case your API key has access to multiple organization, you can filter the list of domains fetched by a single organization ID (_uuid_).
* `--subdir`: flag to create a sub directory per domain and generate the `main.tf` inside it with a second file containing all the `import` commands.
## Configuration
In order to access the DNS records through the API, you have to provide your API key. It uses the same variable name than the [Gandi Terraform](https://registry.terraform.io/providers/go-gandi/gandi/latest) provider `GANDI_KEY`. See [Gandi authentication documentation](https://api.gandi.net/docs/authentication/) of their API on how to generate one.
## Example
```console
$ export GANDI_KEY=A1b2C3d4E5f6
$ gandi-2tf example.com
```
will generate a file `example.com.tf` containing:
```hcl
locals {
example_com_records = {
apex_a = {
name = "@"
type = "A"
ttl = 10800
values = [
"192.30.252.153",
"192.30.252.154",
]
}
apex_mx = {
name = "@"
type = "MX"
ttl = 10800
values = [
"10 spool.mail.gandi.net.",
"50 fb.mail.gandi.net.",
]
}
apex_txt = {
name = "@"
type = "TXT"
ttl = 10800
values = [
"\"v=spf1 include:_mailcust.gandi.net -all\"",
]
}
imap_cname = {
name = "imap"
type = "CNAME"
ttl = 10800
values = [
"access.mail.gandi.net.",
]
}
smtp_cname = {
name = "smtp"
type = "CNAME"
ttl = 10800
values = [
"relay.mail.gandi.net.",
]
}
webmail_cname = {
name = "webmail"
type = "CNAME"
ttl = 10800
values = [
"webmail.gandi.net.",
]
}
}
}
resource "gandi_livedns_record" "example_com" {
for_each = local.example_com_records
zone = "example.com"
name = each.value.name
ttl = each.value.ttl
type = each.value.type
values = each.value.values
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/marcaurele/gandi-2-terraform",
"name": "gandi-2-terraform",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8.1",
"maintainer_email": null,
"keywords": "gandi, terraform, DNS",
"author": "Marc-Aur\u00e8le Brothier",
"author_email": "m@brothier.org",
"download_url": "https://files.pythonhosted.org/packages/b4/7d/11b24367956c654724f9a377b8c6464695e6871ca95e569a61f4f1d66fc9/gandi_2_terraform-1.3.3.tar.gz",
"platform": null,
"description": "# Generate Terraform file from Gandi DNS records\n\n[](https://pypi.org/project/gandi-2-terraform/)\n[](https://pypi.org/project/gandi-2-terraform/)\n[](https://github.com/marcaurele/gandi-2-terraform/actions)\n\n> [!IMPORTANT]\n> This repository has been archived as I moved all my domains out of Gandi.net and will not use their services anymore. Therefore I will not be able to keep updating the code if their API changes.\n\n> [!WARNING]\n> This project is archived on pypi.org too and will not receive any further update. The final version is `1.3.3`.\n\nThis tool aims to simplify managing DNS recods using Terrafom by making the initial import through a single operation.\nIt fetches DNS records from one or multiple domains you own with [Gandi.net](https://gandi.et) and generates TF files with the corresponding records' resources using `gandi_livedns_record` and defining each record in a set (see the example output). It will output all the `terraform import` command to execute for the records.\n\n## Install\n\n```console\n$ pip install gandi-2-terraform\n$ gandi2tf --help\n```\n\n### Usage\n\nYou need to provide the Gandi API key as an environment variable `GANDI_KEY` (same as for the TF provider).\n\n```console\n$ export GANDI_KEY=A1b2C3d4E5f6\n```\n\nWhen no argument is given, it will fetch all available domains for the given API key:\n\n```console\n$ gandi-2tf\n```\n\nOr it can generate the tf configuration file for a single domain:\n\n```console\n$ gandi-2tf example.com\n```\n\nFetching the domains only owned by a single organization:\n\n```console\n$ gandi-2tf --organization-id 04303337-a1b0-4b96-8bd7-992005a072e9\n```\n\n### Options\n\n* `--organization-id`: in case your API key has access to multiple organization, you can filter the list of domains fetched by a single organization ID (_uuid_).\n* `--subdir`: flag to create a sub directory per domain and generate the `main.tf` inside it with a second file containing all the `import` commands.\n\n## Configuration\n\nIn order to access the DNS records through the API, you have to provide your API key. It uses the same variable name than the [Gandi Terraform](https://registry.terraform.io/providers/go-gandi/gandi/latest) provider `GANDI_KEY`. See [Gandi authentication documentation](https://api.gandi.net/docs/authentication/) of their API on how to generate one.\n\n## Example\n\n```console\n$ export GANDI_KEY=A1b2C3d4E5f6\n$ gandi-2tf example.com\n```\n\nwill generate a file `example.com.tf` containing:\n\n```hcl\nlocals {\n example_com_records = {\n apex_a = {\n name = \"@\"\n type = \"A\"\n ttl = 10800\n values = [\n \"192.30.252.153\",\n \"192.30.252.154\",\n ]\n }\n apex_mx = {\n name = \"@\"\n type = \"MX\"\n ttl = 10800\n values = [\n \"10 spool.mail.gandi.net.\",\n \"50 fb.mail.gandi.net.\",\n ]\n }\n apex_txt = {\n name = \"@\"\n type = \"TXT\"\n ttl = 10800\n values = [\n \"\\\"v=spf1 include:_mailcust.gandi.net -all\\\"\",\n ]\n }\n imap_cname = {\n name = \"imap\"\n type = \"CNAME\"\n ttl = 10800\n values = [\n \"access.mail.gandi.net.\",\n ]\n }\n smtp_cname = {\n name = \"smtp\"\n type = \"CNAME\"\n ttl = 10800\n values = [\n \"relay.mail.gandi.net.\",\n ]\n }\n webmail_cname = {\n name = \"webmail\"\n type = \"CNAME\"\n ttl = 10800\n values = [\n \"webmail.gandi.net.\",\n ]\n }\n }\n}\n\nresource \"gandi_livedns_record\" \"example_com\" {\n for_each = local.example_com_records\n\n zone = \"example.com\"\n\n name = each.value.name\n ttl = each.value.ttl\n type = each.value.type\n values = each.value.values\n}\n```\n",
"bugtrack_url": null,
"license": "AGPL",
"summary": "CLI to read Gandi.net live DNS records and generate corresponding TF gandi_livedns_record resources",
"version": "1.3.3",
"project_urls": {
"Bug Tracker": "https://github.com/marcaurele/gandi-2-terraform/issues",
"Homepage": "https://github.com/marcaurele/gandi-2-terraform",
"Repository": "https://github.com/marcaurele/gandi-2-terraform"
},
"split_keywords": [
"gandi",
" terraform",
" dns"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cad2ca4f389d607e160b7a7fc2bfacfffa8161c56216e4d2687c95b41944646f",
"md5": "262b9fd12cb24ecd90bc6055c8ac81cd",
"sha256": "9020ecc733c1cc2dd77d0e39928d131a287bc96914d3154cb4888bff20fac6fb"
},
"downloads": -1,
"filename": "gandi_2_terraform-1.3.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "262b9fd12cb24ecd90bc6055c8ac81cd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8.1",
"size": 17622,
"upload_time": "2025-02-01T09:55:05",
"upload_time_iso_8601": "2025-02-01T09:55:05.932813Z",
"url": "https://files.pythonhosted.org/packages/ca/d2/ca4f389d607e160b7a7fc2bfacfffa8161c56216e4d2687c95b41944646f/gandi_2_terraform-1.3.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b47d11b24367956c654724f9a377b8c6464695e6871ca95e569a61f4f1d66fc9",
"md5": "8531e4e2e29ba9ae6e1f091f457efd5c",
"sha256": "e8e8bfcebb862d312709e3fba60c2a71c3a215eaea55457d2f2c551be58cb03d"
},
"downloads": -1,
"filename": "gandi_2_terraform-1.3.3.tar.gz",
"has_sig": false,
"md5_digest": "8531e4e2e29ba9ae6e1f091f457efd5c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8.1",
"size": 16465,
"upload_time": "2025-02-01T09:55:07",
"upload_time_iso_8601": "2025-02-01T09:55:07.590084Z",
"url": "https://files.pythonhosted.org/packages/b4/7d/11b24367956c654724f9a377b8c6464695e6871ca95e569a61f4f1d66fc9/gandi_2_terraform-1.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-01 09:55:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "marcaurele",
"github_project": "gandi-2-terraform",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "gandi-2-terraform"
}