williamchanrico / tfvarser

Generate Terraform tfvars file using Go text/template, mapping values from cloud provider SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tfvarser πŸ‘‹

Generate tfvars file by mapping live cloud resources (query via SDK) to a tfvars template

A quick hack to reduce toils in importing hundreds of scaling groups by hand

Disclaimer: the templates are curated to specific needs and not really for general use, at least for now as this is only a quick hack to help current task. So keeping the source close by will come in handy every now and then (modifying, rebuilding, etc.)

Installation

$ make go-build will build the tfvarser binary in ./bin/tfvarser according to your machine's OS and arch.

You can also build it yourself using simple gotools

Usage & Examples

Requires some form of authentication to interact with cloud provider's API

Aliyun

export ALICLOUD_ACCESS_KEY=
export ALICLOUD_SECRET_KEY=
export ALICLOUD_REGION_ID=ap-southeast-1 # default
# example generate by names
$ tfvarser -provider ali -obj ess -limit-names testapp,node-qwertyapp,go-asdfapp

# or just import by ID
$ tfvarser -provider ali -obj ess -limit-ids asdf1234

# or just import one at a time
$ tfvarser -provider ali -obj ess -limit-names testapp

Command above will generate the following structure:

β”œβ”€β”€ testapp
β”‚   β”œβ”€β”€ autoscale
β”‚   β”‚   β”œβ”€β”€ ess-alarms
β”‚   β”‚   β”‚   β”œβ”€β”€ go-testapp-downscale
β”‚   β”‚   β”‚   β”‚   └── terraform.tfvars
β”‚   β”‚   β”‚   └── go-testapp-upscale
β”‚   β”‚   β”‚       └── terraform.tfvars
β”‚   β”‚   β”œβ”€β”€ ess-lifecycle-hooks
β”‚   β”‚   β”‚   β”œβ”€β”€ autoscaledown-event-mns-queue
β”‚   β”‚   β”‚   β”‚   └── terraform.tfvars
β”‚   β”‚   β”‚   └── autoscaleup-event-mns-queue
β”‚   β”‚   β”‚       └── terraform.tfvars
β”‚   β”‚   β”œβ”€β”€ ess-scaling-configurations
β”‚   β”‚   β”‚   β”œβ”€β”€ go-testapp-1c-1gb
β”‚   β”‚   β”‚   β”‚   └── terraform.tfvars
β”‚   β”‚   β”‚   └── go-testapp-1c-500mb
β”‚   β”‚   β”‚       └── terraform.tfvars
β”‚   β”‚   β”œβ”€β”€ ess-scaling-group
β”‚   β”‚   β”‚   └── terraform.tfvars
β”‚   β”‚   └── ess-scaling-rules
β”‚   β”‚       β”œβ”€β”€ auto-downscale
β”‚   β”‚       β”‚   └── terraform.tfvars
β”‚   β”‚       └── auto-upscale
β”‚   β”‚           └── terraform.tfvars

Every provider objects e.g. ESS or ECS in Aliyun may decide what limit-names and limit-ids correspond to.

For example, in Aliyun ESS object limit-names and limit-ids will limit by scaling group's name and ID.

About

Generate Terraform tfvars file using Go text/template, mapping values from cloud provider SDK

License:Apache License 2.0


Languages

Language:Go 95.0%Language:Makefile 5.0%