Skip to content

Commit

Permalink
azurerm_stream_analytics_output_blob - support new property authentic…
Browse files Browse the repository at this point in the history
…ation_mode (#16652)
  • Loading branch information
Neil Ye authored Jul 14, 2022
1 parent c1bdd5e commit 6aaf2b6
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ func resourceStreamAnalyticsOutputBlob() *pluginsdk.Resource {
Required: true,
},

"storage_account_key": {
Type: pluginsdk.TypeString,
Required: true,
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"storage_account_name": {
Type: pluginsdk.TypeString,
Required: true,
Expand All @@ -91,6 +84,16 @@ func resourceStreamAnalyticsOutputBlob() *pluginsdk.Resource {

"serialization": schemaStreamAnalyticsOutputSerialization(),

"authentication_mode": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(streamanalytics.AuthenticationModeConnectionString),
ValidateFunc: validation.StringInSlice([]string{
string(streamanalytics.AuthenticationModeConnectionString),
string(streamanalytics.AuthenticationModeMsi),
}, false),
},

"batch_max_wait_time": {
Type: pluginsdk.TypeString,
Optional: true,
Expand All @@ -101,6 +104,13 @@ func resourceStreamAnalyticsOutputBlob() *pluginsdk.Resource {
Optional: true,
ValidateFunc: validation.FloatBetween(0, 10000),
},

"storage_account_key": {
Type: pluginsdk.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
}
}
Expand Down Expand Up @@ -129,7 +139,6 @@ func resourceStreamAnalyticsOutputBlobCreateUpdate(d *pluginsdk.ResourceData, me
containerName := d.Get("storage_container_name").(string)
dateFormat := d.Get("date_format").(string)
pathPattern := d.Get("path_pattern").(string)
storageAccountKey := d.Get("storage_account_key").(string)
storageAccountName := d.Get("storage_account_name").(string)
timeFormat := d.Get("time_format").(string)

Expand All @@ -147,14 +156,15 @@ func resourceStreamAnalyticsOutputBlobCreateUpdate(d *pluginsdk.ResourceData, me
BlobOutputDataSourceProperties: &streamanalytics.BlobOutputDataSourceProperties{
StorageAccounts: &[]streamanalytics.StorageAccount{
{
AccountKey: utils.String(storageAccountKey),
AccountKey: getStorageAccountKey(d.Get("storage_account_key").(string)),
AccountName: utils.String(storageAccountName),
},
},
Container: utils.String(containerName),
DateFormat: utils.String(dateFormat),
PathPattern: utils.String(pathPattern),
TimeFormat: utils.String(timeFormat),
Container: utils.String(containerName),
DateFormat: utils.String(dateFormat),
PathPattern: utils.String(pathPattern),
TimeFormat: utils.String(timeFormat),
AuthenticationMode: streamanalytics.AuthenticationMode(d.Get("authentication_mode").(string)),
},
},
Serialization: serialization,
Expand Down Expand Up @@ -223,6 +233,7 @@ func resourceStreamAnalyticsOutputBlobRead(d *pluginsdk.ResourceData, meta inter
d.Set("path_pattern", v.PathPattern)
d.Set("storage_container_name", v.Container)
d.Set("time_format", v.TimeFormat)
d.Set("authentication_mode", v.AuthenticationMode)

if accounts := v.StorageAccounts; accounts != nil && len(*accounts) > 0 {
account := (*accounts)[0]
Expand Down Expand Up @@ -257,3 +268,11 @@ func resourceStreamAnalyticsOutputBlobDelete(d *pluginsdk.ResourceData, meta int

return nil
}

func getStorageAccountKey(input string) *string {
if input == "" {
return nil
}

return utils.String(input)
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,29 @@ func TestAccStreamAnalyticsOutputBlob_requiresImport(t *testing.T) {
})
}

func TestAccStreamAnalyticsOutputBlob_authenticationMode(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_blob", "test")
r := StreamAnalyticsOutputBlobResource{}
identity := "identity { type = \"SystemAssigned\" }"

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

func (r StreamAnalyticsOutputBlobResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
name := state.Attributes["name"]
jobName := state.Attributes["stream_analytics_job_name"]
Expand All @@ -126,7 +149,7 @@ func (r StreamAnalyticsOutputBlobResource) Exists(ctx context.Context, client *c
}

func (r StreamAnalyticsOutputBlobResource) avro(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s
Expand All @@ -149,7 +172,7 @@ resource "azurerm_stream_analytics_output_blob" "test" {
}

func (r StreamAnalyticsOutputBlobResource) csv(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s
Expand All @@ -174,7 +197,7 @@ resource "azurerm_stream_analytics_output_blob" "test" {
}

func (r StreamAnalyticsOutputBlobResource) json(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s
Expand All @@ -199,7 +222,7 @@ resource "azurerm_stream_analytics_output_blob" "test" {
}

func (r StreamAnalyticsOutputBlobResource) parquet(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s
Expand All @@ -224,7 +247,7 @@ resource "azurerm_stream_analytics_output_blob" "test" {
}

func (r StreamAnalyticsOutputBlobResource) updated(data acceptance.TestData) string {
template := r.template(data)
template := r.template(data, "")
return fmt.Sprintf(`
%s
Expand Down Expand Up @@ -287,7 +310,31 @@ resource "azurerm_stream_analytics_output_blob" "import" {
`, template)
}

func (r StreamAnalyticsOutputBlobResource) template(data acceptance.TestData) string {
func (r StreamAnalyticsOutputBlobResource) authenticationMode(data acceptance.TestData, identity string) string {
return fmt.Sprintf(`
%s
resource "azurerm_stream_analytics_output_blob" "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
storage_account_name = azurerm_storage_account.test.name
storage_container_name = azurerm_storage_container.test.name
path_pattern = "some-pattern"
date_format = "yyyy-MM-dd"
time_format = "HH"
authentication_mode = "Msi"
serialization {
type = "Csv"
encoding = "UTF8"
field_delimiter = ","
}
}
`, r.template(data, identity), data.RandomInteger)
}

func (r StreamAnalyticsOutputBlobResource) template(data acceptance.TestData, identity string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand Down Expand Up @@ -330,6 +377,7 @@ resource "azurerm_stream_analytics_job" "test" {
FROM [YourInputAlias]
QUERY
%s
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger)
`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, identity)
}
6 changes: 4 additions & 2 deletions website/docs/r/stream_analytics_output_blob.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,20 @@ The following arguments are supported:

* `storage_account_name` - (Required) The name of the Storage Account.

* `storage_account_key` - (Required) The Access Key which should be used to connect to this Storage Account.

* `storage_container_name` - (Required) The name of the Container within the Storage Account.

* `time_format` - (Required) The time format. Wherever `{time}` appears in `path_pattern`, the value of this property is used as the time format instead.

* `serialization` - (Required) A `serialization` block as defined below.

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

* `batch_max_wait_time` - (Optional) The maximum wait time per batch in `hh:mm:ss` e.g. `00:02:00` for two minutes.

* `batch_min_rows` - (Optional) The minimum number of rows per batch (must be between `0` and `10000`).

* `storage_account_key` - (Optional) The Access Key which should be used to connect to this Storage Account.

---

A `serialization` block supports the following:
Expand Down

0 comments on commit 6aaf2b6

Please sign in to comment.