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

stream_analytics_output_cosmosdb: add support for authentication_mode #28372

Merged
merged 3 commits into from
Jan 29, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
},
}
}

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading