Skip to content

Commit

Permalink
added unit tests for breaking changes case
Browse files Browse the repository at this point in the history
  • Loading branch information
Devang Gaur committed Jan 15, 2021
1 parent b1c5360 commit a359304
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/getting-started/usage.md
Expand Up @@ -118,7 +118,7 @@ Flags:
-d, --iac-dir string path to a directory containing one or more IaC files (default ".")
-f, --iac-file string path to a single IaC file
-i, --iac-type string iac type (helm, k8s, kustomize, terraform)
--iac-version string iac version (helm: v3, k8s: v1, kustomize: v3, terraform: v14)
--iac-version string iac version (helm: v3, k8s: v1, kustomize: v3, terraform: v12, v14)
-p, --policy-path stringArray policy path directory
-t, --policy-type strings policy type (all, aws, azure, gcp, github, k8s) (default [all])
-r, --remote-type string type of remote backend (git, s3, gcs, http)
Expand Down
6 changes: 6 additions & 0 deletions pkg/iac-providers/terraform/v12/load-dir_test.go
Expand Up @@ -60,6 +60,12 @@ func TestLoadIacDir(t *testing.T) {
tfv12: TfV12{},
wantErr: commons.ErrLoadConfigDir,
},
{
name: "load invalid config dir",
dirPath: "./testdata/multiple-required-providers",
tfv12: TfV12{},
wantErr: commons.ErrLoadConfigDir,
},
}

for _, tt := range table {
Expand Down
6 changes: 6 additions & 0 deletions pkg/iac-providers/terraform/v12/load-file_test.go
Expand Up @@ -54,6 +54,12 @@ func TestLoadIacFile(t *testing.T) {
tfv12: TfV12{},
wantErr: commons.ErrLoadConfigFile,
},
{
name: "destroy-provisioners",
filePath: "./testdata/destroy-provisioners/main.tf",
tfv12: TfV12{},
wantErr: commons.ErrLoadConfigFile,
},
}

for _, tt := range table {
Expand Down
@@ -0,0 +1,44 @@
locals {
user = "name"
}

resource "null_resource" "a" {
connection {
host = self.hostname
user = local.user # ERROR: Invalid reference from destroy provisioner
}

provisioner "remote-exec" {
when = destroy
index = count.index
key = each.key

// path and terraform values are static, and do not create any
// dependencies.
dir = path.module
workspace = terraform.workspace
}
}

resource "null_resource" "b" {
connection {
host = self.hostname
# this is OK since there is no destroy provisioner
user = local.user
}

provisioner "remote-exec" {
}
}

resource "null_resource" "b" {
provisioner "remote-exec" {
when = destroy
connection {
host = self.hostname
user = local.user # ERROR: Invalid reference from destroy provisioner
}

command = "echo ${local.name}" # ERROR: Invalid reference from destroy provisioner
}
}
@@ -0,0 +1,7 @@
terraform {
required_providers {
bar = {
version = "~>1.0.0"
}
}
}
@@ -0,0 +1,7 @@
terraform {
required_providers {
foo = {
version = "~>2.0.0"
}
}
}

0 comments on commit a359304

Please sign in to comment.