terraform-provider-akamai
terraform-provider-akamai copied to clipboard
TF Panic on akamai_property_rules_template - see stack trace included
Hi,
I seem to be running into this problem, and I can't seem to figure out why. I'll save you the details of everything I tried to come up with a solution. I'm hoping you can look at this stack trace and give me an idea of where to look. I looked at the code, and it seems like it might be related to the length of a string as part of a line-ending check, although my Go is not strong at all. I am just using template_file in my akamai_property_rules_template datasource. I've checked the obvious (path exists, etc.,) and can't seem to figure this one out.
Thanks in advance for any help you can provide.
Tom
Stack trace from the terraform-provider-akamai_v2.1.1 plugin:
panic: runtime error: index out of range [-1]
goroutine 14 [running]: github.com/akamai/terraform-provider-akamai/v2/pkg/providers/property.stringToTemplate({0x0, 0x0}) github.com/akamai/terraform-provider-akamai/v2/pkg/providers/property/data_akamai_property_rules_template.go:320 +0x510 github.com/akamai/terraform-provider-akamai/v2/pkg/providers/property.convertToTemplate({0xc0157c69c0, 0xc0157f8700}) github.com/akamai/terraform-provider-akamai/v2/pkg/providers/property/data_akamai_property_rules_template.go:334 +0xb4 github.com/akamai/terraform-provider-akamai/v2/pkg/providers/property.dataAkamaiPropertyRulesRead({0x10e2238, 0xc0157a0180}, 0x7f8c0e2595b8, {0xe88020, 0xc0002dfbc0}) github.com/akamai/terraform-provider-akamai/v2/pkg/providers/property/data_akamai_property_rules_template.go:217 +0x13fe github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc0016f5c00, {0x10e2238, 0xc0157a0180}, 0xc0157aa630, {0xe88020, 0xc0002dfbc0}) github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:347 +0x12e github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ReadDataApply(0xc0016f5c00, {0x10e2238, 0xc0157a0180}, 0xc01579e1c0, {0xe88020, 0xc0002dfbc0}) github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:558 +0xf7 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadDataSource(0xc0156de690, {0x10e2238, 0xc0157a0180}, 0xc01579e020) github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1105 +0x32c github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ReadDataSource(0xc00007e8e0, {0x10e22e0, 0xc0157aa000}, 0xc000516140) github.com/hashicorp/[email protected]/tfprotov5/server/server.go:247 +0x1db github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadDataSource_Handler({0xf12f60, 0xc00007e8e0}, {0x10e22e0, 0xc0157aa000}, 0xc0002804e0, 0x0) github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:416 +0x170 google.golang.org/grpc.(*Server).processUnaryRPC(0xc000272700, {0x10f66f0, 0xc0001e8480}, 0xc0156c2480, 0xc0156e0d50, 0x170fbb0, 0x0) google.golang.org/[email protected]/server.go:1286 +0xc8f google.golang.org/grpc.(*Server).handleStream(0xc000272700, {0x10f66f0, 0xc0001e8480}, 0xc0156c2480, 0x0) google.golang.org/[email protected]/server.go:1609 +0xa2a google.golang.org/grpc.(*Server).serveStreams.func1.2() google.golang.org/[email protected]/server.go:934 +0x98 created by google.golang.org/grpc.(*Server).serveStreams.func1 google.golang.org/[email protected]/server.go:932 +0x294
Error: The terraform-provider-akamai_v2.1.1 plugin crashed!
This is always indicative of a bug within the plugin. It would be immensely helpful if you could report the crash with the plugin's maintainers so that it can be fixed. The output above should help diagnose the issue.
Hi @hypnotisttom ,
Thank you for your report, this quite probably is our fault :-) could you please add your .tf
configuration for easier debugging from our side? Thank you.
Kind regards,
Roberto
That is the tricky part, Roberto. I have two what I thought were identical TF projects except for names for the property, cert, etc., and yet one of them is producing this error if the data source is included. I am trying to figure out what's causing it, as I don't see any deltas. I presume what I give you won't actually cause the issue on your side, as it hasn't caused issues for me in other TF projects either.
I even removed the includes from my main.json to simplify things...
{
"ruleFormat": "v2021-09-22",
"rules": {
"name": "default",
"children": [],
"behaviors": [],
"options": {
"is_secure": true
},
"variables": [],
"comments": "The Default Rule template contains all the necessary and recommended behaviors. Rules are evaluated from top to bottom and the last matching rule wins."
}
}
And I took the variables out of the data source so that the only thing is...
data "akamai_property_rules_template" "akarules" {
template_file = abspath("${path.module}/rule_trees/${var.rule_tree_identifier}/property-snippets/main.json")
}
In this particular TF project, if I remove the data source, the error goes away.
This all started when I had spaces in an EW name as part of a template, which caused the original provisioning to error out. I have since deleted the state file, changed the akamai object names so as to create all new stuff, etc., all to start over, yet it still occurs. There must be something obvious that I'm missing here (and it might be user error on my side).
Any insight you have regarding what would cause that index out of bounds error, please do let me know.
I hope what I sent above is helpful. If you need anything else, please let me know.
Thanks!
Tom
Turned out I started hitting this with the newer TF projects, so that gave me something to compare against.
To reproduce this issue, place a file in the property-snippets directory that is an empty file, which is technically not valid JSON.
Inside property-snippets, I have a property_specific directory that I added a .gitkeep to so that if there are no rules unique to the specific property (compared to global rules applied to all properties via CI/CD), the directory would still exist in the template.
I was now testing more of the CI/CD and less of the local-to-the-property type configuration.
So, yes, it was an error on my side. However, if you want to either a) only read files in property-snippets that end in .json, or b) validate that each file is valid json, that would prevent this panic. Even if you check for ending in .json, we probably should check the files pass a json lint before expecting them to be valid json.
For me to resolve the issue, I added a []
to my .gitkeep. :-)
Oh, thank you. Although it might not be a valid JSON, I think we should handle this properly (either validating the user input, or handling that panic before it happens). I will forward to the team to get this fixed as soon as possible.
This issue has been addressed in the latest release https://github.com/akamai/terraform-provider-akamai/releases/tag/v2.3.0