Skip to content

Commit

Permalink
add import
Browse files Browse the repository at this point in the history
  • Loading branch information
Chang Zhe Jiet authored and Chang Zhe Jiet committed Nov 24, 2023
1 parent 5d39a59 commit 252be24
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
26 changes: 13 additions & 13 deletions src/TerraformGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,19 @@ export class TerraformGenerator {
return block;
}

/**
* Add import into Terraform.
*
* Refer to Terraform documentation on what can be put as arguments.
*
* @param args arguments
*/
import(args?: Record<string, any>): Import {
const block = new Import(args);
this.addBlocks(block);
return block;
}

/**
* Add variable values into Terraform.
*
Expand All @@ -323,19 +336,6 @@ export class TerraformGenerator {
return this;
}

/**
* Add import into Terraform.
*
* Refer to Terraform documentation on what can be put as arguments.
*
* @param args arguments
*/
import(args?: Record<string, any>): Import {
const importBlock = new Import(args);
this.addBlocks(importBlock);
return importBlock;
}

/**
* Merge this instance with other TerraformGenerator instances.
*
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/Import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Block } from '.';
export class Import extends Block {

/**
* Construct import blocks.
* Construct import.
*
* Refer to Terraform documentation on what can be put as arguments.
*
Expand Down
8 changes: 4 additions & 4 deletions test/blocks/Import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { arg4 } from '..';
import { Import } from '../../src/blocks';

test('Import', () => {
const importTest = new Import(arg4);
expect(importTest.toTerraform()).toMatchSnapshot();
expect(() => importTest.asArgument()).toThrow();
expect(() => importTest.attr('attr')).toThrow();
const imp = new Import(arg4);
expect(imp.toTerraform()).toMatchSnapshot();
expect(() => imp.asArgument()).toThrow();
expect(() => imp.attr('attr')).toThrow();
});
6 changes: 6 additions & 0 deletions test/tfg/Others.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ const createTerraformGenerator = (): TerraformGenerator => {
c: r.attr('x')
});

tfg.import({
a: 'a',
b: 123,
c: r.attr('x')
});

tfg.resource('tags', 'tags', {
tags: map({
'a': 'a',
Expand Down
16 changes: 16 additions & 0 deletions test/tfg/__snapshots__/Others.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ exports[`Others 2`] = `
"blockType": "provisioner",
"type": "provisioner",
},
Import {
"blockNames": [],
"blockType": "import",
},
Resource {
"blockNames": [
"tags",
Expand Down Expand Up @@ -188,6 +192,12 @@ b = 123
c = aws_vpc.test.x
}
import{
a = "a"
b = 123
c = aws_vpc.test.x
}
resource "tags" "tags"{
tags = {
a = "a"
Expand Down Expand Up @@ -276,6 +286,12 @@ b = 123
c = aws_vpc.test.x
}
import{
a = "a"
b = 123
c = aws_vpc.test.x
}
resource "tags" "tags"{
tags = {
a = "a"
Expand Down

0 comments on commit 252be24

Please sign in to comment.