From 80198220a74357d145fea8fc91f32d1ded609df6 Mon Sep 17 00:00:00 2001 From: Jiawei Tao Date: Mon, 23 Dec 2024 14:26:12 +0800 Subject: [PATCH 1/3] stream_analytics_output_cosmosdb: add support for authentication_mode --- .../stream_analytics_output_cosmosdb_resource.go | 15 +++++++++++++++ ...eam_analytics_output_cosmosdb_resource_test.go | 1 + ...stream_analytics_output_cosmosdb.html.markdown | 2 ++ 3 files changed, 18 insertions(+) diff --git a/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go b/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go index 89269fef25fc..d8f9eadb5a28 100644 --- a/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go +++ b/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go @@ -6,6 +6,7 @@ package streamanalytics import ( "context" "fmt" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -36,6 +37,7 @@ type OutputCosmosDBResourceModel struct { ContainerName string `tfschema:"container_name"` DocumentID string `tfschema:"document_id"` PartitionKey string `tfschema:"partition_key"` + AuthenticationMode string `tfschema:"authentication_mode"` } func (r OutputCosmosDBResource) Arguments() map[string]*pluginsdk.Schema { @@ -84,6 +86,16 @@ func (r OutputCosmosDBResource) Arguments() map[string]*pluginsdk.Schema { Optional: true, ValidateFunc: validation.StringIsNotEmpty, }, + + "authentication_mode": { + Type: pluginsdk.TypeString, + Optional: true, + Default: string(outputs.AuthenticationModeConnectionString), + ValidateFunc: validation.StringInSlice([]string{ + string(outputs.AuthenticationModeConnectionString), + string(outputs.AuthenticationModeMsi), + }, false), + }, } } @@ -138,6 +150,7 @@ func (r OutputCosmosDBResource) Create() sdk.ResourceFunc { CollectionNamePattern: utils.String(model.ContainerName), DocumentId: utils.String(model.DocumentID), PartitionKey: utils.String(model.PartitionKey), + AuthenticationMode: pointer.To(outputs.AuthenticationMode(model.AuthenticationMode)), } props := outputs.Output{ @@ -215,6 +228,8 @@ func (r OutputCosmosDBResource) Read() sdk.ResourceFunc { } state.PartitionKey = partitionKey + state.AuthenticationMode = string(*output.Properties.AuthenticationMode) + return metadata.Encode(&state) } } diff --git a/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource_test.go b/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource_test.go index 9142bca2983f..845962c8a0b8 100644 --- a/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource_test.go +++ b/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource_test.go @@ -159,6 +159,7 @@ resource "azurerm_stream_analytics_output_cosmosdb" "test" { container_name = azurerm_cosmosdb_sql_container.test.name document_id = "exampledocumentid" partition_key = "examplekey" + authentication_mode = "Msi" } `, template, data.RandomString, data.RandomInteger) } diff --git a/website/docs/r/stream_analytics_output_cosmosdb.html.markdown b/website/docs/r/stream_analytics_output_cosmosdb.html.markdown index 5033b7807101..c37ebed89386 100644 --- a/website/docs/r/stream_analytics_output_cosmosdb.html.markdown +++ b/website/docs/r/stream_analytics_output_cosmosdb.html.markdown @@ -85,6 +85,8 @@ The following arguments are supported: * `partition_key` - (Optional) The name of the field in output events used to specify the key for partitioning output across collections. If `container_name` contains `{partition}` token, this property is required to be specified. +* `authentication_mode` - (Optional) The authentication mode for the CosmosDB database. Possible values are `ConnectionString` and `Msi`. Defaults to `ConnectionString`. + ## Attributes Reference In addition to the Arguments listed above - the following Attributes are exported: From 5a6c46d68427f1c65abc4d22cb65db4271c9092e Mon Sep 17 00:00:00 2001 From: Jiawei Tao Date: Mon, 23 Dec 2024 14:28:58 +0800 Subject: [PATCH 2/3] sort imports --- .../stream_analytics_output_cosmosdb_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go b/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go index d8f9eadb5a28..fb3b9ec7da70 100644 --- a/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go +++ b/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go @@ -6,9 +6,9 @@ package streamanalytics import ( "context" "fmt" - "github.com/hashicorp/go-azure-helpers/lang/pointer" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/streamingjobs" "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/outputs" From 0b516105dff5ec3d69a2645d18e7c53c52578333 Mon Sep 17 00:00:00 2001 From: Jiawei Tao Date: Tue, 21 Jan 2025 15:52:17 +0800 Subject: [PATCH 3/3] Address comments --- .../stream_analytics_output_cosmosdb_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go b/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go index fb3b9ec7da70..3e90bb91c5b2 100644 --- a/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go +++ b/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go @@ -228,7 +228,7 @@ func (r OutputCosmosDBResource) Read() sdk.ResourceFunc { } state.PartitionKey = partitionKey - state.AuthenticationMode = string(*output.Properties.AuthenticationMode) + state.AuthenticationMode = string(pointer.From(output.Properties.AuthenticationMode)) return metadata.Encode(&state) }