Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

terraform-generator

> 数据库
Open source

Generate Terraform configurations with Node.js.

100 stars0 likes3 views
WebsiteGitHub

About

Generate Terraform configurations with Node.js.

terraform-generator

Use Node.js to generate Terraform configurations.

You do not need to have Terraform installed to use this module.

The end result of using this module is Terraform configurations in plain text, you will need to write the text into a file (terraform-generator does provide an utility function to write the file for you) and execute it yourself.

Currently support generating configurations for Terraform version >= 0.12.

API Documentation

Benefit

Make use of all Javascript programming features (some of which is not available in Terraform), e.g. functions, array, loops, if-else, map, etc. to generate a plain Terraform configurations.

You can easily maintain your infra in Javascript/Typescript.

You don't need to use Terraform variables, you can use your own Javascript/JSON variables or use dotenv.

You don't need to use Terraform modules for reusable resource creations, you can make use of Javascript functions.

You can incorporate other Node.js libraries to facilitate your work.

Limitation

The generated configurations are unformatted and its validity is not verified, use terraform fmt and terraform plan to format it and check its validity yourself.

Install via NPM

bash
npm install terraform-generator

Usage

Import

typescript
import { TerraformGenerator, Resource, map, fn } from 'terraform-generator';

or

typescript
const { TerraformGenerator, Resource, map, fn } = require('terraform-generator');

Initialize TerraformGenerator

typescript
const tfg = new TerraformGenerator({
  required_version: '>= 0.12'
});

Blocks

Some block's arguments are not typed, please refer to official Terraform documentation on what arguments can be supplied.

typescript
tfg.provider('aws', {
  region: 'ap-southeast-1',
  profile: 'example'
});

const vpc = tfg.resource('aws_vpc', 'vpc', {
  cidr_block: '172.88.0.0/16'
});

Convert resource to data source

typescript
import { vpc as vpcDS } from 'other-terraform-generator-configuration';

const vpc = tfg.dataFromResource(vpcDS, undefined, ['cidr_block', ['tags', 'tag']]);

Arguments

…

Attributes

typescript
block.attr('id')                                      // block id, string
block.id                                              // convenience getter function, same as above
block.attr('subnets')                                 // subnet objects, object list
block.attr('subnets.*.id')                            // subnet ids, string list
block.attr('subnets').attr('*').attr('id')            // same as above
block.attr('subnets.*.id[0]')                         // first subnet id, string
block.attr('subnets').attr('*').attr('id').element(0) // same as above

Variables

typescript
// You can directly add multiple variable values.
tfg.addVars({
  var1: 123,
  var2: 'abc'
});

// You can also add single variable value while adding variable block to your configuration.
tfg.variable('password', {
  type: 'string'
}, 'p@ssW0rd');

Merge multiple configurations

typescript
// You can split your configuration into multiple files and merge them before you generate the final outcome.
tfg.merge(tfg2, tfg3);

Generate Terraform configuration

typescript
// Generate Terraform configuration as string
const result = tfg.generate();
console.log(result.tf);
console.log(result.tfvars);

// Write Terraform configuration to a file
tfg.write({
  dir: 'outputDir',
  format: true
});

Example

…

Issues· 1 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptjavascriptterraformterraform-configurationsterraform-project

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库