From 418b60915a1b14e402b5a86125bd5dd91ab9e188 Mon Sep 17 00:00:00 2001 From: James Bennett Date: Wed, 18 Aug 2021 01:08:28 +0100 Subject: [PATCH 1/5] add msk broker node data lookup --- aws/data_source_aws_msk_nodes.go | 103 ++++++++++++++++++++++++++ aws/data_source_aws_msk_nodes_test.go | 69 +++++++++++++++++ aws/provider.go | 1 + 3 files changed, 173 insertions(+) create mode 100644 aws/data_source_aws_msk_nodes.go create mode 100644 aws/data_source_aws_msk_nodes_test.go diff --git a/aws/data_source_aws_msk_nodes.go b/aws/data_source_aws_msk_nodes.go new file mode 100644 index 00000000000..c8c681e4bbd --- /dev/null +++ b/aws/data_source_aws_msk_nodes.go @@ -0,0 +1,103 @@ +package aws + +import ( + "fmt" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/kafka" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "sort" +) + +func dataSourceAwsMskNodes() *schema.Resource { + return &schema.Resource{ + Read: dataSourceAwsMskNodesRead, + + Schema: map[string]*schema.Schema{ + "cluster_arn": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validateArn, + }, + "nodes": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "broker_id": { + Type: schema.TypeFloat, + Computed: true, + }, + "attached_eni_id": { + Type: schema.TypeString, + Computed: true, + }, + "client_subnet": { + Type: schema.TypeString, + Computed: true, + }, + "endpoints": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + }, + } +} + +func dataSourceAwsMskNodesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).kafkaconn + + listNodesInput := &kafka.ListNodesInput{ + ClusterArn: aws.String(d.Get("cluster_arn").(string)), + } + + var nodes []*kafka.NodeInfo + for { + listNodesOutput, err := conn.ListNodes(listNodesInput) + + if err != nil { + return fmt.Errorf("error listing MSK Nodes: %w", err) + } + + if listNodesOutput == nil { + break + } + + nodes = append(nodes, listNodesOutput.NodeInfoList...) + + if aws.StringValue(listNodesOutput.NextToken) == "" { + break + } + + listNodesInput.NextToken = listNodesOutput.NextToken + } + + if len(nodes) == 0 { + return fmt.Errorf("error reading MSK Nodes: no results found") + } + + // node list is returned unsorted sort on broker id + sort.Slice(nodes, func(i, j int) bool { + iBrokerId := aws.Float64Value(nodes[i].BrokerNodeInfo.BrokerId) + jBrokerId := aws.Float64Value(nodes[j].BrokerNodeInfo.BrokerId) + return iBrokerId < jBrokerId + }) + + brokerList := make([]interface{}, len(nodes)) + for i, node := range nodes { + broker := map[string]interface{}{ + "broker_id": aws.Float64Value(node.BrokerNodeInfo.BrokerId), + "attached_eni_id": aws.StringValue(node.BrokerNodeInfo.AttachedENIId), + "client_subnet": aws.StringValue(node.BrokerNodeInfo.ClientSubnet), + "endpoints": aws.StringValueSlice(node.BrokerNodeInfo.Endpoints), + } + brokerList[i] = broker + } + + d.SetId(d.Get("cluster_arn").(string)) + d.Set("nodes", brokerList) + return nil +} diff --git a/aws/data_source_aws_msk_nodes_test.go b/aws/data_source_aws_msk_nodes_test.go new file mode 100644 index 00000000000..151fa98b5c8 --- /dev/null +++ b/aws/data_source_aws_msk_nodes_test.go @@ -0,0 +1,69 @@ +package aws + +import ( + "fmt" + "regexp" + "testing" + + "github.com/aws/aws-sdk-go/service/kafka" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAWSMskNodesDataSource_Name(t *testing.T) { + rName := acctest.RandomWithPrefix("tf-acc-test") + dataSourceName := "data.aws_msk_nodes.test" + resourceName := "aws_msk_cluster.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSMsk(t) }, + ErrorCheck: testAccErrorCheck(t, kafka.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckMskClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMskNodesDataSourceConfigName(rName), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "cluster_arn", resourceName, "arn"), + resource.TestCheckResourceAttrPair(dataSourceName, "nodes.#", resourceName, "number_of_broker_nodes"), + resource.TestCheckResourceAttr(dataSourceName, "nodes.0.broker_id", "1"), + resource.TestMatchResourceAttr(dataSourceName, "nodes.0.attached_eni_id", regexp.MustCompile(`^eni-.+`)), + resource.TestMatchResourceAttr(dataSourceName, "nodes.0.client_subnet", regexp.MustCompile(`^subnet-.+`)), + resource.TestMatchResourceAttr(dataSourceName, "nodes.0.endpoints.0", regexp.MustCompile(`^[\w\-\.]+\.kafka\.[\w\-]+\.amazonaws.com$`)), + resource.TestCheckResourceAttr(dataSourceName, "nodes.1.broker_id", "2"), + resource.TestMatchResourceAttr(dataSourceName, "nodes.1.attached_eni_id", regexp.MustCompile(`^eni-.+`)), + resource.TestMatchResourceAttr(dataSourceName, "nodes.1.client_subnet", regexp.MustCompile(`^subnet-.+`)), + resource.TestMatchResourceAttr(dataSourceName, "nodes.1.endpoints.0", regexp.MustCompile(`^[\w\-\.]+\.kafka\.[\w\-]+\.amazonaws.com$`)), + resource.TestCheckResourceAttr(dataSourceName, "nodes.2.broker_id", "3"), + resource.TestMatchResourceAttr(dataSourceName, "nodes.2.attached_eni_id", regexp.MustCompile(`^eni-.+`)), + resource.TestMatchResourceAttr(dataSourceName, "nodes.2.client_subnet", regexp.MustCompile(`^subnet-.+`)), + resource.TestMatchResourceAttr(dataSourceName, "nodes.2.endpoints.0", regexp.MustCompile(`^[\w\-\.]+\.kafka\.[\w\-]+\.amazonaws.com$`)), + ), + }, + }, + }) +} +func testAccMskNodesDataSourceConfigName(rName string) string { + return composeConfig(testAccMskClusterBaseConfig(rName), fmt.Sprintf(` +resource "aws_msk_cluster" "test" { + cluster_name = %[1]q + kafka_version = "2.2.1" + number_of_broker_nodes = 3 + + broker_node_group_info { + client_subnets = [aws_subnet.example_subnet_az1.id, aws_subnet.example_subnet_az2.id, aws_subnet.example_subnet_az3.id] + ebs_volume_size = 10 + instance_type = "kafka.t3.small" + security_groups = [aws_security_group.example_sg.id] + } + + tags = { + foo = "bar" + } +} + +data "aws_msk_nodes" "test" { + cluster_arn = aws_msk_cluster.test.arn +} +`, rName)) +} diff --git a/aws/provider.go b/aws/provider.go index 1beb5e9c100..1759205c9fd 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -346,6 +346,7 @@ func Provider() *schema.Provider { "aws_mq_broker": dataSourceAwsMqBroker(), "aws_msk_cluster": dataSourceAwsMskCluster(), "aws_msk_configuration": dataSourceAwsMskConfiguration(), + "aws_msk_nodes": dataSourceAwsMskNodes(), "aws_nat_gateway": dataSourceAwsNatGateway(), "aws_neptune_orderable_db_instance": dataSourceAwsNeptuneOrderableDbInstance(), "aws_neptune_engine_version": dataSourceAwsNeptuneEngineVersion(), From ef917a01c301d179f2324f6aed19faaeda0d7b0d Mon Sep 17 00:00:00 2001 From: James Bennett Date: Thu, 19 Aug 2021 00:16:20 +0100 Subject: [PATCH 2/5] add docs --- website/docs/d/msk_nodes.html.markdown | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 website/docs/d/msk_nodes.html.markdown diff --git a/website/docs/d/msk_nodes.html.markdown b/website/docs/d/msk_nodes.html.markdown new file mode 100644 index 00000000000..151dc5e6187 --- /dev/null +++ b/website/docs/d/msk_nodes.html.markdown @@ -0,0 +1,37 @@ +--- +subcategory: "Managed Streaming for Kafka (MSK)" +layout: "aws" +page_title: "AWS: aws_msk_nodes" +description: |- + Get information on an Amazon MSK Broker Nodes +--- + +# Data Source: aws_msk_nodes + +Get information on an Amazon MSK Broker Nodes. + +## Example Usage + +```terraform +data "aws_msk_nodes" "example" { + cluster_arn = aws_msk_cluster.example.arn +} +``` + +## Argument Reference + +The following arguments are supported: + +* `cluster_arn` - (Required) The ARN of the cluster the nodes belong to. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* [`nodes`](#Nodes) - List of MSK Broker Nodes, sorted by broker ID in ascending order. + +### Nodes +* `broker_id` - Numeric ID of the broker node +* `attached_eni_id` - The ENI associated with the broker node +* `client_subnet` - The subnet name the broker resides in +* `endpoints` - List of hostnames associates with the broker node. This does not include ports. \ No newline at end of file From e6166133efd8b06ebcf579ba9acfc5f7b84810b6 Mon Sep 17 00:00:00 2001 From: James Bennett Date: Thu, 19 Aug 2021 00:46:09 +0100 Subject: [PATCH 3/5] add changelog --- .changelog/20615.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/20615.txt diff --git a/.changelog/20615.txt b/.changelog/20615.txt new file mode 100644 index 00000000000..705fd0899d0 --- /dev/null +++ b/.changelog/20615.txt @@ -0,0 +1,3 @@ +```release-note:new-data-source +aws_msk_nodes +``` \ No newline at end of file From 55504bc16443d7e4cc764e35e7cfa7b7a81d8085 Mon Sep 17 00:00:00 2001 From: James Bennett Date: Thu, 19 Aug 2021 00:58:38 +0100 Subject: [PATCH 4/5] fix typo --- website/docs/d/msk_nodes.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/msk_nodes.html.markdown b/website/docs/d/msk_nodes.html.markdown index 151dc5e6187..31c8dd426ca 100644 --- a/website/docs/d/msk_nodes.html.markdown +++ b/website/docs/d/msk_nodes.html.markdown @@ -34,4 +34,4 @@ In addition to all arguments above, the following attributes are exported: * `broker_id` - Numeric ID of the broker node * `attached_eni_id` - The ENI associated with the broker node * `client_subnet` - The subnet name the broker resides in -* `endpoints` - List of hostnames associates with the broker node. This does not include ports. \ No newline at end of file +* `endpoints` - List of hostnames associated with the broker node. This does not include ports. \ No newline at end of file From 60e8f5da7b0e5bf2463c19a82553b4f230a5bc8b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 17 Sep 2021 15:29:50 -0400 Subject: [PATCH 5/5] Rename 'aws_msk_nodes' -> 'aws_msk_broker_nodes'. --- .changelog/20615.txt | 2 +- aws/data_source_aws_msk_broker_nodes.go | 113 ++++++++++++++++++ aws/data_source_aws_msk_broker_nodes_test.go | 59 +++++++++ aws/data_source_aws_msk_cluster_test.go | 6 +- aws/data_source_aws_msk_nodes.go | 103 ---------------- aws/data_source_aws_msk_nodes_test.go | 69 ----------- aws/provider.go | 2 +- website/docs/d/msk_broker_nodes.html.markdown | 40 +++++++ website/docs/d/msk_nodes.html.markdown | 37 ------ 9 files changed, 217 insertions(+), 214 deletions(-) create mode 100644 aws/data_source_aws_msk_broker_nodes.go create mode 100644 aws/data_source_aws_msk_broker_nodes_test.go delete mode 100644 aws/data_source_aws_msk_nodes.go delete mode 100644 aws/data_source_aws_msk_nodes_test.go create mode 100644 website/docs/d/msk_broker_nodes.html.markdown delete mode 100644 website/docs/d/msk_nodes.html.markdown diff --git a/.changelog/20615.txt b/.changelog/20615.txt index 705fd0899d0..3e3a1e98804 100644 --- a/.changelog/20615.txt +++ b/.changelog/20615.txt @@ -1,3 +1,3 @@ ```release-note:new-data-source -aws_msk_nodes +aws_msk_broker_nodes ``` \ No newline at end of file diff --git a/aws/data_source_aws_msk_broker_nodes.go b/aws/data_source_aws_msk_broker_nodes.go new file mode 100644 index 00000000000..ed63cffb4bf --- /dev/null +++ b/aws/data_source_aws_msk_broker_nodes.go @@ -0,0 +1,113 @@ +package aws + +import ( + "fmt" + "sort" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/kafka" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func dataSourceAwsMskBrokerNodes() *schema.Resource { + return &schema.Resource{ + Read: dataSourceAwsMskBrokerNodesRead, + + Schema: map[string]*schema.Schema{ + "cluster_arn": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validateArn, + }, + + "node_info_list": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "attached_eni_id": { + Type: schema.TypeString, + Computed: true, + }, + "broker_id": { + Type: schema.TypeFloat, + Computed: true, + }, + "client_subnet": { + Type: schema.TypeString, + Computed: true, + }, + "client_vpc_ip_address": { + Type: schema.TypeString, + Computed: true, + }, + "endpoints": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "node_arn": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func dataSourceAwsMskBrokerNodesRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).kafkaconn + + clusterARN := d.Get("cluster_arn").(string) + input := &kafka.ListNodesInput{ + ClusterArn: aws.String(clusterARN), + } + var nodeInfos []*kafka.NodeInfo + + err := conn.ListNodesPages(input, func(page *kafka.ListNodesOutput, lastPage bool) bool { + if page == nil { + return !lastPage + } + + nodeInfos = append(nodeInfos, page.NodeInfoList...) + + return !lastPage + }) + + if err != nil { + return fmt.Errorf("error listing MSK Cluster (%s) Broker Nodes: %w", clusterARN, err) + } + + // node list is returned unsorted sort on broker id + sort.Slice(nodeInfos, func(i, j int) bool { + iBrokerId := aws.Float64Value(nodeInfos[i].BrokerNodeInfo.BrokerId) + jBrokerId := aws.Float64Value(nodeInfos[j].BrokerNodeInfo.BrokerId) + return iBrokerId < jBrokerId + }) + + tfList := make([]interface{}, len(nodeInfos)) + + for i, apiObject := range nodeInfos { + brokerNodeInfo := apiObject.BrokerNodeInfo + tfMap := map[string]interface{}{ + "attached_eni_id": aws.StringValue(brokerNodeInfo.AttachedENIId), + "broker_id": aws.Float64Value(brokerNodeInfo.BrokerId), + "client_subnet": aws.StringValue(brokerNodeInfo.ClientSubnet), + "client_vpc_ip_address": aws.StringValue(brokerNodeInfo.ClientVpcIpAddress), + "endpoints": aws.StringValueSlice(brokerNodeInfo.Endpoints), + "node_arn": aws.StringValue(apiObject.NodeARN), + } + + tfList[i] = tfMap + } + + d.SetId(clusterARN) + + if err := d.Set("node_info_list", tfList); err != nil { + return fmt.Errorf("error setting node_info_list: %w", err) + } + + return nil +} diff --git a/aws/data_source_aws_msk_broker_nodes_test.go b/aws/data_source_aws_msk_broker_nodes_test.go new file mode 100644 index 00000000000..ed529018d06 --- /dev/null +++ b/aws/data_source_aws_msk_broker_nodes_test.go @@ -0,0 +1,59 @@ +package aws + +import ( + "fmt" + "testing" + + "github.com/aws/aws-sdk-go/service/kafka" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccAWSMskBrokerNodesDataSource_basic(t *testing.T) { + rName := acctest.RandomWithPrefix("tf-acc-test") + dataSourceName := "data.aws_msk_broker_nodes.test" + resourceName := "aws_msk_cluster.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSMsk(t) }, + ErrorCheck: testAccErrorCheck(t, kafka.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckMskClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMskBrokerNodesDataSourceConfig(rName), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttrPair(dataSourceName, "cluster_arn", resourceName, "arn"), + resource.TestCheckResourceAttrPair(dataSourceName, "node_info_list.#", resourceName, "number_of_broker_nodes"), + resource.TestCheckResourceAttr(dataSourceName, "node_info_list.0.broker_id", "1"), + resource.TestCheckResourceAttr(dataSourceName, "node_info_list.1.broker_id", "2"), + resource.TestCheckResourceAttr(dataSourceName, "node_info_list.2.broker_id", "3"), + ), + }, + }, + }) +} +func testAccMskBrokerNodesDataSourceConfig(rName string) string { + return composeConfig(testAccMskClusterBaseConfig(rName), fmt.Sprintf(` +resource "aws_msk_cluster" "test" { + cluster_name = %[1]q + kafka_version = "2.2.1" + number_of_broker_nodes = 3 + + broker_node_group_info { + client_subnets = [aws_subnet.example_subnet_az1.id, aws_subnet.example_subnet_az2.id, aws_subnet.example_subnet_az3.id] + ebs_volume_size = 10 + instance_type = "kafka.t3.small" + security_groups = [aws_security_group.example_sg.id] + } + + tags = { + foo = "bar" + } +} + +data "aws_msk_broker_nodes" "test" { + cluster_arn = aws_msk_cluster.test.arn +} +`, rName)) +} diff --git a/aws/data_source_aws_msk_cluster_test.go b/aws/data_source_aws_msk_cluster_test.go index 594f721bc17..9f62d0e05f3 100644 --- a/aws/data_source_aws_msk_cluster_test.go +++ b/aws/data_source_aws_msk_cluster_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -func TestAccAWSMskClusterDataSource_Name(t *testing.T) { +func TestAccAWSMskClusterDataSource_basic(t *testing.T) { rName := acctest.RandomWithPrefix("tf-acc-test") dataSourceName := "data.aws_msk_cluster.test" resourceName := "aws_msk_cluster.test" @@ -21,7 +21,7 @@ func TestAccAWSMskClusterDataSource_Name(t *testing.T) { CheckDestroy: testAccCheckMskClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccMskClusterDataSourceConfigName(rName), + Config: testAccMskClusterDataSourceConfig(rName), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), resource.TestCheckResourceAttrPair(dataSourceName, "bootstrap_brokers", resourceName, "bootstrap_brokers"), @@ -38,7 +38,7 @@ func TestAccAWSMskClusterDataSource_Name(t *testing.T) { }) } -func testAccMskClusterDataSourceConfigName(rName string) string { +func testAccMskClusterDataSourceConfig(rName string) string { return composeConfig(testAccMskClusterBaseConfig(rName), fmt.Sprintf(` resource "aws_msk_cluster" "test" { cluster_name = %[1]q diff --git a/aws/data_source_aws_msk_nodes.go b/aws/data_source_aws_msk_nodes.go deleted file mode 100644 index c8c681e4bbd..00000000000 --- a/aws/data_source_aws_msk_nodes.go +++ /dev/null @@ -1,103 +0,0 @@ -package aws - -import ( - "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/kafka" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "sort" -) - -func dataSourceAwsMskNodes() *schema.Resource { - return &schema.Resource{ - Read: dataSourceAwsMskNodesRead, - - Schema: map[string]*schema.Schema{ - "cluster_arn": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validateArn, - }, - "nodes": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "broker_id": { - Type: schema.TypeFloat, - Computed: true, - }, - "attached_eni_id": { - Type: schema.TypeString, - Computed: true, - }, - "client_subnet": { - Type: schema.TypeString, - Computed: true, - }, - "endpoints": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - }, - }, - }, - }, - } -} - -func dataSourceAwsMskNodesRead(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*AWSClient).kafkaconn - - listNodesInput := &kafka.ListNodesInput{ - ClusterArn: aws.String(d.Get("cluster_arn").(string)), - } - - var nodes []*kafka.NodeInfo - for { - listNodesOutput, err := conn.ListNodes(listNodesInput) - - if err != nil { - return fmt.Errorf("error listing MSK Nodes: %w", err) - } - - if listNodesOutput == nil { - break - } - - nodes = append(nodes, listNodesOutput.NodeInfoList...) - - if aws.StringValue(listNodesOutput.NextToken) == "" { - break - } - - listNodesInput.NextToken = listNodesOutput.NextToken - } - - if len(nodes) == 0 { - return fmt.Errorf("error reading MSK Nodes: no results found") - } - - // node list is returned unsorted sort on broker id - sort.Slice(nodes, func(i, j int) bool { - iBrokerId := aws.Float64Value(nodes[i].BrokerNodeInfo.BrokerId) - jBrokerId := aws.Float64Value(nodes[j].BrokerNodeInfo.BrokerId) - return iBrokerId < jBrokerId - }) - - brokerList := make([]interface{}, len(nodes)) - for i, node := range nodes { - broker := map[string]interface{}{ - "broker_id": aws.Float64Value(node.BrokerNodeInfo.BrokerId), - "attached_eni_id": aws.StringValue(node.BrokerNodeInfo.AttachedENIId), - "client_subnet": aws.StringValue(node.BrokerNodeInfo.ClientSubnet), - "endpoints": aws.StringValueSlice(node.BrokerNodeInfo.Endpoints), - } - brokerList[i] = broker - } - - d.SetId(d.Get("cluster_arn").(string)) - d.Set("nodes", brokerList) - return nil -} diff --git a/aws/data_source_aws_msk_nodes_test.go b/aws/data_source_aws_msk_nodes_test.go deleted file mode 100644 index 151fa98b5c8..00000000000 --- a/aws/data_source_aws_msk_nodes_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package aws - -import ( - "fmt" - "regexp" - "testing" - - "github.com/aws/aws-sdk-go/service/kafka" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccAWSMskNodesDataSource_Name(t *testing.T) { - rName := acctest.RandomWithPrefix("tf-acc-test") - dataSourceName := "data.aws_msk_nodes.test" - resourceName := "aws_msk_cluster.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSMsk(t) }, - ErrorCheck: testAccErrorCheck(t, kafka.EndpointsID), - Providers: testAccProviders, - CheckDestroy: testAccCheckMskClusterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccMskNodesDataSourceConfigName(rName), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttrPair(dataSourceName, "cluster_arn", resourceName, "arn"), - resource.TestCheckResourceAttrPair(dataSourceName, "nodes.#", resourceName, "number_of_broker_nodes"), - resource.TestCheckResourceAttr(dataSourceName, "nodes.0.broker_id", "1"), - resource.TestMatchResourceAttr(dataSourceName, "nodes.0.attached_eni_id", regexp.MustCompile(`^eni-.+`)), - resource.TestMatchResourceAttr(dataSourceName, "nodes.0.client_subnet", regexp.MustCompile(`^subnet-.+`)), - resource.TestMatchResourceAttr(dataSourceName, "nodes.0.endpoints.0", regexp.MustCompile(`^[\w\-\.]+\.kafka\.[\w\-]+\.amazonaws.com$`)), - resource.TestCheckResourceAttr(dataSourceName, "nodes.1.broker_id", "2"), - resource.TestMatchResourceAttr(dataSourceName, "nodes.1.attached_eni_id", regexp.MustCompile(`^eni-.+`)), - resource.TestMatchResourceAttr(dataSourceName, "nodes.1.client_subnet", regexp.MustCompile(`^subnet-.+`)), - resource.TestMatchResourceAttr(dataSourceName, "nodes.1.endpoints.0", regexp.MustCompile(`^[\w\-\.]+\.kafka\.[\w\-]+\.amazonaws.com$`)), - resource.TestCheckResourceAttr(dataSourceName, "nodes.2.broker_id", "3"), - resource.TestMatchResourceAttr(dataSourceName, "nodes.2.attached_eni_id", regexp.MustCompile(`^eni-.+`)), - resource.TestMatchResourceAttr(dataSourceName, "nodes.2.client_subnet", regexp.MustCompile(`^subnet-.+`)), - resource.TestMatchResourceAttr(dataSourceName, "nodes.2.endpoints.0", regexp.MustCompile(`^[\w\-\.]+\.kafka\.[\w\-]+\.amazonaws.com$`)), - ), - }, - }, - }) -} -func testAccMskNodesDataSourceConfigName(rName string) string { - return composeConfig(testAccMskClusterBaseConfig(rName), fmt.Sprintf(` -resource "aws_msk_cluster" "test" { - cluster_name = %[1]q - kafka_version = "2.2.1" - number_of_broker_nodes = 3 - - broker_node_group_info { - client_subnets = [aws_subnet.example_subnet_az1.id, aws_subnet.example_subnet_az2.id, aws_subnet.example_subnet_az3.id] - ebs_volume_size = 10 - instance_type = "kafka.t3.small" - security_groups = [aws_security_group.example_sg.id] - } - - tags = { - foo = "bar" - } -} - -data "aws_msk_nodes" "test" { - cluster_arn = aws_msk_cluster.test.arn -} -`, rName)) -} diff --git a/aws/provider.go b/aws/provider.go index 1759205c9fd..2dea4c427d3 100644 --- a/aws/provider.go +++ b/aws/provider.go @@ -344,9 +344,9 @@ func Provider() *schema.Provider { "aws_lex_intent": dataSourceAwsLexIntent(), "aws_lex_slot_type": dataSourceAwsLexSlotType(), "aws_mq_broker": dataSourceAwsMqBroker(), + "aws_msk_broker_nodes": dataSourceAwsMskBrokerNodes(), "aws_msk_cluster": dataSourceAwsMskCluster(), "aws_msk_configuration": dataSourceAwsMskConfiguration(), - "aws_msk_nodes": dataSourceAwsMskNodes(), "aws_nat_gateway": dataSourceAwsNatGateway(), "aws_neptune_orderable_db_instance": dataSourceAwsNeptuneOrderableDbInstance(), "aws_neptune_engine_version": dataSourceAwsNeptuneEngineVersion(), diff --git a/website/docs/d/msk_broker_nodes.html.markdown b/website/docs/d/msk_broker_nodes.html.markdown new file mode 100644 index 00000000000..43993892601 --- /dev/null +++ b/website/docs/d/msk_broker_nodes.html.markdown @@ -0,0 +1,40 @@ +--- +subcategory: "Managed Streaming for Kafka (MSK)" +layout: "aws" +page_title: "AWS: aws_msk_broker_nodes" +description: |- + Get information on an Amazon MSK Broker Nodes +--- + +# Data Source: aws_msk_broker_nodes + +Get information on an Amazon MSK Broker Nodes. + +## Example Usage + +```terraform +data "aws_msk_broker_nodes" "example" { + cluster_arn = aws_msk_cluster.example.arn +} +``` + +## Argument Reference + +The following arguments are supported: + +* `cluster_arn` - (Required) The ARN of the cluster the nodes belong to. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* [`node_info_list`](#Nodes) - List of MSK Broker Nodes, sorted by broker ID in ascending order. + +### Nodes + +* `attached_eni_id` - The attached elastic network interface of the broker +* `broker_id` - The ID of the broker +* `client_subnet` - The client subnet to which this broker node belongs +* `client_vpc_ip_address` - The client virtual private cloud (VPC) IP address +* `endpoints` - Set of endpoints for accessing the broker. This does not include ports +* `node_arn` - The Amazon Resource Name (ARN) of the node \ No newline at end of file diff --git a/website/docs/d/msk_nodes.html.markdown b/website/docs/d/msk_nodes.html.markdown deleted file mode 100644 index 31c8dd426ca..00000000000 --- a/website/docs/d/msk_nodes.html.markdown +++ /dev/null @@ -1,37 +0,0 @@ ---- -subcategory: "Managed Streaming for Kafka (MSK)" -layout: "aws" -page_title: "AWS: aws_msk_nodes" -description: |- - Get information on an Amazon MSK Broker Nodes ---- - -# Data Source: aws_msk_nodes - -Get information on an Amazon MSK Broker Nodes. - -## Example Usage - -```terraform -data "aws_msk_nodes" "example" { - cluster_arn = aws_msk_cluster.example.arn -} -``` - -## Argument Reference - -The following arguments are supported: - -* `cluster_arn` - (Required) The ARN of the cluster the nodes belong to. - -## Attribute Reference - -In addition to all arguments above, the following attributes are exported: - -* [`nodes`](#Nodes) - List of MSK Broker Nodes, sorted by broker ID in ascending order. - -### Nodes -* `broker_id` - Numeric ID of the broker node -* `attached_eni_id` - The ENI associated with the broker node -* `client_subnet` - The subnet name the broker resides in -* `endpoints` - List of hostnames associated with the broker node. This does not include ports. \ No newline at end of file