brave/cf2tf

Name: cf2tf

Owner: Brave Software

Description: A Terraform importer for Cloudflare resources, inspired by terraforming

Created: 2017-08-24 04:30:02.0

Updated: 2018-04-18 16:57:12.0

Pushed: 2018-02-15 16:00:16.0

Homepage:

Size: 26

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

cf2tf: Cloudflare to Terraform

A Terraform importer for Cloudflare resources inspired by terraforming.

Installation
clone https://github.com/brave/cf2tf
install -g
Prerequisites

You must export your Cloudflare credentials:

rt CLOUDFLARE_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
rt CLOUDFLARE_EMAIL=xxx@xxx.xxx
Usage
2tf --help
ands:
s  import dns records

ons:
help  Show help                                                    [boolean]
tfstate  output tfstate                                     [default: false]

2tf dns --help
f dns

ons:
help     Show help                                                 [boolean]
tfstate  output tfstate                                     [default: false]
zone     limit to a particular zone by name                    [default: ""]
Example

The following example shows simulated output for a domain mysite.com which has a single record, an apex CNAME to mysite.org

2tf dns --zone mysite.com > main.tf
t main.tf

"resource": {
    "cloudflare_record": {
        "mysite_com_CNAME_mysite_org": {
            "domain": "mysite.com",
            "name": "mysite.com",
            "value": "mysite.org",
            "type": "CNAME",
            "proxied": false
        }
    }
}

2tf dns --zone mysite.com --tfstate > terraform.tfstate
t terraform.tfstate

"version": 1,
"serial": 1,
"modules": [
    {
        "path": [
            "root"
        ],
        "outputs": {},
        "resources": {
            "cloudflare_record.mysite_com_CNAME_mysite_org": {
                "type": "cloudflare_record",
                "depends_on": [],
                "primary": {
                    "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                    "attributes": {
                        "domain": "mysite.com",
                        "hostname": "mysite.com",
                        "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                        "name": "mysite.com",
                        "priority": "0",
                        "proxied": "false",
                        "ttl": "1",
                        "type": "CNAME",
                        "value": "mysite.org",
                        "zone_id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
                    },
                    "meta": {
                        "schema_version": "1"
                    },
                    "tainted": false
                },
                "deposed": [],
                "provider": ""
            }
        },
        "depends_on": []
    }
]

Notes

Unlike terraforming, cf2tf outputs in the Terraform JSON configuration format. This can easily converted to hcl format via a tool like json2hcl.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.