From 095bf22e7e47249b4b94b574c8a8f38c54836655 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Tue, 3 Mar 2020 12:52:17 -0500 Subject: [PATCH] add tests showing expected prior state resource addressing --- command/show_test.go | 4 - .../show-json-state/basic/output.json | 36 ++++ .../show-json-state/basic/terraform.tfstate | 34 ++++ .../show-json/multi-resource-update/main.tf | 13 ++ .../multi-resource-update/output.json | 167 ++++++++++++++++++ .../multi-resource-update/terraform.tfstate | 24 +++ 6 files changed, 274 insertions(+), 4 deletions(-) create mode 100644 command/testdata/show-json-state/basic/output.json create mode 100644 command/testdata/show-json-state/basic/terraform.tfstate create mode 100644 command/testdata/show-json/multi-resource-update/main.tf create mode 100644 command/testdata/show-json/multi-resource-update/output.json create mode 100644 command/testdata/show-json/multi-resource-update/terraform.tfstate diff --git a/command/show_test.go b/command/show_test.go index 86a4a790cff2..3ad7b437d597 100644 --- a/command/show_test.go +++ b/command/show_test.go @@ -323,9 +323,7 @@ func TestShow_json_output(t *testing.T) { if !cmp.Equal(got, want) { t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, want)) } - }) - } } @@ -405,9 +403,7 @@ func TestShow_json_output_state(t *testing.T) { if !cmp.Equal(got, want) { t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, want)) } - }) - } } diff --git a/command/testdata/show-json-state/basic/output.json b/command/testdata/show-json-state/basic/output.json new file mode 100644 index 000000000000..67d485a6eb86 --- /dev/null +++ b/command/testdata/show-json-state/basic/output.json @@ -0,0 +1,36 @@ +{ + "format_version": "0.1", + "terraform_version": "0.12.0", + "values": { + "root_module": { + "resources": [ + { + "address": "test_instance.example[0]", + "mode": "managed", + "type": "test_instance", + "name": "example", + "index": 0, + "provider_name": "test", + "schema_version": 0, + "values": { + "ami": null, + "id": "621124146446964903" + } + }, + { + "address": "test_instance.example[1]", + "mode": "managed", + "type": "test_instance", + "name": "example", + "index": 1, + "provider_name": "test", + "schema_version": 0, + "values": { + "ami": null, + "id": "4330206298367988603" + } + } + ] + } + } +} diff --git a/command/testdata/show-json-state/basic/terraform.tfstate b/command/testdata/show-json-state/basic/terraform.tfstate new file mode 100644 index 000000000000..61983c6b0426 --- /dev/null +++ b/command/testdata/show-json-state/basic/terraform.tfstate @@ -0,0 +1,34 @@ +{ + "version": 4, + "terraform_version": "0.12.0", + "serial": 1, + "lineage": "00bfda35-ad61-ec8d-c013-14b0320bc416", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "test_instance", + "name": "example", + "each": "list", + "provider": "provider.test", + "instances": [ + { + "index_key": 0, + "schema_version": 0, + "attributes": { + "id": "621124146446964903" + }, + "private": "bnVsbA==" + }, + { + "index_key": 1, + "schema_version": 0, + "attributes": { + "id": "4330206298367988603" + }, + "private": "bnVsbA==" + } + ] + } + ] +} diff --git a/command/testdata/show-json/multi-resource-update/main.tf b/command/testdata/show-json/multi-resource-update/main.tf new file mode 100644 index 000000000000..3ead9dd32b79 --- /dev/null +++ b/command/testdata/show-json/multi-resource-update/main.tf @@ -0,0 +1,13 @@ +variable "test_var" { + default = "bar" +} + +// There is a single instance in state. The plan will add a resource. +resource "test_instance" "test" { + ami = var.test_var + count = 2 +} + +output "test" { + value = var.test_var +} diff --git a/command/testdata/show-json/multi-resource-update/output.json b/command/testdata/show-json/multi-resource-update/output.json new file mode 100644 index 000000000000..a5a3a5b3d8b0 --- /dev/null +++ b/command/testdata/show-json/multi-resource-update/output.json @@ -0,0 +1,167 @@ +{ + "format_version": "0.1", + "terraform_version": "0.13.0", + "variables": { + "test_var": { + "value": "bar" + } + }, + "planned_values": { + "outputs": { + "test": { + "sensitive": false, + "value": "bar" + } + }, + "root_module": { + "resources": [ + { + "address": "test_instance.test[0]", + "mode": "managed", + "type": "test_instance", + "name": "test", + "index": 0, + "provider_name": "test", + "schema_version": 0, + "values": { + "ami": "bar", + "id": "placeholder" + } + }, + { + "address": "test_instance.test[1]", + "mode": "managed", + "type": "test_instance", + "name": "test", + "index": 1, + "provider_name": "test", + "schema_version": 0, + "values": { + "ami": "bar" + } + } + ] + } + }, + "resource_changes": [ + { + "address": "test_instance.test[0]", + "mode": "managed", + "type": "test_instance", + "name": "test", + "index": 0, + "provider_name": "test", + "change": { + "actions": [ + "no-op" + ], + "before": { + "ami": "bar", + "id": "placeholder" + }, + "after": { + "ami": "bar", + "id": "placeholder" + }, + "after_unknown": {} + } + }, + { + "address": "test_instance.test[1]", + "mode": "managed", + "type": "test_instance", + "name": "test", + "index": 1, + "provider_name": "test", + "change": { + "actions": [ + "create" + ], + "before": null, + "after": { + "ami": "bar" + }, + "after_unknown": { + "id": true + } + } + } + ], + "output_changes": { + "test": { + "actions": [ + "create" + ], + "before": null, + "after": "bar", + "after_unknown": false + } + }, + "prior_state": { + "format_version": "0.1", + "terraform_version": "0.13.0", + "values": { + "outputs": { + "test": { + "sensitive": false, + "value": "bar" + } + }, + "root_module": { + "resources": [ + { + "address": "test_instance.test[0]", + "mode": "managed", + "type": "test_instance", + "name": "test", + "index": 0, + "provider_name": "test", + "schema_version": 0, + "values": { + "ami": "bar", + "id": "placeholder" + } + } + ] + } + } + }, + "configuration": { + "root_module": { + "outputs": { + "test": { + "expression": { + "references": [ + "var.test_var" + ] + } + } + }, + "resources": [ + { + "address": "test_instance.test", + "mode": "managed", + "type": "test_instance", + "name": "test", + "provider_config_key": "test", + "expressions": { + "ami": { + "references": [ + "var.test_var" + ] + } + }, + "schema_version": 0, + "count_expression": { + "constant_value": 2 + } + } + ], + "variables": { + "test_var": { + "default": "bar" + } + } + } + } +} diff --git a/command/testdata/show-json/multi-resource-update/terraform.tfstate b/command/testdata/show-json/multi-resource-update/terraform.tfstate new file mode 100644 index 000000000000..f68865a9ba57 --- /dev/null +++ b/command/testdata/show-json/multi-resource-update/terraform.tfstate @@ -0,0 +1,24 @@ +{ + "version": 4, + "terraform_version": "0.12.0", + "serial": 7, + "lineage": "configuredUnchanged", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "test_instance", + "name": "test", + "provider": "provider[\"registry.terraform.io/-/test\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "ami": "bar", + "id": "placeholder" + } + } + ] + } + ] +}