kubernetes/kops · error

error rendering DO file: %w

Error message

error rendering DO file: %w

What it means

In RenderTerraform's DigitalOcean branch, AddFileBytes registers a digitalocean_spaces_bucket_object resource with the Terraform writer. This error wraps any failure of that registration — schema/validation problems in the Terraform model, duplicate resource names, or writer-level errors. It indicates the DO Spaces object could not be modeled in the generated Terraform.

Source

Thrown at util/pkg/vfs/s3fs.go:714

	Key     string                   `json:"key" cty:"key"`
	Content *terraformWriter.Literal `json:"content,omitempty" cty:"content"`
}

func (p *S3Path) RenderTerraform(w *terraformWriter.TerraformWriter, name string, data io.Reader, acl ACL) error {
	ctx := context.TODO()

	bytes, err := io.ReadAll(data)
	if err != nil {
		return fmt.Errorf("reading data: %v", err)
	}

	// render DO's terraform
	switch p.scheme {
	case "do":

		content, err := w.AddFileBytes("digitalocean_spaces_bucket_object", name, "content", bytes, false)
		if err != nil {
			return fmt.Errorf("error rendering DO file: %w", err)
		}

		// retrieve space region from endpoint
		endpoint := os.Getenv("S3_ENDPOINT")
		if endpoint == "" {
			return errors.New("S3 Endpoint is empty")
		}
		region := strings.Split(endpoint, ".")[0]

		tf := &terraformDOFile{
			Bucket:  p.Bucket(),
			Region:  region,
			Key:     p.Key(),
			Content: content,
		}
		return w.RenderResource("digitalocean_spaces_bucket_object", name, tf)

		// render Scaleway's Terraform objects

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Inspect the wrapped error from AddFileBytes — for name collisions, ensure each object gets a unique Terraform resource name.
  2. Sanitize the 'name' argument to a valid Terraform resource identifier (letters, digits, underscores).
  3. Regenerate with the correct target (kops update cluster --target terraform) so the DO branch is exercised with valid inputs.
  4. If it's a schema error from the writer, update kops / terraformWriter to a version matching your cluster spec.

Example fix

// before
name := "cluster.example.com-config" // contains dots
// after
name := strings.NewReplacer(".", "_", "/", "_").Replace("cluster.example.com-config")
Defensive patterns

Strategy: validation

Validate before calling

// sanitize the resource name before rendering
validName := regexp.MustCompile(`[^A-Za-z0-9_]`).ReplaceAllString(name, "_")
if validName == "" || regexp.MustCompile(`^[0-9]`).MatchString(validName) { return errors.New("invalid terraform resource name") }

Type guard

func isValidTerraformName(s string) bool {
    re := regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_-]*$`)
    return re.MatchString(s)
}

Try / catch

err := p.RenderTerraform(w, name, data, acl)
if err != nil && strings.Contains(err.Error(), "error rendering DO file") {
    return fmt.Errorf("DO spaces object %q rejected by terraform writer: %w", name, err)
}

Prevention

When it happens

Trigger: Calling RenderTerraform with p.scheme == "do" when w.AddFileBytes fails: invalid resource name characters, conflicting/duplicate resource names, or an internal TerraformWriter validation failure.

Common situations: kops clusters with DigitalOcean state stores generating out-of-target Terraform; name collisions when multiple objects map to the same resource name; upstream terraformWriter version drift.

Related errors


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