# Generate Terraform file from Gandi DNS records
[![Pypi version](https://img.shields.io/pypi/v/gandi-2-terraform?color=blue)](https://pypi.org/project/gandi-2-terraform/)
[![Python versions](https://img.shields.io/pypi/pyversions/gandi-2-terraform.svg)](https://pypi.org/project/gandi-2-terraform/)
[![Build status](https://github.com/marcaurele/gandi-2-terraform/workflows/Build%20status/badge.svg)](https://github.com/marcaurele/gandi-2-terraform/actions)
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/a2/d2/e35b9496d89fececbc366b0e66517c036706bb927cbae7aa19df85bf9543/gandi_2_terraform-1.3.0.tar.gz",
"platform": null,
"description": "# Generate Terraform file from Gandi DNS records\n\n[![Pypi version](https://img.shields.io/pypi/v/gandi-2-terraform?color=blue)](https://pypi.org/project/gandi-2-terraform/)\n[![Python versions](https://img.shields.io/pypi/pyversions/gandi-2-terraform.svg)](https://pypi.org/project/gandi-2-terraform/)\n[![Build status](https://github.com/marcaurele/gandi-2-terraform/workflows/Build%20status/badge.svg)](https://github.com/marcaurele/gandi-2-terraform/actions)\n\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.0",
"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": "a54818b60e5a3717199bc8cc0022d416900f785c7e63a2f1c9733187ac83548d",
"md5": "ebae00e4de46efabe5948b19b0237151",
"sha256": "6175aba4cd27b0bb205529e6b613bcd92d94b582b04f8bb80661b255966c845a"
},
"downloads": -1,
"filename": "gandi_2_terraform-1.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ebae00e4de46efabe5948b19b0237151",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8.1",
"size": 17445,
"upload_time": "2024-04-12T22:04:43",
"upload_time_iso_8601": "2024-04-12T22:04:43.075671Z",
"url": "https://files.pythonhosted.org/packages/a5/48/18b60e5a3717199bc8cc0022d416900f785c7e63a2f1c9733187ac83548d/gandi_2_terraform-1.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a2d2e35b9496d89fececbc366b0e66517c036706bb927cbae7aa19df85bf9543",
"md5": "c6a2e8c79f1b896550cd50b0e93b4a36",
"sha256": "e9409c46f7d2770015b40d6c3bbf0aa0206e34130f5911458a6ef5f1617220da"
},
"downloads": -1,
"filename": "gandi_2_terraform-1.3.0.tar.gz",
"has_sig": false,
"md5_digest": "c6a2e8c79f1b896550cd50b0e93b4a36",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8.1",
"size": 16588,
"upload_time": "2024-04-12T22:04:44",
"upload_time_iso_8601": "2024-04-12T22:04:44.698609Z",
"url": "https://files.pythonhosted.org/packages/a2/d2/e35b9496d89fececbc366b0e66517c036706bb927cbae7aa19df85bf9543/gandi_2_terraform-1.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-12 22:04:44",
"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"
}