{"record":{"id":"0940bfe2d42d1825","repo":"kubernetes/kops","slug":"error-decoding-userdata-s","errorCode":null,"errorMessage":"error decoding userdata: %s","messagePattern":"error decoding userdata: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go","lineNumber":312,"sourceCode":"\t\t\tactual.RootVolumeType = b.Ebs.VolumeType\n\t\t\tactual.RootVolumeIops = b.Ebs.Iops\n\t\t\tactual.RootVolumeThroughput = b.Ebs.Throughput\n\t\t\tactual.RootVolumeEncryption = b.Ebs.Encrypted\n\t\t\tif b.Ebs.KmsKeyId != nil {\n\t\t\t\tactual.RootVolumeKmsKey = b.Ebs.KmsKeyId\n\t\t\t} else {\n\t\t\t\tactual.RootVolumeKmsKey = new(\"\")\n\t\t\t}\n\t\t} else {\n\t\t\t_, d := BlockDeviceMappingFromLaunchTemplateBootDeviceRequest(b)\n\t\t\tactual.BlockDeviceMappings = append(actual.BlockDeviceMappings, d)\n\t\t}\n\t}\n\n\tif lt.LaunchTemplateData.UserData != nil {\n\t\tud, err := base64.StdEncoding.DecodeString(aws.ToString(lt.LaunchTemplateData.UserData))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error decoding userdata: %s\", err)\n\t\t}\n\t\tactual.UserData = fi.NewStringResource(string(ud))\n\t}\n\n\t// @step: add tags\n\tif len(lt.LaunchTemplateData.TagSpecifications) > 0 {\n\t\tts := lt.LaunchTemplateData.TagSpecifications[0]\n\t\tif ts.Tags != nil {\n\t\t\ttags := mapEC2TagsToMap(ts.Tags)\n\t\t\tactual.Tags = tags\n\t\t}\n\t}\n\n\t// @step: add instance metadata options\n\tif options := lt.LaunchTemplateData.MetadataOptions; options != nil {\n\t\tactual.HTTPPutResponseHopLimit = options.HttpPutResponseHopLimit\n\t\tif len(options.HttpTokens) > 0 {\n\t\t\tactual.HTTPTokens = new(options.HttpTokens)","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/launchtemplate_target_api.go#L294-L330","documentation":"Find() decodes the UserData stored in an existing EC2 Launch Template from base64 into raw user data. EC2 stores UserData base64-encoded; this error means that stored value could not be decoded, which indicates corrupted or non-base64 data in the launch template. The Find operation aborts so the actual state cannot be compared with the desired state.","triggerScenarios":"lt.LaunchTemplateData.UserData is non-nil but its string is not valid base64 (e.g. manually edited launch template with plaintext UserData, or data corrupted by external tooling).","commonSituations":"Someone modified the launch template via AWS console/packer and supplied unencoded userdata; custom automation writing UserData without base64 encoding; data corruption from copy-paste.","solutions":["Inspect the launch template's UserData in the AWS console and re-encode it as base64","Let kOps recreate the launch template (kops update cluster --cloud-labels / replace task) so correct userdata is written","Validate any external tooling base64-encodes UserData before CreateLaunchTemplate","Check `echo '<stored>' | base64 -d` locally to confirm corruption"],"exampleFix":"// before (external tool)\nUserData: string(nodeUpConfig)\n// after\nUserData: base64.StdEncoding.EncodeToString(nodeUpConfig)","handlingStrategy":"validation","validationCode":"raw := aws.ToString(lt.LaunchTemplateData.UserData)\nif _, err := base64.StdEncoding.DecodeString(raw); err != nil {\n  return fmt.Errorf(\"launch template %s has non-base64 userdata\", name)\n}","typeGuard":"func isBase64(s string) bool {\n  _, err := base64.StdEncoding.DecodeString(s)\n  return err == nil\n}","tryCatchPattern":"ud, err := base64.StdEncoding.DecodeString(raw)\nif err != nil {\n  return nil, fmt.Errorf(\"error decoding userdata for %s (recreate the launch template): %w\", name, err)\n}","preventionTips":["Never edit launch template UserData manually with plaintext; always base64-encode","Let kOps manage userdata end-to-end","Validate base64 before CreateLaunchTemplate in external tooling"],"tags":["aws","ec2","launch-template","userdata","base64"],"backgroundTag":"base64-decode-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"}