From ac83827c903414b0bceb69c2aca609aec5a59b8b Mon Sep 17 00:00:00 2001 From: Masayuki Morita Date: Tue, 28 May 2019 23:56:09 +0900 Subject: [PATCH] states/statefile: decode backend hash as uint64 Fixes #21478 In #19688, `terraform.BackendState.Hash` was fixed. We also need to fix `states/statefile.backendStateV2.Hash` --- .../testdata/roundtrip/v3-bigint.in.tfstate | 136 ++++++++++++++++++ .../testdata/roundtrip/v3-bigint.out.tfstate | 97 +++++++++++++ states/statefile/version2.go | 2 +- 3 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 states/statefile/testdata/roundtrip/v3-bigint.in.tfstate create mode 100644 states/statefile/testdata/roundtrip/v3-bigint.out.tfstate diff --git a/states/statefile/testdata/roundtrip/v3-bigint.in.tfstate b/states/statefile/testdata/roundtrip/v3-bigint.in.tfstate new file mode 100644 index 000000000..eadc3e7c2 --- /dev/null +++ b/states/statefile/testdata/roundtrip/v3-bigint.in.tfstate @@ -0,0 +1,136 @@ +{ + "version": 3, + "terraform_version": "0.11.1", + "serial": 8, + "lineage": "0f5b2ff9-6ff5-8e9e-1f81-aa3ce9a483eb", + "backend": { + "hash": 10669755453527594976 + }, + "modules": [ + { + "path": [ + "root" + ], + "outputs": { + "results": { + "sensitive": false, + "type": "map", + "value": { + "aws_region": "us-west-2", + "list": "[{\"triggers\":{\"index\":\"0\"}},{\"triggers\":{\"index\":\"1\"}}]", + "list_item_0": "{\"triggers\":{\"index\":\"0\"}}", + "list_item_1": "{\"triggers\":{\"index\":\"1\"}}", + "list_triggers": "[{\"index\":\"0\"},{\"index\":\"1\"}]", + "list_triggers_item": "{\"index\":\"0\"}", + "module_object": "{\"test\":\"hello us-west-2\",\"test2\":\"hello world 2\"}", + "module_output": "hello us-west-2", + "single": "{\"triggers\":{\"baz\":\"BAR\",\"cwd_path\":\"/home/mart/Devel/terraform/tmp/hcl2-simple\",\"foo\":\"bar\",\"format\":\"Hello 12\",\"json\":\"{\\\"foo\\\":\\\"bar\\\",\\\"wonk\\\":[]}\",\"module_path\":\"/home/mart/Devel/terraform/tmp/hcl2-simple\",\"root_path\":\"/home/mart/Devel/terraform/tmp/hcl2-simple\",\"woot\":\"us-west-2\",\"workspace\":\"default\"}}" + } + } + }, + "resources": { + "null_resource.bar.0": { + "type": "null_resource", + "depends_on": [ + "null_resource.baz" + ], + "primary": { + "id": "604776346677326098", + "attributes": { + "id": "604776346677326098", + "triggers.%": "1", + "triggers.index": "0" + }, + "meta": { + "schema_version": "1" + }, + "tainted": false + }, + "deposed": [], + "provider": "provider.null" + }, + "null_resource.bar.1": { + "type": "null_resource", + "depends_on": [ + "null_resource.baz" + ], + "primary": { + "id": "4776432143683449212", + "attributes": { + "id": "4776432143683449212", + "triggers.%": "1", + "triggers.index": "1" + }, + "meta": {}, + "tainted": false + }, + "deposed": [], + "provider": "provider.null" + }, + "null_resource.baz": { + "type": "null_resource", + "depends_on": [], + "primary": { + "id": "1361331090091665738", + "attributes": { + "id": "1361331090091665738", + "triggers.%": "9", + "triggers.baz": "BAR", + "triggers.cwd_path": "/home/mart/Devel/terraform/tmp/hcl2-simple", + "triggers.foo": "bar", + "triggers.format": "Hello 12", + "triggers.json": "{\"foo\":\"bar\",\"wonk\":[]}", + "triggers.module_path": "/home/mart/Devel/terraform/tmp/hcl2-simple", + "triggers.root_path": "/home/mart/Devel/terraform/tmp/hcl2-simple", + "triggers.woot": "us-west-2", + "triggers.workspace": "default" + }, + "meta": { + "foo": "bar" + }, + "tainted": false + }, + "deposed": [], + "provider": "provider.null" + } + }, + "depends_on": [] + }, + { + "path": [ + "root", + "child" + ], + "outputs": { + "test": { + "sensitive": false, + "type": "string", + "value": "hello us-west-2" + }, + "test2": { + "sensitive": false, + "type": "string", + "value": "hello world 2" + } + }, + "resources": { + "null_resource.foo": { + "type": "null_resource", + "depends_on": [], + "primary": { + "id": "1361", + "attributes": { + "id": "1361", + "triggers.%": "0" + }, + "meta": {}, + "tainted": false + }, + "deposed": [], + "provider": "provider.null" + } + }, + "depends_on": [] + } + ] +} diff --git a/states/statefile/testdata/roundtrip/v3-bigint.out.tfstate b/states/statefile/testdata/roundtrip/v3-bigint.out.tfstate new file mode 100644 index 000000000..c5531f24c --- /dev/null +++ b/states/statefile/testdata/roundtrip/v3-bigint.out.tfstate @@ -0,0 +1,97 @@ +{ + "version": 4, + "terraform_version": "0.11.1", + "serial": 8, + "lineage": "0f5b2ff9-6ff5-8e9e-1f81-aa3ce9a483eb", + "outputs": { + "results": { + "type": [ + "map", + "string" + ], + "value": { + "aws_region": "us-west-2", + "list": "[{\"triggers\":{\"index\":\"0\"}},{\"triggers\":{\"index\":\"1\"}}]", + "list_item_0": "{\"triggers\":{\"index\":\"0\"}}", + "list_item_1": "{\"triggers\":{\"index\":\"1\"}}", + "list_triggers": "[{\"index\":\"0\"},{\"index\":\"1\"}]", + "list_triggers_item": "{\"index\":\"0\"}", + "module_object": "{\"test\":\"hello us-west-2\",\"test2\":\"hello world 2\"}", + "module_output": "hello us-west-2", + "single": "{\"triggers\":{\"baz\":\"BAR\",\"cwd_path\":\"/home/mart/Devel/terraform/tmp/hcl2-simple\",\"foo\":\"bar\",\"format\":\"Hello 12\",\"json\":\"{\\\"foo\\\":\\\"bar\\\",\\\"wonk\\\":[]}\",\"module_path\":\"/home/mart/Devel/terraform/tmp/hcl2-simple\",\"root_path\":\"/home/mart/Devel/terraform/tmp/hcl2-simple\",\"woot\":\"us-west-2\",\"workspace\":\"default\"}}" + } + } + }, + "resources": [ + { + "mode": "managed", + "type": "null_resource", + "name": "bar", + "each": "list", + "provider": "provider.null", + "instances": [ + { + "attributes_flat": { + "id": "604776346677326098", + "triggers.%": "1", + "triggers.index": "0" + }, + "depends_on": ["null_resource.baz"], + "index_key": 0, + "schema_version": 1 + }, + { + "attributes_flat": { + "id": "604776346677326098", + "triggers.%": "1", + "triggers.index": "0" + }, + "depends_on": ["null_resource.baz"], + "index_key": 1, + "schema_version": 0 + } + ] + }, + { + "mode": "managed", + "type": "null_resource", + "name": "baz", + "provider": "provider.null", + "instances": [ + { + "attributes_flat": { + "id": "1361331090091665738", + "triggers.%": "9", + "triggers.baz": "BAR", + "triggers.cwd_path": "/home/mart/Devel/terraform/tmp/hcl2-simple", + "triggers.foo": "bar", + "triggers.format": "Hello 12", + "triggers.json": "{\"foo\":\"bar\",\"wonk\":[]}", + "triggers.module_path": "/home/mart/Devel/terraform/tmp/hcl2-simple", + "triggers.root_path": "/home/mart/Devel/terraform/tmp/hcl2-simple", + "triggers.woot": "us-west-2", + "triggers.workspace": "default" + }, + "schema_version": 0, + "private": "eyJmb28iOiJiYXIifQ==" + } + ] + }, + { + "module": "module.child", + "mode": "managed", + "type": "null_resource", + "name": "foo", + "provider": "provider.null", + "instances": [ + { + "attributes_flat": { + "id": "1361", + "triggers.%": "0" + }, + "schema_version": 0 + } + ] + } + ] +} diff --git a/states/statefile/version2.go b/states/statefile/version2.go index 6fe2ab8ef..be93924a7 100644 --- a/states/statefile/version2.go +++ b/states/statefile/version2.go @@ -205,5 +205,5 @@ type instanceStateV2 struct { type backendStateV2 struct { Type string `json:"type"` // Backend type ConfigRaw json.RawMessage `json:"config"` // Backend raw config - Hash int `json:"hash"` // Hash of portion of configuration from config files + Hash uint64 `json:"hash"` // Hash of portion of configuration from config files }