kubernetes/kops · error

rendering Azure Blob file: %w

Error message

rendering Azure Blob file: %w

What it means

After reading the bytes, renderTerraformAzure registers the blob content with the TerraformWriter via AddFilePath for resource azurerm_storage_blob. This error wraps any failure returned by that writer call (e.g. duplicate resource name or internal writer error).

Source

Thrown at util/pkg/vfs/memfs.go:254

	Provider *terraformWriter.Literal `json:"provider,omitempty" cty:"provider"`
}

func (p *MemFSPath) RenderTerraform(w *terraformWriter.TerraformWriter, name string, data io.Reader, acl ACL) error {
	if w.Providers != nil && w.Providers["azurerm"] != nil {
		return p.renderTerraformAzure(w, name, data)
	}
	return p.renderTerraformS3(w, name, data, acl)
}

func (p *MemFSPath) renderTerraformAzure(w *terraformWriter.TerraformWriter, name string, data io.Reader) error {
	bytes, err := io.ReadAll(data)
	if err != nil {
		return fmt.Errorf("reading data: %v", err)
	}

	source, err := w.AddFilePath("azurerm_storage_blob", name, "source", bytes, false)
	if err != nil {
		return fmt.Errorf("rendering Azure Blob file: %w", err)
	}

	// memfs:// paths don't encode an Azure account or container, so this
	// fallback (only used in integration tests) hard-codes a test placeholder
	// container on the storage account from the cluster spec.
	tf := &terraformAzureBlobFile{
		Name:               p.location,
		StorageContainerID: w.AzureStorageAccountID + "/blobServices/default/containers/testcontainer",
		Type:               "Block",
		Source:             source,
		Provider:           terraformWriter.LiteralTokens("azurerm", "files"),
	}
	return w.RenderResource("azurerm_storage_blob", name, tf)
}

func (p *MemFSPath) renderTerraformS3(w *terraformWriter.TerraformWriter, name string, data io.Reader, acl ACL) error {
	bytes, err := io.ReadAll(data)
	if err != nil {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check the wrapped error from AddFilePath; if it reports a duplicate, make the resource 'name' unique per path
  2. Ensure RenderTerraform is not invoked twice over the same writer with identical names without a fresh writer
  3. Inspect the terraformWriter implementation for the exact rejection reason and fix the caller accordingly

Example fix

// before
w.AddFilePath("azurerm_storage_blob", name, "source", bytes, false) // name duplicates another resource
// after
uniqueName := strings.ReplaceAll(strings.TrimPrefix(string(p), "memfs://"), "/", "__")
w.AddFilePath("azurerm_storage_blob", uniqueName, "source", bytes, false)
Defensive patterns

Strategy: validation

Validate before calling

if name == "" || seen[name] { name = uniquify(name) }; seen[name] = true

Type guard

null

Try / catch

if err := p.RenderTerraform(w, name, data, nil); err != nil {
    if strings.Contains(err.Error(), "rendering Azure Blob file") {
        klog.Errorf("terraform blob add failed for %s: %v", name, err)
    }
    return err
}

Prevention

When it happens

Trigger: RenderTerraform -> renderTerraformAzure where w.AddFilePath rejects the file — commonly because two files render under the same resource name, or the writer's internal map/lock rejects the add.

Common situations: Azure terraform output tests where multiple memfs paths collide on the same 'name' argument; bugs in caller-provided naming producing duplicate terraform resources.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/9ca85812f49398ec. Report an issue: GitHub.