-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Data Source/Resource:
azurerm_stream_analytics_job
(#3227)
- Loading branch information
1 parent
2039b09
commit 6d9fb2c
Showing
26 changed files
with
9,844 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmStreamAnalyticsJob() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmStreamAnalyticsJobRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | ||
|
||
"location": locationForDataSourceSchema(), | ||
|
||
"compatibility_level": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"data_locale": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"events_late_arrival_max_delay_in_seconds": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"events_out_of_order_max_delay_in_seconds": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"events_out_of_order_policy": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"job_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"output_error_policy": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"streaming_units": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"transformation_query": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmStreamAnalyticsJobRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).streamAnalyticsJobsClient | ||
transformationsClient := meta.(*ArmClient).streamAnalyticsTransformationsClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name, "") | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Stream Analytics Job %q was not found in Resource Group %q!", name, resourceGroup) | ||
} | ||
|
||
return fmt.Errorf("Error retrieving Stream Analytics Job %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
transformation, err := transformationsClient.Get(ctx, resourceGroup, name, "Transformation") | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Transformation for Stream Analytics Job %q was not found in Resource Group %q!", name, resourceGroup) | ||
} | ||
|
||
return fmt.Errorf("Error retrieving Transformation for Stream Analytics Job %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
d.Set("name", name) | ||
d.Set("resource_group_name", resourceGroup) | ||
|
||
if resp.Location != nil { | ||
d.Set("location", azureRMNormalizeLocation(*resp.Location)) | ||
} | ||
|
||
if props := resp.StreamingJobProperties; props != nil { | ||
d.Set("compatibility_level", string(props.CompatibilityLevel)) | ||
d.Set("data_locale", props.DataLocale) | ||
if props.EventsLateArrivalMaxDelayInSeconds != nil { | ||
d.Set("events_late_arrival_max_delay_in_seconds", int(*props.EventsLateArrivalMaxDelayInSeconds)) | ||
} | ||
if props.EventsOutOfOrderMaxDelayInSeconds != nil { | ||
d.Set("events_out_of_order_max_delay_in_seconds", int(*props.EventsOutOfOrderMaxDelayInSeconds)) | ||
} | ||
d.Set("events_out_of_order_policy", string(props.EventsOutOfOrderPolicy)) | ||
d.Set("job_id", props.JobID) | ||
d.Set("output_error_policy", string(props.OutputErrorPolicy)) | ||
} | ||
|
||
if props := transformation.TransformationProperties; props != nil { | ||
if units := props.StreamingUnits; units != nil { | ||
d.Set("streaming_units", int(*units)) | ||
} | ||
d.Set("transformation_query", props.Query) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" | ||
) | ||
|
||
func TestAccDataSourceAzureRMStreamAnalyticsJob_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_stream_analytics_job.test" | ||
ri := tf.AccRandTimeInt() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMStreamAnalyticsJobDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAzureRMStreamAnalyticsJob_basic(ri, testLocation()), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "job_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAzureRMStreamAnalyticsJob_basic(rInt int, location string) string { | ||
config := testAccAzureRMStreamAnalyticsJob_basic(rInt, location) | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_stream_analytics_job" "test" { | ||
name = "${azurerm_stream_analytics_job.test.name}" | ||
resource_group_name = "${azurerm_stream_analytics_job.test.resource_group_name}" | ||
} | ||
`, config) | ||
} |
Oops, something went wrong.