{"record":{"id":"b018dc0f2c6fadaf","repo":"kubernetes/kops","slug":"error-rendering-do-file-w","errorCode":null,"errorMessage":"error rendering DO file: %w","messagePattern":"error rendering DO file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/vfs/s3fs.go","lineNumber":714,"sourceCode":"\tKey     string                   `json:\"key\" cty:\"key\"`\n\tContent *terraformWriter.Literal `json:\"content,omitempty\" cty:\"content\"`\n}\n\nfunc (p *S3Path) RenderTerraform(w *terraformWriter.TerraformWriter, name string, data io.Reader, acl ACL) error {\n\tctx := context.TODO()\n\n\tbytes, err := io.ReadAll(data)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"reading data: %v\", err)\n\t}\n\n\t// render DO's terraform\n\tswitch p.scheme {\n\tcase \"do\":\n\n\t\tcontent, err := w.AddFileBytes(\"digitalocean_spaces_bucket_object\", name, \"content\", bytes, false)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error rendering DO file: %w\", err)\n\t\t}\n\n\t\t// retrieve space region from endpoint\n\t\tendpoint := os.Getenv(\"S3_ENDPOINT\")\n\t\tif endpoint == \"\" {\n\t\t\treturn errors.New(\"S3 Endpoint is empty\")\n\t\t}\n\t\tregion := strings.Split(endpoint, \".\")[0]\n\n\t\ttf := &terraformDOFile{\n\t\t\tBucket:  p.Bucket(),\n\t\t\tRegion:  region,\n\t\t\tKey:     p.Key(),\n\t\t\tContent: content,\n\t\t}\n\t\treturn w.RenderResource(\"digitalocean_spaces_bucket_object\", name, tf)\n\n\t\t// render Scaleway's Terraform objects","sourceCodeStart":696,"sourceCodeEnd":732,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/vfs/s3fs.go#L696-L732","documentation":"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.","triggerScenarios":"Calling RenderTerraform with p.scheme == \"do\" when w.AddFileBytes fails: invalid resource name characters, conflicting/duplicate resource names, or an internal TerraformWriter validation failure.","commonSituations":"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.","solutions":["Inspect the wrapped error from AddFileBytes — for name collisions, ensure each object gets a unique Terraform resource name.","Sanitize the 'name' argument to a valid Terraform resource identifier (letters, digits, underscores).","Regenerate with the correct target (kops update cluster --target terraform) so the DO branch is exercised with valid inputs.","If it's a schema error from the writer, update kops / terraformWriter to a version matching your cluster spec."],"exampleFix":"// before\nname := \"cluster.example.com-config\" // contains dots\n// after\nname := strings.NewReplacer(\".\", \"_\", \"/\", \"_\").Replace(\"cluster.example.com-config\")","handlingStrategy":"validation","validationCode":"// sanitize the resource name before rendering\nvalidName := regexp.MustCompile(`[^A-Za-z0-9_]`).ReplaceAllString(name, \"_\")\nif validName == \"\" || regexp.MustCompile(`^[0-9]`).MatchString(validName) { return errors.New(\"invalid terraform resource name\") }","typeGuard":"func isValidTerraformName(s string) bool {\n    re := regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_-]*$`)\n    return re.MatchString(s)\n}","tryCatchPattern":"err := p.RenderTerraform(w, name, data, acl)\nif err != nil && strings.Contains(err.Error(), \"error rendering DO file\") {\n    return fmt.Errorf(\"DO spaces object %q rejected by terraform writer: %w\", name, err)\n}","preventionTips":["Use unique, identifier-safe names per rendered object to avoid collisions.","Run with --target terraform when working with DO state stores so the DO branch is exercised.","Keep kops and its terraformWriter versions in sync with your cluster spec.","Validate generated Terraform with terraform validate in CI after kops update cluster."],"tags":["terraform","digitalocean","rendering","spaces"],"backgroundTag":"terraform-render-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"}