From d4d39e0be56d7bff59d3a04ce232cf876c43945f Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 15 Aug 2024 10:30:00 -0400 Subject: [PATCH] r/aws_ecs_service: fix crash from nil `service_registries` item This appears only to be possible with dynamic blocks as explicitly setting a nil `service_registries` block will prompt for the required attributes within the block. However, this fix should prevent the nil value from being expanded and causing a crash under the dynamic block scenario. ```console % make testacc PKG=ecs TESTS=TestAccECSService_ServiceRegistries make: Verifying source code with gofmt... ==> Checking that code complies with gofmt requirements... TF_ACC=1 go1.22.6 test ./internal/service/ecs/... -v -count 1 -parallel 20 -run='TestAccECSService_ServiceRegistries' -timeout 360m --- PASS: TestAccECSService_ServiceRegistries_basic (145.59s) --- PASS: TestAccECSService_ServiceRegistries_container (145.60s) --- PASS: TestAccECSService_ServiceRegistries_removal (156.46s) --- PASS: TestAccECSService_ServiceRegistries_changes (279.51s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/ecs 285.700s ``` --- .changelog/38883.txt | 3 +++ internal/service/ecs/flex.go | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 .changelog/38883.txt diff --git a/.changelog/38883.txt b/.changelog/38883.txt new file mode 100644 index 00000000000..aaae023e7d6 --- /dev/null +++ b/.changelog/38883.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ecs_service: Fix crash from nil `service_registries` item +``` diff --git a/internal/service/ecs/flex.go b/internal/service/ecs/flex.go index 0ffe28bc257..dc2bca24792 100644 --- a/internal/service/ecs/flex.go +++ b/internal/service/ecs/flex.go @@ -164,6 +164,10 @@ func expandServiceRegistries(tfList []interface{}) []awstypes.ServiceRegistry { apiObjects := make([]awstypes.ServiceRegistry, 0, len(tfList)) for _, tfMapRaw := range tfList { + if tfMapRaw == nil { + continue + } + tfMap := tfMapRaw.(map[string]interface{}) apiObject := awstypes.ServiceRegistry{ RegistryArn: aws.String(tfMap["registry_arn"].(string)),