diff --git a/.changelog/38042.txt b/.changelog/38042.txt new file mode 100644 index 00000000000..02b29dcd007 --- /dev/null +++ b/.changelog/38042.txt @@ -0,0 +1,3 @@ +```release-note:bug +data-source/aws_msk_broker_nodes: Filter out nodes with no broker info +``` diff --git a/internal/service/kafka/broker_nodes_data_source.go b/internal/service/kafka/broker_nodes_data_source.go index e6961b2cc4e..b0fa5902d59 100644 --- a/internal/service/kafka/broker_nodes_data_source.go +++ b/internal/service/kafka/broker_nodes_data_source.go @@ -84,7 +84,11 @@ func dataSourceBrokerNodesRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "listing MSK Cluster (%s) Broker Nodes: %s", clusterARN, err) } - nodeInfos = append(nodeInfos, page.NodeInfoList...) + for _, nodeInfo := range page.NodeInfoList { + if nodeInfo.BrokerNodeInfo != nil { + nodeInfos = append(nodeInfos, nodeInfo) + } + } } // node list is returned unsorted sort on broker id @@ -96,17 +100,16 @@ func dataSourceBrokerNodesRead(ctx context.Context, d *schema.ResourceData, meta tfList := []interface{}{} for _, apiObject := range nodeInfos { - if brokerNodeInfo := apiObject.BrokerNodeInfo; brokerNodeInfo != nil { - tfMap := map[string]interface{}{ - "attached_eni_id": aws.ToString(brokerNodeInfo.AttachedENIId), - "broker_id": aws.ToFloat64(brokerNodeInfo.BrokerId), - "client_subnet": aws.ToString(brokerNodeInfo.ClientSubnet), - "client_vpc_ip_address": aws.ToString(brokerNodeInfo.ClientVpcIpAddress), - names.AttrEndpoints: brokerNodeInfo.Endpoints, - "node_arn": aws.ToString(apiObject.NodeARN), - } - tfList = append(tfList, tfMap) + brokerNodeInfo := apiObject.BrokerNodeInfo + tfMap := map[string]interface{}{ + "attached_eni_id": aws.ToString(brokerNodeInfo.AttachedENIId), + "broker_id": aws.ToFloat64(brokerNodeInfo.BrokerId), + "client_subnet": aws.ToString(brokerNodeInfo.ClientSubnet), + "client_vpc_ip_address": aws.ToString(brokerNodeInfo.ClientVpcIpAddress), + names.AttrEndpoints: brokerNodeInfo.Endpoints, + "node_arn": aws.ToString(apiObject.NodeARN), } + tfList = append(tfList, tfMap) } d.SetId(clusterARN)