diff --git a/azurerm/resource_arm_stream_analytics_job.go b/azurerm/resource_arm_stream_analytics_job.go index ef8c599be110..6208ae85c2dd 100644 --- a/azurerm/resource_arm_stream_analytics_job.go +++ b/azurerm/resource_arm_stream_analytics_job.go @@ -42,7 +42,8 @@ func resourceArmStreamAnalyticsJob() *schema.Resource { "compatibility_level": { Type: schema.TypeString, - Required: true, + Optional: true, + Computed: true, ValidateFunc: validation.StringInSlice([]string{ // values found in the other API the portal uses string(streamanalytics.OneFullStopZero), @@ -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": { @@ -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) @@ -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), @@ -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 diff --git a/azurerm/resource_arm_stream_analytics_job_test.go b/azurerm/resource_arm_stream_analytics_job_test.go index 7b8871cf93b7..c2d2037e7371 100644 --- a/azurerm/resource_arm_stream_analytics_job_test.go +++ b/azurerm/resource_arm_stream_analytics_job_test.go @@ -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") @@ -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 = < **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`.