From bf1b8773827e39234d79362a0fc6261d16024e9b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 6 Oct 2023 14:49:08 -0400 Subject: [PATCH 1/6] r/aws_msk_cluster: Add 'cluster_uuid' attribute. --- .changelog/#####.txt | 3 +++ internal/service/kafka/cluster.go | 25 +++++++++++++++++++++++- internal/service/kafka/cluster_test.go | 5 +++++ website/docs/r/msk_cluster.html.markdown | 1 + 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .changelog/#####.txt diff --git a/.changelog/#####.txt b/.changelog/#####.txt new file mode 100644 index 00000000000..e60195dd27f --- /dev/null +++ b/.changelog/#####.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_msk_cluster: Add `cluster_uuid` attribute +``` diff --git a/internal/service/kafka/cluster.go b/internal/service/kafka/cluster.go index fa6ed484937..2dd2565d960 100644 --- a/internal/service/kafka/cluster.go +++ b/internal/service/kafka/cluster.go @@ -7,9 +7,11 @@ import ( "context" "fmt" "log" + "strings" "time" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/kafka" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -304,6 +306,10 @@ func ResourceCluster() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringLenBetween(1, 64), }, + "cluster_uuid": { + Type: schema.TypeString, + Computed: true, + }, "configuration_info": { Type: schema.TypeList, Optional: true, @@ -638,7 +644,8 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter return diag.Errorf("reading MSK Cluster (%s) bootstrap brokers: %s", d.Id(), err) } - d.Set("arn", cluster.ClusterArn) + clusterARN := aws.StringValue(cluster.ClusterArn) + d.Set("arn", clusterARN) d.Set("bootstrap_brokers", SortEndpointsString(aws.StringValue(output.BootstrapBrokerString))) d.Set("bootstrap_brokers_public_sasl_iam", SortEndpointsString(aws.StringValue(output.BootstrapBrokerStringPublicSaslIam))) d.Set("bootstrap_brokers_public_sasl_scram", SortEndpointsString(aws.StringValue(output.BootstrapBrokerStringPublicSaslScram))) @@ -664,6 +671,8 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set("client_authentication", nil) } d.Set("cluster_name", cluster.ClusterName) + clusterUUID, _ := clusterUUIDFromARN(clusterARN) + d.Set("cluster_uuid", clusterUUID) if cluster.CurrentBrokerSoftwareInfo != nil { if err := d.Set("configuration_info", []interface{}{flattenBrokerSoftwareInfo(cluster.CurrentBrokerSoftwareInfo)}); err != nil { return diag.Errorf("setting configuration_info: %s", err) @@ -1877,3 +1886,17 @@ func refreshClusterVersion(ctx context.Context, d *schema.ResourceData, meta int return nil } + +func clusterUUIDFromARN(clusterARN string) (string, error) { + parsedARN, err := arn.Parse(clusterARN) + if err != nil { + return "", err + } + + // arn:${Partition}:kafka:${Region}:${Account}:cluster/${ClusterName}/${Uuid} + parts := strings.Split(parsedARN.Resource, "/") + if len(parts) != 3 || parts[0] != "cluster" || parts[1] == "" || parts[2] == "" { + return "", fmt.Errorf("invalid MSK Cluster ARN (%s)", clusterARN) + } + return parts[2], nil +} diff --git a/internal/service/kafka/cluster_test.go b/internal/service/kafka/cluster_test.go index 54e1a45a9af..9d3a22567a0 100644 --- a/internal/service/kafka/cluster_test.go +++ b/internal/service/kafka/cluster_test.go @@ -15,6 +15,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/acmpca" "github.com/aws/aws-sdk-go/service/kafka" + uuid "github.com/hashicorp/go-uuid" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -100,6 +101,10 @@ func TestAccKafkaCluster_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "broker_node_group_info.0.storage_info.0.ebs_storage_info.0.provisioned_throughput.#", "0"), resource.TestCheckResourceAttr(resourceName, "client_authentication.#", "0"), resource.TestCheckResourceAttr(resourceName, "cluster_name", rName), + resource.TestCheckResourceAttrWith(resourceName, "cluster_uuid", func(value string) error { + _, err := uuid.ParseUUID(value) + return err + }), resource.TestCheckResourceAttr(resourceName, "configuration_info.#", "1"), resource.TestCheckResourceAttr(resourceName, "encryption_info.#", "1"), acctest.MatchResourceAttrRegionalARN(resourceName, "encryption_info.0.encryption_at_rest_kms_key_arn", "kms", regexache.MustCompile(`key/.+`)), diff --git a/website/docs/r/msk_cluster.html.markdown b/website/docs/r/msk_cluster.html.markdown index d5255d4c654..2c35400501a 100644 --- a/website/docs/r/msk_cluster.html.markdown +++ b/website/docs/r/msk_cluster.html.markdown @@ -343,6 +343,7 @@ This resource exports the following attributes in addition to the arguments abov * `bootstrap_brokers_vpc_connectivity_sasl_iam` - A string containing one or more DNS names (or IP addresses) and SASL IAM port pairs for VPC connectivity. AWS may not always return all endpoints so the values may not be stable across applies. * `bootstrap_brokers_vpc_connectivity_sasl_scram` - A string containing one or more DNS names (or IP addresses) and SASL SCRAM port pairs for VPC connectivity. AWS may not always return all endpoints so the values may not be stable across applies. * `bootstrap_brokers_vpc_connectivity_tls` - A string containing one or more DNS names (or IP addresses) and TLS port pairs for VPC connectivity. AWS may not always return all endpoints so the values may not be stable across applies. +* `cluster_uuid` - UUID of the MSK cluster, for use in IAM policies. * `current_version` - Current version of the MSK Cluster used for updates, e.g., `K13V1IB3VIYZZH` * `encryption_info.0.encryption_at_rest_kms_key_arn` - The ARN of the KMS key used for encryption at rest of the broker data volumes. * `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). From 0141f1e83af3e9bbe830079c0ebc4723276db68e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 6 Oct 2023 14:51:05 -0400 Subject: [PATCH 2/6] d/aws_msk_cluster: Add 'cluster_uuid' attribute. --- .changelog/#####.txt | 4 ++++ internal/service/kafka/cluster_data_source.go | 9 ++++++++- internal/service/kafka/cluster_data_source_test.go | 1 + website/docs/d/msk_cluster.html.markdown | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.changelog/#####.txt b/.changelog/#####.txt index e60195dd27f..a1edbe7dc4f 100644 --- a/.changelog/#####.txt +++ b/.changelog/#####.txt @@ -1,3 +1,7 @@ ```release-note:enhancement resource/aws_msk_cluster: Add `cluster_uuid` attribute ``` + +```release-note:enhancement +data-source/aws_msk_cluster: Add `cluster_uuid` attribute +``` \ No newline at end of file diff --git a/internal/service/kafka/cluster_data_source.go b/internal/service/kafka/cluster_data_source.go index 529471048c2..bbb43cb8d73 100644 --- a/internal/service/kafka/cluster_data_source.go +++ b/internal/service/kafka/cluster_data_source.go @@ -59,6 +59,10 @@ func DataSourceCluster() *schema.Resource { Required: true, ValidateFunc: validation.StringLenBetween(1, 64), }, + "cluster_uuid": { + Type: schema.TypeString, + Computed: true, + }, "kafka_version": { Type: schema.TypeString, Computed: true, @@ -125,7 +129,8 @@ func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta int return sdkdiag.AppendErrorf(diags, "reading MSK Cluster (%s) bootstrap brokers: %s", aws.StringValue(cluster.ClusterArn), err) } - d.Set("arn", cluster.ClusterArn) + clusterARN := aws.StringValue(cluster.ClusterArn) + d.Set("arn", clusterARN) d.Set("bootstrap_brokers", SortEndpointsString(aws.StringValue(bootstrapBrokersOutput.BootstrapBrokerString))) d.Set("bootstrap_brokers_public_sasl_iam", SortEndpointsString(aws.StringValue(bootstrapBrokersOutput.BootstrapBrokerStringPublicSaslIam))) d.Set("bootstrap_brokers_public_sasl_scram", SortEndpointsString(aws.StringValue(bootstrapBrokersOutput.BootstrapBrokerStringPublicSaslScram))) @@ -134,6 +139,8 @@ func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta int d.Set("bootstrap_brokers_sasl_scram", SortEndpointsString(aws.StringValue(bootstrapBrokersOutput.BootstrapBrokerStringSaslScram))) d.Set("bootstrap_brokers_tls", SortEndpointsString(aws.StringValue(bootstrapBrokersOutput.BootstrapBrokerStringTls))) d.Set("cluster_name", cluster.ClusterName) + clusterUUID, _ := clusterUUIDFromARN(clusterARN) + d.Set("cluster_uuid", clusterUUID) d.Set("kafka_version", cluster.CurrentBrokerSoftwareInfo.KafkaVersion) d.Set("number_of_broker_nodes", cluster.NumberOfBrokerNodes) diff --git a/internal/service/kafka/cluster_data_source_test.go b/internal/service/kafka/cluster_data_source_test.go index 0eba73dfd3a..9126cf01d06 100644 --- a/internal/service/kafka/cluster_data_source_test.go +++ b/internal/service/kafka/cluster_data_source_test.go @@ -37,6 +37,7 @@ func TestAccKafkaClusterDataSource_basic(t *testing.T) { resource.TestCheckResourceAttrPair(dataSourceName, "bootstrap_brokers_sasl_scram", resourceName, "bootstrap_brokers_sasl_scram"), resource.TestCheckResourceAttrPair(dataSourceName, "bootstrap_brokers_tls", resourceName, "bootstrap_brokers_tls"), resource.TestCheckResourceAttrPair(dataSourceName, "cluster_name", resourceName, "cluster_name"), + resource.TestCheckResourceAttrPair(dataSourceName, "cluster_uuid", resourceName, "cluster_uuid"), resource.TestCheckResourceAttrPair(dataSourceName, "kafka_version", resourceName, "kafka_version"), resource.TestCheckResourceAttrPair(dataSourceName, "number_of_broker_nodes", resourceName, "number_of_broker_nodes"), resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), diff --git a/website/docs/d/msk_cluster.html.markdown b/website/docs/d/msk_cluster.html.markdown index e0d0f5372bc..42e33e43690 100644 --- a/website/docs/d/msk_cluster.html.markdown +++ b/website/docs/d/msk_cluster.html.markdown @@ -38,6 +38,7 @@ This data source exports the following attributes in addition to the arguments a * `bootstrap_brokers_sasl_iam` - One or more DNS names (or IP addresses) and SASL IAM port pairs. For example, `b-1.exampleClusterName.abcde.c2.kafka.us-east-1.amazonaws.com:9098,b-2.exampleClusterName.abcde.c2.kafka.us-east-1.amazonaws.com:9098,b-3.exampleClusterName.abcde.c2.kafka.us-east-1.amazonaws.com:9098`. This attribute will have a value if `encryption_info.0.encryption_in_transit.0.client_broker` is set to `TLS_PLAINTEXT` or `TLS` and `client_authentication.0.sasl.0.iam` is set to `true`. The resource sorts the list alphabetically. AWS may not always return all endpoints so the values may not be stable across applies. * `bootstrap_brokers_sasl_scram` - One or more DNS names (or IP addresses) and SASL SCRAM port pairs. For example, `b-1.exampleClusterName.abcde.c2.kafka.us-east-1.amazonaws.com:9096,b-2.exampleClusterName.abcde.c2.kafka.us-east-1.amazonaws.com:9096,b-3.exampleClusterName.abcde.c2.kafka.us-east-1.amazonaws.com:9096`. This attribute will have a value if `encryption_info.0.encryption_in_transit.0.client_broker` is set to `TLS_PLAINTEXT` or `TLS` and `client_authentication.0.sasl.0.scram` is set to `true`. The resource sorts the list alphabetically. AWS may not always return all endpoints so the values may not be stable across applies. * `bootstrap_brokers_tls` - One or more DNS names (or IP addresses) and TLS port pairs. For example, `b-1.exampleClusterName.abcde.c2.kafka.us-east-1.amazonaws.com:9094,b-2.exampleClusterName.abcde.c2.kafka.us-east-1.amazonaws.com:9094,b-3.exampleClusterName.abcde.c2.kafka.us-east-1.amazonaws.com:9094`. This attribute will have a value if `encryption_info.0.encryption_in_transit.0.client_broker` is set to `TLS_PLAINTEXT` or `TLS`. The resource sorts the list alphabetically. AWS may not always return all endpoints so the values may not be stable across applies. +* `cluster_uuid` - UUID of the MSK cluster, for use in IAM policies. * `kafka_version` - Apache Kafka version. * `number_of_broker_nodes` - Number of broker nodes in the cluster. * `tags` - Map of key-value pairs assigned to the cluster. From 6012f8a796f78d351ee59e1b431af23292649d78 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 6 Oct 2023 14:54:01 -0400 Subject: [PATCH 3/6] r/aws_msk_serverless_cluster: Add 'cluster_uuid' attribute. --- .changelog/#####.txt | 4 ++++ internal/service/kafka/serverless_cluster.go | 14 +++++++++----- internal/service/kafka/serverless_cluster_test.go | 7 ++++++- .../docs/r/msk_serverless_cluster.html.markdown | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.changelog/#####.txt b/.changelog/#####.txt index a1edbe7dc4f..1b7c042bd60 100644 --- a/.changelog/#####.txt +++ b/.changelog/#####.txt @@ -4,4 +4,8 @@ resource/aws_msk_cluster: Add `cluster_uuid` attribute ```release-note:enhancement data-source/aws_msk_cluster: Add `cluster_uuid` attribute +``` + +```release-note:enhancement +resource/aws_msk_serverless_cluster: Add `cluster_uuid` attribute ``` \ No newline at end of file diff --git a/internal/service/kafka/serverless_cluster.go b/internal/service/kafka/serverless_cluster.go index 347f7135d71..51f1dc56fe0 100644 --- a/internal/service/kafka/serverless_cluster.go +++ b/internal/service/kafka/serverless_cluster.go @@ -87,6 +87,10 @@ func ResourceServerlessCluster() *schema.Resource { ForceNew: true, ValidateFunc: validation.StringLenBetween(1, 64), }, + "cluster_uuid": { + Type: schema.TypeString, + Computed: true, + }, names.AttrTags: tftags.TagsSchema(), names.AttrTagsAll: tftags.TagsSchemaComputed(), "vpc_config": { @@ -133,7 +137,6 @@ func resourceServerlessClusterCreate(ctx context.Context, d *schema.ResourceData Tags: getTagsIn(ctx), } - log.Printf("[DEBUG] Creating MSK Serverless Cluster: %s", input) output, err := conn.CreateClusterV2WithContext(ctx, input) if err != nil { @@ -142,9 +145,7 @@ func resourceServerlessClusterCreate(ctx context.Context, d *schema.ResourceData d.SetId(aws.StringValue(output.ClusterArn)) - _, err = waitClusterCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)) - - if err != nil { + if _, err := waitClusterCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return diag.Errorf("waiting for MSK Serverless Cluster (%s) create: %s", d.Id(), err) } @@ -166,7 +167,8 @@ func resourceServerlessClusterRead(ctx context.Context, d *schema.ResourceData, return diag.Errorf("reading MSK Serverless Cluster (%s): %s", d.Id(), err) } - d.Set("arn", cluster.ClusterArn) + clusterARN := aws.StringValue(cluster.ClusterArn) + d.Set("arn", clusterARN) if cluster.Serverless.ClientAuthentication != nil { if err := d.Set("client_authentication", []interface{}{flattenServerlessClientAuthentication(cluster.Serverless.ClientAuthentication)}); err != nil { return diag.Errorf("setting client_authentication: %s", err) @@ -175,6 +177,8 @@ func resourceServerlessClusterRead(ctx context.Context, d *schema.ResourceData, d.Set("client_authentication", nil) } d.Set("cluster_name", cluster.ClusterName) + clusterUUID, _ := clusterUUIDFromARN(clusterARN) + d.Set("cluster_uuid", clusterUUID) if err := d.Set("vpc_config", flattenVpcConfigs(cluster.Serverless.VpcConfigs)); err != nil { return diag.Errorf("setting vpc_config: %s", err) } diff --git a/internal/service/kafka/serverless_cluster_test.go b/internal/service/kafka/serverless_cluster_test.go index d4653a88a90..cea1f266372 100644 --- a/internal/service/kafka/serverless_cluster_test.go +++ b/internal/service/kafka/serverless_cluster_test.go @@ -10,6 +10,7 @@ import ( "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go/service/kafka" + uuid "github.com/hashicorp/go-uuid" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -36,11 +37,15 @@ func TestAccKafkaServerlessCluster_basic(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckServerlessClusterExists(ctx, resourceName, &v), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "kafka", regexache.MustCompile(`cluster/.+$`)), - resource.TestCheckResourceAttr(resourceName, "cluster_name", rName), resource.TestCheckResourceAttr(resourceName, "client_authentication.#", "1"), resource.TestCheckResourceAttr(resourceName, "client_authentication.0.sasl.#", "1"), resource.TestCheckResourceAttr(resourceName, "client_authentication.0.sasl.0.iam.#", "1"), resource.TestCheckResourceAttr(resourceName, "client_authentication.0.sasl.0.iam.0.enabled", "true"), + resource.TestCheckResourceAttr(resourceName, "cluster_name", rName), + resource.TestCheckResourceAttrWith(resourceName, "cluster_uuid", func(value string) error { + _, err := uuid.ParseUUID(value) + return err + }), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "vpc_config.#", "1"), resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "1"), diff --git a/website/docs/r/msk_serverless_cluster.html.markdown b/website/docs/r/msk_serverless_cluster.html.markdown index bfdb42c94d6..e3b96231b82 100644 --- a/website/docs/r/msk_serverless_cluster.html.markdown +++ b/website/docs/r/msk_serverless_cluster.html.markdown @@ -64,6 +64,7 @@ This resource supports the following arguments: This resource exports the following attributes in addition to the arguments above: * `arn` - The ARN of the serverless cluster. +* `cluster_uuid` - UUID of the serverless cluster, for use in IAM policies. * `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block). ## Timeouts From efa97c8ce02c1043f66cac5e2d69db1d704fc80b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 6 Oct 2023 14:55:37 -0400 Subject: [PATCH 4/6] Correct CHANGELOG entry file name. --- .changelog/{#####.txt => 33805.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{#####.txt => 33805.txt} (100%) diff --git a/.changelog/#####.txt b/.changelog/33805.txt similarity index 100% rename from .changelog/#####.txt rename to .changelog/33805.txt From 76370ab4146cb1e318e15659d68d2893ff6f496b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 6 Oct 2023 15:43:43 -0400 Subject: [PATCH 5/6] 'cluster_uuid' does not have standard UUID format. --- internal/service/kafka/cluster_test.go | 6 +----- internal/service/kafka/serverless_cluster_test.go | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/internal/service/kafka/cluster_test.go b/internal/service/kafka/cluster_test.go index 9d3a22567a0..9ac40756532 100644 --- a/internal/service/kafka/cluster_test.go +++ b/internal/service/kafka/cluster_test.go @@ -15,7 +15,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/acmpca" "github.com/aws/aws-sdk-go/service/kafka" - uuid "github.com/hashicorp/go-uuid" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -101,10 +100,7 @@ func TestAccKafkaCluster_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "broker_node_group_info.0.storage_info.0.ebs_storage_info.0.provisioned_throughput.#", "0"), resource.TestCheckResourceAttr(resourceName, "client_authentication.#", "0"), resource.TestCheckResourceAttr(resourceName, "cluster_name", rName), - resource.TestCheckResourceAttrWith(resourceName, "cluster_uuid", func(value string) error { - _, err := uuid.ParseUUID(value) - return err - }), + resource.TestMatchResourceAttr(resourceName, "cluster_uuid", regexache.MustCompile(`^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}-\d+$`)), resource.TestCheckResourceAttr(resourceName, "configuration_info.#", "1"), resource.TestCheckResourceAttr(resourceName, "encryption_info.#", "1"), acctest.MatchResourceAttrRegionalARN(resourceName, "encryption_info.0.encryption_at_rest_kms_key_arn", "kms", regexache.MustCompile(`key/.+`)), diff --git a/internal/service/kafka/serverless_cluster_test.go b/internal/service/kafka/serverless_cluster_test.go index cea1f266372..9a1ddaccbf9 100644 --- a/internal/service/kafka/serverless_cluster_test.go +++ b/internal/service/kafka/serverless_cluster_test.go @@ -10,7 +10,6 @@ import ( "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go/service/kafka" - uuid "github.com/hashicorp/go-uuid" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -42,10 +41,7 @@ func TestAccKafkaServerlessCluster_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "client_authentication.0.sasl.0.iam.#", "1"), resource.TestCheckResourceAttr(resourceName, "client_authentication.0.sasl.0.iam.0.enabled", "true"), resource.TestCheckResourceAttr(resourceName, "cluster_name", rName), - resource.TestCheckResourceAttrWith(resourceName, "cluster_uuid", func(value string) error { - _, err := uuid.ParseUUID(value) - return err - }), + resource.TestMatchResourceAttr(resourceName, "cluster_uuid", regexache.MustCompile(`^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}-\d+$`)), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "vpc_config.#", "1"), resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "1"), From 61961601b632336a57c9848e523e9173ea690f48 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 6 Oct 2023 16:22:08 -0400 Subject: [PATCH 6/6] Just check that 'cluster_uuid' is set. --- internal/service/kafka/cluster_test.go | 2 +- internal/service/kafka/serverless_cluster_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/kafka/cluster_test.go b/internal/service/kafka/cluster_test.go index 9ac40756532..d59e4ea5452 100644 --- a/internal/service/kafka/cluster_test.go +++ b/internal/service/kafka/cluster_test.go @@ -100,7 +100,7 @@ func TestAccKafkaCluster_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "broker_node_group_info.0.storage_info.0.ebs_storage_info.0.provisioned_throughput.#", "0"), resource.TestCheckResourceAttr(resourceName, "client_authentication.#", "0"), resource.TestCheckResourceAttr(resourceName, "cluster_name", rName), - resource.TestMatchResourceAttr(resourceName, "cluster_uuid", regexache.MustCompile(`^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}-\d+$`)), + resource.TestCheckResourceAttrSet(resourceName, "cluster_uuid"), resource.TestCheckResourceAttr(resourceName, "configuration_info.#", "1"), resource.TestCheckResourceAttr(resourceName, "encryption_info.#", "1"), acctest.MatchResourceAttrRegionalARN(resourceName, "encryption_info.0.encryption_at_rest_kms_key_arn", "kms", regexache.MustCompile(`key/.+`)), diff --git a/internal/service/kafka/serverless_cluster_test.go b/internal/service/kafka/serverless_cluster_test.go index 9a1ddaccbf9..bb4cea74402 100644 --- a/internal/service/kafka/serverless_cluster_test.go +++ b/internal/service/kafka/serverless_cluster_test.go @@ -41,7 +41,7 @@ func TestAccKafkaServerlessCluster_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "client_authentication.0.sasl.0.iam.#", "1"), resource.TestCheckResourceAttr(resourceName, "client_authentication.0.sasl.0.iam.0.enabled", "true"), resource.TestCheckResourceAttr(resourceName, "cluster_name", rName), - resource.TestMatchResourceAttr(resourceName, "cluster_uuid", regexache.MustCompile(`^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}-\d+$`)), + resource.TestCheckResourceAttrSet(resourceName, "cluster_uuid"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "vpc_config.#", "1"), resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "1"),