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_job Removing requirement of optional properties #4190

Merged
merged 5 commits into from
Sep 13, 2019
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
28 changes: 18 additions & 10 deletions azurerm/resource_arm_stream_analytics_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func resourceArmStreamAnalyticsJob() *schema.Resource {

"compatibility_level": {
Type: schema.TypeString,
Required: true,
Optional: true,
nexxai marked this conversation as resolved.
Show resolved Hide resolved
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
// values found in the other API the portal uses
string(streamanalytics.OneFullStopZero),
Expand All @@ -55,40 +56,45 @@ func resourceArmStreamAnalyticsJob() *schema.Resource {

"data_locale": {
Type: schema.TypeString,
Required: true,
Optional: true,
Computed: true,
ValidateFunc: validate.NoEmptyStrings,
},

"events_late_arrival_max_delay_in_seconds": {
Type: schema.TypeInt,
Required: true,
// portal allows for up to 20d 23h 59m 59s
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(-1, 1814399),
Default: 5,
},

"events_out_of_order_max_delay_in_seconds": {
Type: schema.TypeInt,
Required: true,
// portal allows for up to 9m 59s
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 599),
Default: 0,
},

"events_out_of_order_policy": {
Type: schema.TypeString,
Required: true,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
string(streamanalytics.Adjust),
string(streamanalytics.Drop),
}, false),
Default: string(streamanalytics.Adjust),
},

"output_error_policy": {
Type: schema.TypeString,
Required: true,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
string(streamanalytics.OutputErrorPolicyDrop),
string(streamanalytics.OutputErrorPolicyStop),
}, false),
Default: string(streamanalytics.OutputErrorPolicyDrop),
},

"streaming_units": {
Expand Down Expand Up @@ -137,7 +143,6 @@ func resourceArmStreamAnalyticsJobCreateUpdate(d *schema.ResourceData, meta inte
}

compatibilityLevel := d.Get("compatibility_level").(string)
dataLocale := d.Get("data_locale").(string)
eventsLateArrivalMaxDelayInSeconds := d.Get("events_late_arrival_max_delay_in_seconds").(int)
eventsOutOfOrderMaxDelayInSeconds := d.Get("events_out_of_order_max_delay_in_seconds").(int)
eventsOutOfOrderPolicy := d.Get("events_out_of_order_policy").(string)
Expand All @@ -164,7 +169,6 @@ func resourceArmStreamAnalyticsJobCreateUpdate(d *schema.ResourceData, meta inte
Name: streamanalytics.Standard,
},
CompatibilityLevel: streamanalytics.CompatibilityLevel(compatibilityLevel),
DataLocale: utils.String(dataLocale),
EventsLateArrivalMaxDelayInSeconds: utils.Int32(int32(eventsLateArrivalMaxDelayInSeconds)),
EventsOutOfOrderMaxDelayInSeconds: utils.Int32(int32(eventsOutOfOrderMaxDelayInSeconds)),
EventsOutOfOrderPolicy: streamanalytics.EventsOutOfOrderPolicy(eventsOutOfOrderPolicy),
Expand All @@ -173,6 +177,10 @@ func resourceArmStreamAnalyticsJobCreateUpdate(d *schema.ResourceData, meta inte
Tags: tags.Expand(t),
}

if dataLocale, ok := d.GetOk("data_locale"); ok {
props.StreamingJobProperties.DataLocale = utils.String(dataLocale.(string))
}

if d.IsNewResource() {
props.StreamingJobProperties.Transformation = &transformation

Expand Down
57 changes: 55 additions & 2 deletions azurerm/resource_arm_stream_analytics_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ func TestAccAzureRMStreamAnalyticsJob_basic(t *testing.T) {
})
}

func TestAccAzureRMStreamAnalyticsJob_complete(t *testing.T) {
resourceName := "azurerm_stream_analytics_job.test"
ri := tf.AccRandTimeInt()
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMStreamAnalyticsJobDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMStreamAnalyticsJob_complete(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStreamAnalyticsJobExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.environment", "Test"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMStreamAnalyticsJob_requiresImport(t *testing.T) {
if features.ShouldResourcesBeImported() {
t.Skip("Skipping since resources aren't required to be imported")
Expand Down Expand Up @@ -159,8 +186,33 @@ resource "azurerm_stream_analytics_job" "test" {
name = "acctestjob-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
streaming_units = 3

tags = {
environment = "Test"
}

transformation_query = <<QUERY
SELECT *
INTO [YourOutputAlias]
FROM [YourInputAlias]
QUERY
}`, rInt, location, rInt)
}

func testAccAzureRMStreamAnalyticsJob_complete(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_stream_analytics_job" "test" {
name = "acctestjob-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
data_locale = "en-GB"
compatibility_level = "1.0"
data_locale = "en-GB"
events_late_arrival_max_delay_in_seconds = 60
events_out_of_order_max_delay_in_seconds = 50
events_out_of_order_policy = "Adjust"
Expand Down Expand Up @@ -197,6 +249,7 @@ resource "azurerm_stream_analytics_job" "import" {
output_error_policy = "${azurerm_stream_analytics_job.test.output_error_policy}"
streaming_units = "${azurerm_stream_analytics_job.test.streaming_units}"
transformation_query = "${azurerm_stream_analytics_job.test.transformation_query}"
tags = "${azurerm_stream_analytics_job.test.tags}"
}
`, template)
}
Expand All @@ -212,8 +265,8 @@ resource "azurerm_stream_analytics_job" "test" {
name = "acctestjob-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
data_locale = "en-GB"
compatibility_level = "1.1"
data_locale = "en-US"
events_late_arrival_max_delay_in_seconds = 10
events_out_of_order_max_delay_in_seconds = 20
events_out_of_order_policy = "Drop"
Expand Down
10 changes: 5 additions & 5 deletions website/docs/r/stream_analytics_job.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ The following arguments are supported:

-> **NOTE:** Support for Compatibility Level 1.2 is dependent on a new version of the Stream Analytics API, which [being tracked in this issue](https://github.com/Azure/azure-rest-api-specs/issues/5604).

* `data_locale` - (Required) Specifies the Data Locale of the Job, which [should be a supported .NET Culture](https://msdn.microsoft.com/en-us/library/system.globalization.culturetypes(v=vs.110).aspx).
* `data_locale` - (Optional) Specifies the Data Locale of the Job, which [should be a supported .NET Culture](https://msdn.microsoft.com/en-us/library/system.globalization.culturetypes(v=vs.110).aspx).

* `events_late_arrival_max_delay_in_seconds` - (Required) Specifies the maximum tolerable delay in seconds where events arriving late could be included. Supported range is `-1` (indefinite) to `1814399` (20d 23h 59m 59s).
* `events_late_arrival_max_delay_in_seconds` - (Optional) Specifies the maximum tolerable delay in seconds where events arriving late could be included. Supported range is `-1` (indefinite) to `1814399` (20d 23h 59m 59s). Default is `0`.

* `events_out_of_order_max_delay_in_seconds` - (Required) Specifies the maximum tolerable delay in seconds where out-of-order events can be adjusted to be back in order. Supported range is `0` to `599` (9m 59s).
* `events_out_of_order_max_delay_in_seconds` - (Optional) Specifies the maximum tolerable delay in seconds where out-of-order events can be adjusted to be back in order. Supported range is `0` to `599` (9m 59s). Default is `5`.

* `events_out_of_order_policy` - (Required) Specifies the policy which should be applied to events which arrive out of order in the input event stream. Possible values are `Adjust` and `Drop`.
* `events_out_of_order_policy` - (Optional) Specifies the policy which should be applied to events which arrive out of order in the input event stream. Possible values are `Adjust` and `Drop`. Default is `Adjust`.

* `output_error_policy` - (Required) Specifies the policy which should be applied to events which arrive at the output and cannot be written to the external storage due to being malformed (such as missing column values, column values of wrong type or size). Possible values are `Drop` and `Stop`.
* `output_error_policy` - (Optional) Specifies the policy which should be applied to events which arrive at the output and cannot be written to the external storage due to being malformed (such as missing column values, column values of wrong type or size). Possible values are `Drop` and `Stop`. Default is `Drop`.

* `streaming_units` - (Required) Specifies the number of streaming units that the streaming job uses. Supported values are `1`, `3`, `6` and multiples of `6` up to `120`.

Expand Down