Skip to content

Commit

Permalink
azurerm_stream_analytics_reference_input_mssql: add support for table
Browse files Browse the repository at this point in the history
property
  • Loading branch information
jiaweitao001 committed Sep 1, 2022
1 parent 534174e commit d7ae7c3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ func resourceStreamAnalyticsReferenceMsSql() *pluginsdk.Resource {
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"table": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
}
}
Expand Down Expand Up @@ -158,6 +164,10 @@ func resourceStreamAnalyticsReferenceInputMsSqlCreateUpdate(d *pluginsdk.Resourc
properties.DeltaSnapshotQuery = utils.String(v.(string))
}

if v, ok := d.GetOk("table"); ok {
properties.Table = utils.String(v.(string))
}

props := streamanalytics.Input{
Name: utils.String(id.InputName),
Properties: &streamanalytics.ReferenceInputProperties{
Expand Down Expand Up @@ -221,6 +231,7 @@ func resourceStreamAnalyticsReferenceInputMsSqlRead(d *pluginsdk.ResourceData, m
d.Set("refresh_interval_duration", inputDataSource.AzureSQLReferenceInputDataSourceProperties.RefreshRate)
d.Set("full_snapshot_query", inputDataSource.AzureSQLReferenceInputDataSourceProperties.FullSnapshotQuery)
d.Set("delta_snapshot_query", inputDataSource.AzureSQLReferenceInputDataSourceProperties.DeltaSnapshotQuery)
d.Set("table", inputDataSource.AzureSQLReferenceInputDataSourceProperties.Table)
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ func TestAccStreamAnalyticsReferenceInputMsSql_update(t *testing.T) {
})
}

func TestAccStreamAnalyticsReferenceInputMsSql_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_stream_analytics_reference_input_mssql", "test")
r := StreamAnalyticsReferenceInputMsSqlResource{}

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

func TestAccStreamAnalyticsReferenceInputMsSql_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_stream_analytics_reference_input_mssql", "test")
r := StreamAnalyticsReferenceInputMsSqlResource{}
Expand Down Expand Up @@ -137,6 +152,32 @@ QUERY
`, template, data.RandomInteger)
}

func (r StreamAnalyticsReferenceInputMsSqlResource) complete(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
resource "azurerm_analytics_reference_input_mssql" "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
server = azurerm_mssql_server.test.fully_qualified_domain_name
database = azurerm_mssql_database.test.name
username = "maurice"
password = "ludicrousdisplay"
refresh_type = "RefreshPeriodicallyWithFull"
refresh_interval_duration = "00:10:00"
table = "exampletable"
full_snapshot_query = <<QUERY
SELECT *
INTO [YourOutputAlias]
FROM [YourInputAlias]
QUERY
}
`, template, data.RandomInteger)
}

func (r StreamAnalyticsReferenceInputMsSqlResource) requiresImport(data acceptance.TestData) string {
template := r.basic(data)
return fmt.Sprintf(`
Expand Down Expand Up @@ -197,8 +238,9 @@ resource "azurerm_mssql_server" "test" {
}
resource "azurerm_mssql_database" "test" {
name = "acctest-db-%[1]d"
server_id = azurerm_mssql_server.test.id
name = "acctest-db-%[1]d"
server_id = azurerm_mssql_server.test.id
license_type = "LicenseIncluded"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ The following arguments are supported:

* `delta_snapshot_query` - (Optional) The query used to retrieve incremental changes in the reference data from the MS SQL database. Cannot be set when `refresh_type` is `Static`.

* `table` - (Optional) The name of the table in the Azure SQL database.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:
Expand Down

0 comments on commit d7ae7c3

Please sign in to comment.