I am running into an error while validating a Terraform 0.12 JSON plan file with the latest terraform-validator binary.
steps to reproduce:
Terraform v0.12.6
- provider.google v2.12.0
terraform-validator Build version: 2019-08-08
main.tf with local state
resource "google_storage_bucket" "image-store-1" { name = "cf-random-test-image-store-bucket-1" location = "europe-north1" }
- terraform init
- terraform plan -out=plan.tfplan
- terraform show -json plan.tfplan > plan.json
- terraform-validator validate --tf-version 0.12 plan.json --policy-path=policy-library --project cf-gcp-challenge-test
plan.json
{"format_version":"0.1","terraform_version":"0.12.6","variables":{"app_project":{"value":"cf-gcp-challenge-dev"}},"planned_values":{"root_module":{"resources":[{"address":"google_app_engine_application.app","mode":"managed","type":"google_app_engine_application","name":"app","provider_name":"google","schema_version":0,"values":{"location_id":"us-central","project":"your-project-id"}},{"address":"google_project.my_project","mode":"managed","type":"google_project","name":"my_project","provider_name":"google","schema_version":1,"values":{"auto_create_network":true,"billing_account":null,"labels":null,"name":"My Project","org_id":"1234567","project_id":"your-project-id"}}]}},"resource_changes":[{"address":"google_app_engine_application.app","mode":"managed","type":"google_app_engine_application","name":"app","provider_name":"google","change":{"actions":["create"],"before":null,"after":{"location_id":"us-central","project":"your-project-id"},"after_unknown":{"auth_domain":true,"code_bucket":true,"default_bucket":true,"default_hostname":true,"feature_settings":true,"gcr_domain":true,"id":true,"name":true,"serving_status":true,"url_dispatch_rule":true}}},{"address":"google_project.my_project","mode":"managed","type":"google_project","name":"my_project","provider_name":"google","change":{"actions":["create"],"before":null,"after":{"auto_create_network":true,"billing_account":null,"labels":null,"name":"My Project","org_id":"1234567","project_id":"your-project-id"},"after_unknown":{"app_engine":true,"folder_id":true,"id":true,"number":true,"policy_data":true,"policy_etag":true,"skip_delete":true}}}],"configuration":{"provider_config":{"google":{"name":"google","expressions":{"project":{"constant_value":"cf-gcp-challenge-dev"}}}},"root_module":{"resources":[{"address":"google_app_engine_application.app","mode":"managed","type":"google_app_engine_application","name":"app","provider_config_key":"google","expressions":{"location_id":{"constant_value":"us-central"},"project":{"references":["google_project.my_project"]}},"schema_version":0},{"address":"google_project.my_project","mode":"managed","type":"google_project","name":"my_project","provider_config_key":"google","expressions":{"name":{"constant_value":"My Project"},"org_id":{"constant_value":"1234567"},"project_id":{"constant_value":"your-project-id"}},"schema_version":1}],"variables":{"app_project":{}}}}}
expected output: no violations found
actual output:
panic: Unknown type: TypeMap
goroutine 1 [running]:
github.com/GoogleCloudPlatform/terraform-validator/tfplan.jsonResourceFieldReader.ReadField(0x21ced49, 0x4, 0xc0005ecb10, 0xd, 0xc00003b080, 0x23, 0xc0005ecb00, 0x7, 0xc00041c8e0, 0x15,...)
/home/awalko/terraform-validator/tfplan/json_plan.go:110 +0x419
github.com/GoogleCloudPlatform/terraform-validator/tfplan.(*fieldGetter).GetOk(0xc0003382a0, 0x21d0bb6, 0x6, 0x0, 0x0, 0xc000227c00)
/home/awalko/terraform-validator/tfplan/fields.go:87 +0xac
github.com/GoogleCloudPlatform/terraform-google-conversion/google.expandStringMap(0x25b2a00, 0xc0003382c0, 0x21d0bb6, 0x6, 0xc000227c90)
/home/awalko/terraform-validator/vendor/github.com/GoogleCloudPlatform/terraform-google-conversion/google/utils.go:242 +0x49
github.com/GoogleCloudPlatform/terraform-google-conversion/google.expandLabels(...)
/home/awalko/terraform-validator/vendor/github.com/GoogleCloudPlatform/terraform-google-conversion/google/utils.go:232
github.com/GoogleCloudPlatform/terraform-google-conversion/google.GetStorageBucketApiObject(0x25b2a00, 0xc0003382c0, 0xc0000aa1a0, 0x21fce27, 0x21, 0xc00003f380)
/home/awalko/terraform-validator/vendor/github.com/GoogleCloudPlatform/terraform-google-conversion/google/storage_bucket.go:54 +0x188
github.com/GoogleCloudPlatform/terraform-google-conversion/google.GetStorageBucketCaiObject(0x25b2a00, 0xc0003382c0, 0xc0000aa1a0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/home/awalko/terraform-validator/vendor/github.com/GoogleCloudPlatform/terraform-google-conversion/google/storage_bucket.go:25 +0xdc
github.com/GoogleCloudPlatform/terraform-validator/converters/google.(*Converter).AddResource(0xc0004a98f0, 0x25aa0c0, 0xc00048bf40, 0xc0004a9920, 0xc00048bf00)
/home/awalko/terraform-validator/converters/google/convert.go:154 +0x14c
github.com/GoogleCloudPlatform/terraform-validator/tfgcv.ReadPlannedAssets(0x7ffed96be21e, 0x9, 0x7ffed96be24f, 0x15, 0x0, 0x0, 0x7ffed96be219, 0x4, 0x0, 0x0, ...)
/home/awalko/terraform-validator/tfgcv/planned_assets.go:97 +0x6d8
github.com/GoogleCloudPlatform/terraform-validator/cmd.glob..func6(0x37038e0, 0xc00057a600, 0x1, 0x6, 0x0, 0x0)
/home/awalko/terraform-validator/cmd/validate.go:49 +0xa8
github.com/spf13/cobra.(*Command).execute(0x37038e0, 0xc00057a540, 0x6, 0x6, 0x37038e0, 0xc00057a540)
/home/awalko/terraform-validator/vendor/github.com/spf13/cobra/command.go:762 +0x465
github.com/spf13/cobra.(*Command).ExecuteC(0x3703680, 0x0, 0x0, 0x1ae9bc5)
/home/awalko/terraform-validator/vendor/github.com/spf13/cobra/command.go:850 +0x2bb
github.com/spf13/cobra.(*Command).Execute(...)
/home/awalko/terraform-validator/vendor/github.com/spf13/cobra/command.go:800
github.com/GoogleCloudPlatform/terraform-validator/cmd.Execute()
/home/awalko/terraform-validator/cmd/root.go:76 +0x2e
main.main()
/home/awalko/terraform-validator/main.go:20 +0x20