{"record":{"id":"6921369cb4873c3f","repo":"kubernetes/kops","slug":"error-rendering-instance-userdata-v","errorCode":null,"errorMessage":"error rendering Instance UserData: %v","messagePattern":"error rendering Instance UserData: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awstasks/instance.go","lineNumber":272,"sourceCode":"\n\t\t// Build up the actual block device mappings\n\t\t// TODO: Support RootVolumeType & RootVolumeSize (see launchconfiguration)\n\t\tblockDeviceMappings, err := buildEphemeralDevices(t.Cloud, e.InstanceType)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif len(blockDeviceMappings) != 0 {\n\t\t\trequest.BlockDeviceMappings = []ec2types.BlockDeviceMapping{}\n\t\t\tfor deviceName, bdm := range blockDeviceMappings {\n\t\t\t\trequest.BlockDeviceMappings = append(request.BlockDeviceMappings, bdm.ToEC2(deviceName))\n\t\t\t}\n\t\t}\n\n\t\tif e.UserData != nil {\n\t\t\td, err := fi.ResourceAsBytes(e.UserData)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error rendering Instance UserData: %v\", err)\n\t\t\t}\n\t\t\tif len(d) > MaxUserDataSize {\n\t\t\t\t// TODO: Re-enable gzip?\n\t\t\t\t// But it exposes some bugs in the AWS console, so if we can avoid it, we should\n\t\t\t\t//d, err = fi.GzipBytes(d)\n\t\t\t\t//if err != nil {\n\t\t\t\t//\treturn fmt.Errorf(\"error while gzipping UserData: %v\", err)\n\t\t\t\t//}\n\t\t\t\treturn fmt.Errorf(\"Instance UserData was too large (%d bytes)\", len(d))\n\t\t\t}\n\t\t\trequest.UserData = aws.String(base64.StdEncoding.EncodeToString(d))\n\t\t}\n\n\t\tif e.IAMInstanceProfile != nil {\n\t\t\trequest.IamInstanceProfile = &ec2types.IamInstanceProfileSpecification{\n\t\t\t\tName: e.IAMInstanceProfile.Name,\n\t\t\t}\n\t\t}","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/instance.go#L254-L290","documentation":"Instance.RenderAWS reads the task's UserData resource fully into memory via fi.ResourceAsBytes before base64-encoding it into the RunInstances request. If reading the resource fails (unreadable file, broken resource implementation, I/O error), kOps wraps the failure as 'error rendering Instance UserData'. The instance is not created in this case.","triggerScenarios":"RunInstances-time rendering of an Instance task whose e.UserData resource cannot be read: missing file path in a file resource, permission denied, or a custom fi.Resource whose Bytes() returns an error.","commonSituations":"A bootstrap script path referenced in the cluster spec no longer exists or is unreadable; manifests using generated/template resources whose backing data failed to load; permission issues after running kops from a different user or container; packaging a nodeup/igconfig resource that errors on read.","solutions":["Check that the UserData source (file path or template) exists and is readable by the user running kops.","Run `kops update cluster --v=8` to see the underlying wrapped I/O error and fix the specific resource.","If using templates/assets, regenerate them (`kops create instancegroup` / update manifests) so the resource is valid.","Verify file permissions (chmod/chown) or copy the script into the repo and use a relative path.","Test rendering with a minimal inline UserData to isolate the failing resource."],"exampleFix":"# before\nkops edit cluster  # igconfig userData: file:///etc/kubernetes/bootstrap-old.sh  (file deleted)\n# after\nkops edit cluster  # igconfig userData: file:///etc/kubernetes/bootstrap.sh (exists, chmod 644)\nkops update cluster","handlingStrategy":"validation","validationCode":"// Verify the UserData source is readable before running kops update\npath := \"/etc/kubernetes/bootstrap.sh\"\nf, err := os.Open(path)\nif err != nil {\n\treturn fmt.Errorf(\"userData source unreadable: %w\", err)\n}\nf.Close()\n// For custom fi.Resource implementations, dry-run Bytes() first\nif r, ok := userDataResource.(interface{ Bytes() ([]byte, error) }); ok {\n\tif _, err := r.Bytes(); err != nil {\n\t\treturn fmt.Errorf(\"userData resource fails to render: %w\", err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"err := runKopsUpdate(ctx)\nif err != nil && strings.Contains(err.Error(), \"error rendering Instance UserData\") {\n\treturn fmt.Errorf(\"check userData file paths/permissions in the cluster spec: %w\", err)\n}\nreturn err","preventionTips":["Reference userData files with paths that exist in the environment running kops (containers mount them too).","Keep bootstrap scripts in the repo and use relative paths so they travel with the config.","Run `kops update cluster` in CI against a copy of the spec to catch missing assets early.","Check file permissions when switching users/CI runners."],"tags":["aws","ec2","userdata","io","resource"],"backgroundTag":"resource-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"}