{"record":{"id":"2f24a5c6ec12b357","repo":"kubernetes/kops","slug":"reading-data-v-2f24a5","errorCode":null,"errorMessage":"reading data: %v","messagePattern":"reading data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/vfs/memfs.go","lineNumber":249,"sourceCode":"\tBucket   string                   `json:\"bucket\" cty:\"bucket\"`\n\tKey      string                   `json:\"key\" cty:\"key\"`\n\tContent  *terraformWriter.Literal `json:\"content,omitempty\" cty:\"content\"`\n\tAcl      *string                  `json:\"acl,omitempty\" cty:\"acl\"`\n\tSSE      string                   `json:\"server_side_encryption,omitempty\" cty:\"server_side_encryption\"`\n\tProvider *terraformWriter.Literal `json:\"provider,omitempty\" cty:\"provider\"`\n}\n\nfunc (p *MemFSPath) RenderTerraform(w *terraformWriter.TerraformWriter, name string, data io.Reader, acl ACL) error {\n\tif w.Providers != nil && w.Providers[\"azurerm\"] != nil {\n\t\treturn p.renderTerraformAzure(w, name, data)\n\t}\n\treturn p.renderTerraformS3(w, name, data, acl)\n}\n\nfunc (p *MemFSPath) renderTerraformAzure(w *terraformWriter.TerraformWriter, name string, data io.Reader) error {\n\tbytes, err := io.ReadAll(data)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"reading data: %v\", err)\n\t}\n\n\tsource, err := w.AddFilePath(\"azurerm_storage_blob\", name, \"source\", bytes, false)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"rendering Azure Blob file: %w\", err)\n\t}\n\n\t// memfs:// paths don't encode an Azure account or container, so this\n\t// fallback (only used in integration tests) hard-codes a test placeholder\n\t// container on the storage account from the cluster spec.\n\ttf := &terraformAzureBlobFile{\n\t\tName:               p.location,\n\t\tStorageContainerID: w.AzureStorageAccountID + \"/blobServices/default/containers/testcontainer\",\n\t\tType:               \"Block\",\n\t\tSource:             source,\n\t\tProvider:           terraformWriter.LiteralTokens(\"azurerm\", \"files\"),\n\t}\n\treturn w.RenderResource(\"azurerm_storage_blob\", name, tf)","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/vfs/memfs.go#L231-L267","documentation":"During terraform output rendering for Azure, MemFSPath.renderTerraformAzure reads the whole file content from the given io.Reader. Any read failure is wrapped as 'reading data: %v' and aborts rendering that blob.","triggerScenarios":"Calling RenderTerraform on a memfs path backed by Azure with an io.Reader (from the stored file/write path) that errors mid-read — typically a closed or already-consumed reader.","commonSituations":"Integration tests rendering terraform for Azure-targeted mock clusters where the source data reader was reused after a previous render consumed it.","solutions":["Recreate the reader before rendering (Seek to 0 for ReadSeekers, or re-open the source)","Inspect the wrapped error to identify the underlying read failure and fix the reader lifecycle","Ensure each render pass gets fresh bytes (e.g. keep the raw []byte and pass bytes.NewReader each time)"],"exampleFix":"// before\nr, _ := getReader(); render(r); render(r) // second call: reader consumed\n// after\nif s, ok := r.(io.Seeker); ok { s.Seek(0, io.SeekStart) }\nrender(ctx, w, r)","handlingStrategy":"validation","validationCode":"if rs, ok := data.(io.Seeker); ok { if _, err := rs.Seek(0, io.SeekStart); err != nil { return err } }","typeGuard":"null","tryCatchPattern":"if err := p.RenderTerraform(w, name, data, nil); err != nil {\n    if strings.HasPrefix(err.Error(), \"reading data:\") { /* recreate reader and re-render */ }\n    return err\n}","preventionTips":["Keep raw []byte around and wrap in bytes.NewReader per render","Seek readers to 0 before each render pass","Avoid rendering from network-backed readers that can error mid-read"],"tags":["vfs","memfs","terraform","azure","io"],"backgroundTag":"read-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}