Description
Terraform Core Version
1.4.0
AWS Provider Version
5.1.0
Affected Resource(s)
- aws_ecs_task_definition
Expected Behavior
It should add an environment variable if it's value is not null, else ignore it :
environment = [
{
name = "ENV_VAR1"
value = var.value1
},
var.ENV_VAR2 != null ? {
name = "ENV_VAR2"
value = var.value2
} : null
]
Actual Behavior
Stack trace from the terraform-provider-aws_v4.67.0_x5 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa4dd396]
Error: The terraform-provider-aws_v4.67.0_x5 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.
Relevant Error/Panic Output Snippet
Error: Plugin did not respond
│
│ with aws_alb_target_group.depTargetGroup,
│ on lb_resources.tf line 29, in resource "aws_alb_target_group" "TargetGroup":
│ 29: resource "aws_alb_target_group" "TargetGroup" {
│
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more
│ details.
╵
╷
│ Error: Request cancelled
│
│ with aws_alb.depDB_NLB,
│ on lb_resources.tf line 45, in resource "aws_alb" "NLB":
│ 45: resource "aws_alb" "NLB" {
│
│ The plugin.(*GRPCProvider).ReadResource request was cancelled.
╵
╷
│ Error: Request cancelled
│
│ with aws_security_group.sgEFS,
│ on securitygroup.tf line 102, in resource "aws_security_group" "EFS":
│ 102: resource "aws_security_group" "EFS" {
│
│ The plugin.(*GRPCProvider).ReadResource request was cancelled.
╵
Releasing state lock. This may take a few moments...
Stack trace from the terraform-provider-aws_v4.67.0_x5 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa4dd396]
goroutine 1045 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/ecs.containerDefinitions.OrderEnvironmentVariables.func1(0xc005059d88?, 0xc008260c50?)
github.com/hashicorp/terraform-provider-aws/internal/service/ecs/task_definition_equivalency.go:108 +0x36
sort.insertionSort_func({0xc004176848?, 0xc0050f4be0?}, 0x0, 0x9)
sort/zsortfunc.go:12 +0xb1
sort.pdqsort_func({0xc004176848?, 0xc0050f4be0?}, 0xc005059d88?, 0x0?, 0xc0079c93b0?)
sort/zsortfunc.go:73 +0x345
sort.Slice({0xbbdbde0, 0xc005059d88}, 0x9?)
sort/slice.go:23 +0x97
github.com/hashicorp/terraform-provider-aws/internal/service/ecs.containerDefinitions.OrderEnvironmentVariables({0xc0050f4b60, 0x1, 0xbda1480?})
github.com/hashicorp/terraform-provider-aws/internal/service/ecs/task_definition_equivalency.go:107 +0x85
github.com/hashicorp/terraform-provider-aws/internal/service/ecs.ResourceTaskDefinition.func2({0xbda1480?, 0xc0056d2a50?})
github.com/hashicorp/terraform-provider-aws/internal/service/ecs/task_definition.go:83 +0x52
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.diffString(0xc000680000?, {0xe85b0ee, 0x15}, 0xc00117aa00, 0xc004176ad8, {0xfcae850, 0xc0055e6980}, 0x0)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:1550 +0x103
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.diff(0x6?, {0xfca11c0, 0xc005206060}, {0xe85b0ee, 0x15}, 0xc00117aa00, 0xc0055e6900, {0xfcae850?, 0xc0055e6980}, 0x0)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:1129 +0x16b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.Diff(0xc0011762a0, {0xfca11c0, 0xc005206060}, 0xc00827fe10, 0xc0052105d0, 0xc0010fa9a8, {0xe78cb00, 0xc0003f0c00}, 0x0)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/schema.go:679 +0x353
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).SimpleDiff(0xfca22d0?, {0xfca11c0?, 0xc005206060?}, 0xc00827fe10, 0xca76e80?, {0xe78cb00?, 0xc0003f0c00?})
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:890 +0x6c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange(0xc002801698, {0xfca11c0?, 0xc0051e4240?}, 0xc004945130)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:741 +0x9c9
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.PlanResourceChange({0xc004097380, 0xc0040973e0, {0xc004729ea0, 0x2, 0x2}, {0x0, 0x0, 0x0}, {0x0, 0x0, ...}, ...}, ...)
github.com/hashicorp/[email protected]/tf5muxserver/mux_server_PlanResourceChange.go:56 +0x1d8
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).PlanResourceChange(0xc0034fabe0, {0xfca11c0?, 0xc0051e14d0?}, 0xc002aaf810)
github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:783 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_PlanResourceChange_Handler({0xe4780c0?, 0xc0034fabe0}, {0xfca11c0, 0xc0051e14d0}, 0xc002aaf7a0, 0x0)
github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:401 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0048ea1e0, {0xfcb1a60, 0xc0058da680}, 0xc004ff07e0, 0xc0059698f0, 0x168fe688, 0x0)
google.golang.org/[email protected]/server.go:1345 +0xdf0
google.golang.org/grpc.(*Server).handleStream(0xc0048ea1e0, {0xfcb1a60, 0xc0058da680}, 0xc004ff07e0, 0x0)
google.golang.org/[email protected]/server.go:1722 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.2()
google.golang.org/[email protected]/server.go:966 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
google.golang.org/[email protected]/server.go:964 +0x28a
Error: The terraform-provider-aws_v4.67.0_x5 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.
Terraform Configuration Files
variable "ENV_VAR2" {
description = "optional Environment var"
type = string
default = null
}
resource "aws_ecs_task_definition" "SampleTDF" {
family = "xyz"
requires_compatibilities = ["FARGATE"]
cpu = 1024
memory = 4096
network_mode = "awsvpc"
execution_role_arn = "${local.ecsTaskExecutionRole}"
container_definitions = jsonencode([
{
name = "xxxx"
image = "xxxx"
essential = true
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/abcd"
awslogs-region = "${var.region}"
awslogs-stream-prefix = "ecs"
}
}
cpu = 0
environment = [
{
name = "ENV_VAR1"
value = var.ENV_VAR1
},
var.ENV_VAR2 != null ? {
name = "ENV_VAR2"
value = var.ENV_VAR2
} : null
]
ulimits = null
}])
}
Steps to Reproduce
run terraform plan
/ terraform apply
Debug Output
No response
Panic Output
No response
Important Factoids
This error only comes when I keep the variable value as null.
I want this environment variable to be added only if my variable is not null.
References
Would you like to implement a fix?
None