ahzhezhe / terraform-generator

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

in-built Terraform file function isn't recognized #4

Closed xsmills closed 4 years ago

xsmills commented 4 years ago

Describe the bug The in-built Terraform file function isn't recognized. When it is used in a resource like shown below, a reference error is thrown.

To reproduce

tfg.resource('spinnaker_pipeline', 'deploypipeline', {
    application: `spinnaker_appication.myservice.application`,
    name: 'deploy',
    pipeline: file('resources/rollback.json')
  });

Throws this error:

pipeline: file('resources/rollback.json')
              ^
ReferenceError: file is not defined

Expected behavior I would have expected the file function to be recognized.

Additional context Add any other context about the problem here.

ahzhezhe commented 4 years ago

There are few ways you can do it:

  1. Use TerraformGenerator's Function class:

    tfg.resource('spinnaker_pipeline', 'deploypipeline', {
    application: myservice.attr('application'),
    name: 'deploy',
    pipeline: fn('file', 'resources/rollback.json')
    });
  2. Do it in a more Javascript/Typescript manner

    
    const rollbackJson = required('resources/rollback.json');

tfg.resource('spinnaker_pipeline', 'deploypipeline', { application: myservice.attr('application'), name: 'deploy', pipeline: heredoc(rollbackJson) });


3. You can even write your rollback JSON directly in your .js or .ts file:

const rollbackJson = { something: 'something' };

tfg.resource('spinnaker_pipeline', 'deploypipeline', { application: myservice.attr('application'), name: 'deploy', pipeline: heredoc(rollbackJson) });