Fix bug where range variable is improperly dereferenced (#217)

* Fix bug where range variable is improperly dereferenced

* Add comment explaining why a value is copied
This commit is contained in:
Joe Selman 2017-07-19 13:19:27 -07:00 committed by GitHub
parent 6c27e076ce
commit 8f75c1c9a5

View File

@ -103,7 +103,10 @@ func expandComputeMetadata(m map[string]string) []*compute.MetadataItems {
idx := 0
for key, value := range m {
metadata[idx] = &compute.MetadataItems{Key: key, Value: &value}
// 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++
}