From 21c902813c017c393bb5da4e74928f003d48066b Mon Sep 17 00:00:00 2001 From: Joe Selman Date: Wed, 19 Jul 2017 11:10:33 -0700 Subject: [PATCH 1/2] Fix bug where range variable is improperly dereferenced --- google/metadata.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google/metadata.go b/google/metadata.go index 7e20e58f134..bbb2e100b14 100644 --- a/google/metadata.go +++ b/google/metadata.go @@ -103,7 +103,8 @@ func expandComputeMetadata(m map[string]string) []*compute.MetadataItems { idx := 0 for key, value := range m { - metadata[idx] = &compute.MetadataItems{Key: key, Value: &value} + vtmp := value + metadata[idx] = &compute.MetadataItems{Key: key, Value: &vtmp} idx++ } From 3e007cfafcf65e555885d0b1989cad7e2b3782d5 Mon Sep 17 00:00:00 2001 From: Joe Selman Date: Wed, 19 Jul 2017 13:08:16 -0700 Subject: [PATCH 2/2] Add comment explaining why a value is copied --- google/metadata.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/google/metadata.go b/google/metadata.go index bbb2e100b14..5dc63a67185 100644 --- a/google/metadata.go +++ b/google/metadata.go @@ -103,6 +103,8 @@ func expandComputeMetadata(m map[string]string) []*compute.MetadataItems { idx := 0 for key, value := range m { + // Make a copy of value as we need a ptr type; if we directly use 'value' then all items will reference the same + // memory address vtmp := value metadata[idx] = &compute.MetadataItems{Key: key, Value: &vtmp} idx++