instance_key should be of type interface{} (#94)
diff --git a/checks.go b/checks.go
index 1a4c8cc..558cb29 100644
--- a/checks.go
+++ b/checks.go
@@ -92,7 +92,7 @@
//
// InstanceKey will be empty if there was no foreach or count argument
// defined on the containing object.
- InstanceKey string `json:"instance_key,omitempty"`
+ InstanceKey interface{} `json:"instance_key,omitempty"`
}
// CheckResultStatic is the container for a "checkable object".
diff --git a/parse_test.go b/parse_test.go
index 79c9a66..137d475 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -31,6 +31,12 @@
continue
}
+ // Skip this directory as this is a unique test that only tests a subset
+ // of attributes for a plan. The fixture is not entirely valid, but that's okay.
+ if e.Name() == "has_checks" {
+ continue
+ }
+
t.Run(e.Name(), func(t *testing.T) {
expected, err := ioutil.ReadFile(filepath.Join(testFixtureDir, e.Name(), filename))
if err != nil {
diff --git a/plan_test.go b/plan_test.go
index c74826d..035cd4a 100644
--- a/plan_test.go
+++ b/plan_test.go
@@ -6,6 +6,7 @@
import (
"encoding/json"
"os"
+ "reflect"
"testing"
"github.com/google/go-cmp/cmp"
@@ -65,3 +66,36 @@
t.Fatalf("unexpected variables: %s", diff)
}
}
+
+func TestPlan_withChecks(t *testing.T) {
+ f, err := os.Open("testdata/has_checks/plan.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+
+ var plan *Plan
+ if err := json.NewDecoder(f).Decode(&plan); err != nil {
+ t.Fatal(err)
+ }
+
+ if err := plan.Validate(); err != nil {
+ t.Fatal(err)
+ }
+
+ if len(plan.Checks) == 0 {
+ t.Fatal("expected checks to not be empty")
+ }
+
+ for _, c := range plan.Checks {
+ for _, instance := range c.Instances {
+ k := reflect.TypeOf(instance.Address.InstanceKey).Kind()
+ switch k {
+ case reflect.Int, reflect.Float32, reflect.Float64, reflect.String:
+ t.Log("instance key is a valid type")
+ default:
+ t.Fatalf("unexpected type %s, expected string or int", k.String())
+ }
+ }
+ }
+}
diff --git a/testdata/has_checks/plan.json b/testdata/has_checks/plan.json
new file mode 100644
index 0000000..4c45605
--- /dev/null
+++ b/testdata/has_checks/plan.json
@@ -0,0 +1 @@
+{"format_version":"1.1","terraform_version":"1.5.0","planned_values":{"root_module":{"resources":[{"address":"null_resource.foo","mode":"managed","type":"null_resource","name":"foo","provider_name":"registry.terraform.io/hashicorp/null","schema_version":0,"values":{"triggers":null},"sensitive_values":{}}]}},"resource_changes":[{"address":"null_resource.foo","mode":"managed","type":"null_resource","name":"foo","provider_name":"registry.terraform.io/hashicorp/null","change":{"actions":["create"],"before":null,"after":{"triggers":null},"after_unknown":{"id":true},"before_sensitive":false,"after_sensitive":{}}}],"configuration":{"provider_config":{"null":{"name":"null","full_name":"registry.terraform.io/hashicorp/null"}},"root_module":{"resources":[{"address":"null_resource.foo","mode":"managed","type":"null_resource","name":"foo","provider_config_key":"null","schema_version":0}]}},"checks":[{"//":"EXPERIMENTAL: see docs for details","address":{"kind":"resource","mode":"managed","module":"module.foo.module.bar","name":"this","to_display":"module.foo.module.bar.foobar.this","type":"foobar"},"status":"pass","instances":[{"address":{"instance_key":0,"module":"module.foo.module.bar","to_display":"module.foo.module.bar.foobar.this[0]"},"status":"pass"}]},{"//":"EXPERIMENTAL: see docs for details","address":{"kind":"resource","mode":"managed","module":"module.foo.module.bar","name":"this","to_display":"module.foo.module.bar.foobar.this","type":"foobar"},"status":"pass"}]}