Skip to content

Commit

Permalink
r/aws_ecs_service: fix crash from nil service_registries item
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
jar-b committed Aug 15, 2024
1 parent 7b440b8 commit d4d39e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/38883.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ecs_service: Fix crash from nil `service_registries` item
```
4 changes: 4 additions & 0 deletions internal/service/ecs/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down

0 comments on commit d4d39e0

Please sign in to comment.