diff --git a/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go b/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go index 89269fef25fc..3e90bb91c5b2 100644 --- a/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go +++ b/internal/services/streamanalytics/stream_analytics_output_cosmosdb_resource.go @@ -8,6 +8,7 @@ import ( "fmt" "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" @@ -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(pointer.From(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: