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

azurerm_stream_analytics_output_servicebus_queue: add support for authentication_mode #18491

Merged
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 @@ -96,6 +96,16 @@ func resourceStreamAnalyticsOutputServiceBusQueue() *pluginsdk.Resource {
ValidateFunc: validation.StringIsNotEmpty,
},
},

"authentication_mode": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(streamanalytics.AuthenticationModeConnectionString),
ValidateFunc: validation.StringInSlice([]string{
string(streamanalytics.AuthenticationModeConnectionString),
string(streamanalytics.AuthenticationModeMsi),
}, false),
},
},
}
}
Expand Down Expand Up @@ -143,6 +153,7 @@ func resourceStreamAnalyticsOutputServiceBusQueueCreateUpdate(d *pluginsdk.Resou
SharedAccessPolicyName: utils.String(sharedAccessPolicyName),
PropertyColumns: utils.ExpandStringSlice(d.Get("property_columns").([]interface{})),
SystemPropertyColumns: d.Get("system_property_columns").(map[string]interface{}),
AuthenticationMode: streamanalytics.AuthenticationMode(d.Get("authentication_mode").(string)),
},
},
Serialization: serialization,
Expand Down Expand Up @@ -199,6 +210,7 @@ func resourceStreamAnalyticsOutputServiceBusQueueRead(d *pluginsdk.ResourceData,
d.Set("shared_access_policy_name", v.SharedAccessPolicyName)
d.Set("property_columns", v.PropertyColumns)
d.Set("system_property_columns", v.SystemPropertyColumns)
d.Set("authentication_mode", v.AuthenticationMode)

if err := d.Set("serialization", flattenStreamAnalyticsOutputSerialization(props.Serialization)); err != nil {
return fmt.Errorf("setting `serialization`: %+v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ func TestAccStreamAnalyticsOutputServiceBusQueue_json(t *testing.T) {
})
}

func TestAccStreamAnalyticsOutputServiceBusQueue_authenticationMode(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_queue", "test")
r := StreamAnalyticsOutputServiceBusQueueResource{}
identity := "identity { type = \"SystemAssigned\" }"

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.authenticationMode(data, identity),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("shared_access_policy_key"),
})
}

func TestAccStreamAnalyticsOutputServiceBusQueue_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_queue", "test")
r := StreamAnalyticsOutputServiceBusQueueResource{}
Expand Down Expand Up @@ -183,7 +199,7 @@ func (r StreamAnalyticsOutputServiceBusQueueResource) Exists(ctx context.Context
}

func (r StreamAnalyticsOutputServiceBusQueueResource) avro(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s

Expand All @@ -204,7 +220,7 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "test" {
}

func (r StreamAnalyticsOutputServiceBusQueueResource) csv(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s

Expand All @@ -227,7 +243,7 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "test" {
}

func (r StreamAnalyticsOutputServiceBusQueueResource) json(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s

Expand All @@ -250,7 +266,7 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "test" {
}

func (r StreamAnalyticsOutputServiceBusQueueResource) updated(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s

Expand Down Expand Up @@ -284,7 +300,7 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "test" {
}

func (r StreamAnalyticsOutputServiceBusQueueResource) propertyColumns(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s

Expand All @@ -309,7 +325,7 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "test" {
}

func (r StreamAnalyticsOutputServiceBusQueueResource) updatePropertyColumns(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s

Expand All @@ -334,7 +350,7 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "test" {
}

func (r StreamAnalyticsOutputServiceBusQueueResource) systemPropertyColumns(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s

Expand Down Expand Up @@ -363,7 +379,7 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "test" {
}

func (r StreamAnalyticsOutputServiceBusQueueResource) updateSystemPropertyColumns(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s

Expand Down Expand Up @@ -415,7 +431,30 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "import" {
`, template)
}

func (r StreamAnalyticsOutputServiceBusQueueResource) template(data acceptance.TestData) string {
func (r StreamAnalyticsOutputServiceBusQueueResource) authenticationMode(data acceptance.TestData, identity string) string {
template := r.template(data, identity)
return fmt.Sprintf(`
%s

resource "azurerm_stream_analytics_output_servicebus_queue" "test" {
name = "acctestinput-%d"
stream_analytics_job_name = azurerm_stream_analytics_job.test.name
resource_group_name = azurerm_stream_analytics_job.test.resource_group_name
queue_name = azurerm_servicebus_queue.test.name
servicebus_namespace = azurerm_servicebus_namespace.test.name
shared_access_policy_key = azurerm_servicebus_namespace.test.default_primary_key
shared_access_policy_name = "RootManageSharedAccessKey"

serialization {
type = "Json"
encoding = "UTF8"
format = "LineSeparated"
}
}
`, template, data.RandomInteger)
}

func (r StreamAnalyticsOutputServiceBusQueueResource) template(data acceptance.TestData, identity string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identity is unused in this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's used on L435.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

life 435 doesn't exist in this function?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, misunderstood previously. Added identity usage in template now.

return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -457,6 +496,7 @@ resource "azurerm_stream_analytics_job" "test" {
FROM [YourInputAlias]
QUERY

%s
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, identity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ The following arguments are supported:

* `property_columns` - (Optional) A list of property columns to add to the Service Bus Queue output.

* `authentication_mode` - (Optional) The authentication mode for the Stream Output. Possible values are `Msi` and `ConnectionString`. Defaults to `ConnectionString`.

* `system_property_columns` - (Optional) A key-value pair of system property columns that will be attached to the outgoing messages for the Service Bus Queue Output.

-> **NOTE:** The acceptable keys are `ContentType`, `CorrelationId`, `Label`, `MessageId`, `PartitionKey`, `ReplyTo`, `ReplyToSessionId`, `ScheduledEnqueueTimeUtc`, `SessionId`, `TimeToLive` and `To`.
Expand Down