Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order bootstrap brokers from msk #17579

Merged
merged 2 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion aws/data_source_aws_msk_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package aws

import (
"fmt"
"sort"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/kafka"
Expand Down Expand Up @@ -103,7 +105,7 @@ func dataSourceAwsMskClusterRead(d *schema.ResourceData, meta interface{}) error
}

d.Set("arn", aws.StringValue(cluster.ClusterArn))
d.Set("bootstrap_brokers", aws.StringValue(bootstrapBrokersoOutput.BootstrapBrokerString))
d.Set("bootstrap_brokers", sortDataSourceBrokers(aws.StringValue(bootstrapBrokersoOutput.BootstrapBrokerString)))
d.Set("bootstrap_brokers_sasl_scram", aws.StringValue(bootstrapBrokersoOutput.BootstrapBrokerStringSaslScram))
d.Set("bootstrap_brokers_tls", aws.StringValue(bootstrapBrokersoOutput.BootstrapBrokerStringTls))
d.Set("cluster_name", aws.StringValue(cluster.ClusterName))
Expand All @@ -120,3 +122,9 @@ func dataSourceAwsMskClusterRead(d *schema.ResourceData, meta interface{}) error

return nil
}

func sortDataSourceBrokers(s string) string {
splitBootstrapBrokers := strings.Split(s, ",")
sort.Strings(splitBootstrapBrokers)
return strings.Join(splitBootstrapBrokers, ",")
}
7 changes: 7 additions & 0 deletions aws/data_source_aws_msk_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ data "aws_msk_cluster" "test" {
}
`, rName)
}

func TestAccMskClusterDataSource_SortBrokers(t *testing.T) {
testString := "this:123,is:147,just.a.test:443"
if "is:147,just.a.test:443,this:123" != sortDataSourceBrokers(testString) {
t.Fail()
}
}
10 changes: 9 additions & 1 deletion aws/resource_aws_msk_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"log"
"sort"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -455,7 +457,7 @@ func resourceAwsMskClusterRead(d *schema.ResourceData, meta interface{}) error {
cluster := out.ClusterInfo

d.Set("arn", aws.StringValue(cluster.ClusterArn))
d.Set("bootstrap_brokers", aws.StringValue(brokerOut.BootstrapBrokerString))
d.Set("bootstrap_brokers", sortResourceBrokers(aws.StringValue(brokerOut.BootstrapBrokerString)))
d.Set("bootstrap_brokers_sasl_scram", aws.StringValue(brokerOut.BootstrapBrokerStringSaslScram))
d.Set("bootstrap_brokers_tls", aws.StringValue(brokerOut.BootstrapBrokerStringTls))

Expand Down Expand Up @@ -1206,3 +1208,9 @@ func waitForMskClusterOperation(conn *kafka.Kafka, clusterOperationARN string) e

return err
}

func sortResourceBrokers(s string) string {
splitBootstrapBrokers := strings.Split(s, ",")
sort.Strings(splitBootstrapBrokers)
return strings.Join(splitBootstrapBrokers, ",")
}
8 changes: 7 additions & 1 deletion aws/resource_aws_msk_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,13 @@ func testAccCheckMskClusterDestroy(s *terraform.State) error {
return nil
}

func TestAccMskClusterReource_SortBrokers(t *testing.T) {
testString := "this:123,is:147,just.a.test:443"
if "is:147,just.a.test:443,this:123" != sortResourceBrokers(testString) {
t.Fail()
}
}

func testAccCheckMskClusterExists(n string, cluster *kafka.ClusterInfo) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -1423,5 +1430,4 @@ resource "aws_msk_cluster" "test" {
}
}
`, rName)

}