ahzhezhe / terraform-generator

Generate Terraform configurations with Node.js.
ISC License
98 stars 19 forks source link

terraform value from tfg.generate().tf is not pretty #28

Closed luonmincuoi872 closed 1 year ago

luonmincuoi872 commented 2 years ago

Describe the bug Terraform value from tfg.generate().tf is not pretty

To reproduce

const tfg = new TerraformGenerator();
tfg.provider('aws', {
  region: 'ap-southeast-1'
});

tfg.generate().tf return bellow

terraform {
required_providers {
aws = "3.3.0"
}
}

provider "aws" {
region = "ap-southeast-1"
}

Expected behavior

terraform {
  required_providers {
    aws = "3.3.0"
  }
}

provider "aws" {
  region = "ap-southeast-1"
}
lengcheng111 commented 2 years ago

vote up!

ahzhezhe commented 2 years ago

can I understand your use case of using .generate method?

luonmincuoi872 commented 2 years ago

I init data return from generate method into monaco editor as i checked monaco editor not support format hcl code (and some other language like java ...) Is it posible to format terraform code in generate method?

ahzhezhe commented 2 years ago

There is no plan to format it using javascript at the moment, it is mentioned in README limitation section too. I might revisit this if I have time.

The reason why I didn't do it is because I usually write it into a file, the .write() method has an options to format the file using terraform fmt.

I am not familiar with monaco editor, could you explore whether it is possible to run terraform fmt?

luonmincuoi872 commented 2 years ago

Actually, my project is use reactjs and there is an error when i used .write() method. fs.existssync is not a function I have not find the sollution yet. i dont know how is the content of generated terraform file.

ahzhezhe commented 2 years ago

It is suppose to be used in backend Nodejs. Using with react is not something I thought about and catered for.

I will update here if I manage to make .generate produce prettified text.