Skip to content

Commit

Permalink
add more unit test for terraform v12 package
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuf Kanchwala committed Aug 3, 2020
1 parent ae98831 commit 887911b
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/iac-providers/terraform/v12/load-file_test.go
Expand Up @@ -78,6 +78,13 @@ func TestLoadIacFile(t *testing.T) {
tfv12: TfV12{},
wantErr: nil,
},
{
name: "config1",
tfConfigFile: "./testdata/dummyconfig/dummyconfig.tf",
tfJSONFile: "./testdata/tfjson/dummyconfig.json",
tfv12: TfV12{},
wantErr: nil,
},
}

for _, tt := range table2 {
Expand Down
@@ -0,0 +1,55 @@
resource "type1" "resource1" {
test3 = 1 + 2
test1 = "hello"
test2 = 5
arr = [1, 2, 3, 4]
hyphen-test = 3
temp = "${1 + 2} %{if local.test2 < 3}\"4\n\"%{endif}"
temp2 = "${"hi"} there"
quoted = "\"quoted\""
squoted = "'quoted'"
}

resource "type2" "resource2"{
other = {
num = local.test2 + 5
thing = [for x in local.arr: x * 2]
"${local.test3}" = 4
3 = 1
"local.test1" = 89
"a.b.c[\"hi\"][3].*" = 3
loop = "This has a for loop: %{for x in local.arr}x,%{endfor}"
a.b.c = "True"
}
}

resource "type3" "resource3" {
heredoc = <<-EOF
This is a heredoc template.
It references ${local.other.3}
EOF
simple = 4 - 2
cond = test3 > 2 ? 1: 0
heredoc2 = <<EOF
Another heredoc, that
doesn't remove indentation
${local.other.3}
%{if true ? false : true}"gotcha"\n%{else}4%{endif}
EOF
}

resource "terraform_remote_state" "remote" {
backend = "s3"
config = {
profile = var.profile
region = var.region
bucket = "mybucket"
key = "mykey"
}
}

variable "profile" {}

variable "region" {
default = "us-east-1"
}
77 changes: 77 additions & 0 deletions pkg/iac-providers/terraform/v12/testdata/tfjson/dummyconfig.json
@@ -0,0 +1,77 @@
{
"terraform_remote_state": [
{
"id": "terraform_remote_state.remote",
"name": "remote",
"source": "./testdata/dummyconfig/dummyconfig.tf",
"type": "terraform_remote_state",
"config": {
"backend": "s3",
"config": {
"bucket": "mybucket",
"key": "mykey",
"profile": "${var.profile}",
"region": "${var.region}"
}
}
}
],
"type1": [
{
"id": "type1.resource1",
"name": "resource1",
"source": "./testdata/dummyconfig/dummyconfig.tf",
"type": "type1",
"config": {
"arr": [
1,
2,
3,
4
],
"hyphen-test": 3,
"quoted": "\"quoted\"",
"squoted": "'quoted'",
"temp": "${1 + 2} %{if local.test2 \u003c 3}\"4\n\"%{endif}",
"temp2": "hi there",
"test1": "hello",
"test2": 5,
"test3": "${1 + 2}"
}
}
],
"type2": [
{
"id": "type2.resource2",
"name": "resource2",
"source": "./testdata/dummyconfig/dummyconfig.tf",
"type": "type2",
"config": {
"other": {
"${local.test3}": 4,
"3": 1,
"a.b.c": "True",
"a.b.c[\"hi\"][3].*": 3,
"local.test1": 89,
"loop": "This has a for loop: %{for x in local.arr}x,%{endfor}",
"num": "${local.test2 + 5}",
"thing": "${[for x in local.arr: x * 2]}"
}
}
}
],
"type3": [
{
"id": "type3.resource3",
"name": "resource3",
"source": "./testdata/dummyconfig/dummyconfig.tf",
"type": "type3",
"config": {
"cond": "${test3 \u003e 2 ? 1: 0}",
"heredoc": "This is a heredoc template.\nIt references ${local.other.3}\n",
"heredoc2": "\t\tAnother heredoc, that\n\t\tdoesn't remove indentation\n\t\t${local.other.3}\n\t\t%{if true ? false : true}\"gotcha\"\\n%{else}4%{endif}\n",
"simple": "${4 - 2}"
}
}
]
}

0 comments on commit 887911b

Please sign in to comment.