terraform-generator
Advanced tools
Comparing version 0.4.0 to 0.5.0
export default class Argument { | ||
readonly args: (string | Argument)[]; | ||
readonly argument: string | Argument; | ||
readonly asIs: boolean; | ||
constructor(...args: (boolean | string | Argument)[]); | ||
constructor(argument: string | Argument, asIs?: boolean); | ||
toTerraform(): string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Argument { | ||
constructor(...args) { | ||
this.asIs = false; | ||
if (args.length > 0 && typeof args[0] === 'boolean') { | ||
this.asIs = args[0]; | ||
args.splice(0, 1); | ||
constructor(argument, asIs = false) { | ||
if (!argument || (typeof argument === 'string' && !argument.trim())) { | ||
throw new Error('Argument cannot be empty.'); | ||
} | ||
if (args.length < 1 || args.filter(arg => arg == null || typeof arg === 'boolean').length > 0) { | ||
throw new Error(`Invalid argument: ${args}`); | ||
} | ||
this.args = args; | ||
this.argument = typeof argument === 'string' ? argument.trim() : argument; | ||
this.asIs = asIs; | ||
} | ||
toTerraform() { | ||
let str = ''; | ||
this.args.forEach(arg => { | ||
if (arg instanceof Argument) { | ||
str += arg.toTerraform(); | ||
} | ||
else { | ||
str += arg; | ||
} | ||
}); | ||
if (this.argument instanceof Argument) { | ||
str += this.argument.toTerraform(); | ||
} | ||
else { | ||
str += this.argument; | ||
} | ||
return str; | ||
@@ -26,0 +20,0 @@ } |
import { Argument } from '..'; | ||
export default class Function extends Argument { | ||
constructor(fn: string, ...args: any); | ||
constructor(fn: string, ...args: (string | number | boolean | Argument)[]); | ||
private static constructArgument; | ||
} |
@@ -6,5 +6,5 @@ "use strict"; | ||
constructor(str) { | ||
super(true, `<<EOT\n${str}\nEOT`); | ||
super(`<<EOT\n${str}\nEOT`, true); | ||
} | ||
} | ||
exports.default = Heredoc; |
import { Block, Argument, Attribute } from '..'; | ||
export default class Backend extends Block { | ||
readonly type: string; | ||
constructor(type: string, args: object); | ||
constructor(type: string, args?: object); | ||
asArgument(): Argument; | ||
getAttribute(name: string): Attribute; | ||
} |
@@ -10,3 +10,3 @@ "use strict"; | ||
asArgument() { | ||
return new __1.Argument(true, JSON.stringify(this.type)); | ||
return new __1.Argument(JSON.stringify(this.type), true); | ||
} | ||
@@ -13,0 +13,0 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars |
@@ -6,3 +6,3 @@ import { TerraformVersion, Attribute, Argument } from '..'; | ||
private readonly arguments; | ||
constructor(type: string, names: string[], args: object); | ||
constructor(type: string, names: string[], args?: object); | ||
getArguments(): object; | ||
@@ -9,0 +9,0 @@ getArgument(key: string): any; |
@@ -10,5 +10,2 @@ "use strict"; | ||
this.validateIdentifier(type); | ||
if (names.length < 1) { | ||
throw new Error('Names cannot be empty.'); | ||
} | ||
names.forEach(name => { | ||
@@ -15,0 +12,0 @@ this.validateIdentifier(name); |
@@ -5,5 +5,5 @@ import { Block, Argument, Attribute } from '..'; | ||
readonly name: string; | ||
constructor(type: string, name: string, args: object); | ||
constructor(type: string, name: string, args?: object); | ||
asArgument(): Argument; | ||
getAttribute(name: string): Attribute; | ||
} |
import { Block, Argument, Attribute } from '..'; | ||
export default class Module extends Block { | ||
readonly name: string; | ||
constructor(name: string, args: object); | ||
constructor(name: string, args?: object); | ||
asArgument(): Argument; | ||
getAttribute(name: string): Attribute; | ||
} |
import { Block, Argument, Attribute } from '..'; | ||
export default class Output extends Block { | ||
readonly name: string; | ||
constructor(name: string, args: object); | ||
constructor(name: string, args?: object); | ||
asArgument(): Argument; | ||
getAttribute(name: string): Attribute; | ||
} |
import { Block, Argument, Attribute } from '..'; | ||
export default class Provider extends Block { | ||
readonly name: string; | ||
constructor(name: string, args: object); | ||
constructor(name: string, args?: object); | ||
asArgument(): Argument; | ||
getAttribute(name: string): Attribute; | ||
} |
@@ -5,5 +5,5 @@ import { Block, Argument, Attribute } from '..'; | ||
readonly name: string; | ||
constructor(type: string, name: string, args: object); | ||
constructor(type: string, name: string, args?: object); | ||
asArgument(): Argument; | ||
getAttribute(name: string): Attribute; | ||
} |
import { Block, Argument, Attribute } from '..'; | ||
export default class Variable extends Block { | ||
readonly name: string; | ||
constructor(name: string, args: object); | ||
constructor(name: string, args?: object); | ||
asArgument(): Argument; | ||
getAttribute(name: string): Attribute; | ||
} |
{ | ||
"name": "terraform-generator", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"author": "Ah Zhe", | ||
@@ -5,0 +5,0 @@ "description": "Generate Terraform plan using Node.js.", |
@@ -98,3 +98,2 @@ # **terraform-generator** | ||
blockAttribute: block.getAttribute('attrName'), | ||
asIsArg: new Argument(true, 'AS IS'), // it will be printed as is, without extra symbol, quotes and whatnot, regardless of Terraform version | ||
heredoc: new Heredoc(`line1 | ||
@@ -106,3 +105,3 @@ line2 | ||
custom1: new Argument('max(5, 12, 9)'), | ||
custom2: new Argument('sort("a", ', block.getAttribute('attrName'), ', "c")') | ||
custom2: new Argument('as is', true) // it will be printed as is, without extra symbol, quotes and whatnot, regardless of Terraform version | ||
} | ||
@@ -109,0 +108,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28549
630
229