{"record":{"id":"3943abeacacb47a0","repo":"kubernetes/kops","slug":"error-rendering-launchtemplate-userdata-v","errorCode":null,"errorMessage":"error rendering LaunchTemplate UserData: %v","messagePattern":"error rendering LaunchTemplate UserData: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go","lineNumber":133,"sourceCode":"\t\t}\n\t\tdata.TagSpecifications = append(data.TagSpecifications, ec2types.LaunchTemplateTagSpecificationRequest{\n\t\t\tResourceType: ec2types.ResourceTypeInstance,\n\t\t\tTags:         tags,\n\t\t})\n\t\tdata.TagSpecifications = append(data.TagSpecifications, ec2types.LaunchTemplateTagSpecificationRequest{\n\t\t\tResourceType: ec2types.ResourceTypeVolume,\n\t\t\tTags:         tags,\n\t\t})\n\t\tdata.TagSpecifications = append(data.TagSpecifications, ec2types.LaunchTemplateTagSpecificationRequest{\n\t\t\tResourceType: ec2types.ResourceTypeNetworkInterface,\n\t\t\tTags:         tags,\n\t\t})\n\t}\n\t// @step: add the userdata\n\tif t.UserData != nil {\n\t\td, err := fi.ResourceAsBytes(t.UserData)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error rendering LaunchTemplate UserData: %v\", err)\n\t\t}\n\t\tdata.UserData = aws.String(base64.StdEncoding.EncodeToString(d))\n\t}\n\t// @step: add market options\n\tif fi.ValueOf(t.SpotPrice) != \"\" {\n\t\ts := &ec2types.LaunchTemplateSpotMarketOptionsRequest{\n\t\t\tBlockDurationMinutes: t.SpotDurationInMinutes,\n\t\t\tMaxPrice:             t.SpotPrice,\n\t\t}\n\t\tif t.InstanceInterruptionBehavior != nil {\n\t\t\ts.InstanceInterruptionBehavior = fi.ValueOf(t.InstanceInterruptionBehavior)\n\t\t}\n\t\tdata.InstanceMarketOptions = &ec2types.LaunchTemplateInstanceMarketOptionsRequest{\n\t\t\tMarketType:  ec2types.MarketTypeSpot,\n\t\t\tSpotOptions: s,\n\t\t}\n\t}\n\tif fi.ValueOf(t.CPUCredits) != \"\" {","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go#L115-L151","documentation":"RenderAWS renders the task's UserData resource into bytes via fi.ResourceAsBytes(t.UserData) before base64-encoding it into the EC2 launch template. If the resource cannot be rendered (I/O error reading a file resource, template expansion failure), kOps wraps the failure as 'error rendering LaunchTemplate UserData'.","triggerScenarios":"RenderAWS where t.UserData != nil and fi.ResourceAsBytes fails - unreadable file backing the resource, failed templating/string expansion, or a nil/dead resource body.","commonSituations":"Custom nodeup/bootstrap script referenced by path that no longer exists; a templated userdata referencing missing values; broken addon/hook asset producing an invalid resource.","solutions":["Read the wrapped error to find which resource failed to render.","Verify any file-based userdata (hooks, file assets, custom nodeup script) exists and is readable on the machine running kops.","Re-run kops update to regenerate assets; if using templates, fix the template errors."],"exampleFix":"// before\nuserData: file:///etc/kops/missing-bootstrap.sh\n// after\nuserData: file:///etc/kops/bootstrap.sh  // file exists and readable","handlingStrategy":"validation","validationCode":"// ensure referenced userdata files exist and render before apply\nfor f in $(kops get ig -o yaml | yq '.spec.hooks[].execContainer.command[0]' 2>/dev/null); do test -r \"$f\" || echo \"missing: $f\"; done","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"error rendering LaunchTemplate UserData\") { fix the unreadable/invalid resource named in the wrapped error and re-apply }","preventionTips":["Keep userdata/hook assets committed next to the cluster config.","Test templated userdata rendering locally before applying.","Regenerate assets with kops update after editing scripts."],"tags":["aws","launch-template","userdata"],"backgroundTag":"userdata-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"}