Skip to content

Commit

Permalink
Merge pull request #5522 from r0bnet/fix-stream-analytics-job-import
Browse files Browse the repository at this point in the history
Fix import of stream analytics jobs that have been created via Azure Portal
  • Loading branch information
tombuildsstuff authored Feb 11, 2020
2 parents 053a2a5 + abed7bf commit 12d38a9
Showing 1 changed file with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func resourceArmStreamAnalyticsJobCreateUpdate(d *schema.ResourceData, meta inte

// needs to be defined inline for a Create but via a separate API for Update
transformation := streamanalytics.Transformation{
Name: utils.String("Transformation"),
Name: utils.String("main"),
TransformationProperties: &streamanalytics.TransformationProperties{
StreamingUnits: utils.Int32(int32(streamingUnits)),
Query: utils.String(transformationQuery),
Expand Down Expand Up @@ -215,8 +215,15 @@ func resourceArmStreamAnalyticsJobCreateUpdate(d *schema.ResourceData, meta inte
return fmt.Errorf("Error Updating Stream Analytics Job %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if _, err := transformationsClient.Update(ctx, transformation, resourceGroup, name, "Transformation", ""); err != nil {
return fmt.Errorf("Error Updating Transformation for Stream Analytics Job %q (Resource Group %q): %+v", name, resourceGroup, err)
job, err := client.Get(ctx, resourceGroup, name, "transformation")
if err != nil {
return err
}

if readTransformation := job.Transformation; readTransformation != nil {
if _, err := transformationsClient.Update(ctx, transformation, resourceGroup, name, *readTransformation.Name, ""); err != nil {
return fmt.Errorf("Error Updating Transformation for Stream Analytics Job %q (Resource Group %q): %+v", name, resourceGroup, err)
}
}
}

Expand All @@ -225,7 +232,6 @@ func resourceArmStreamAnalyticsJobCreateUpdate(d *schema.ResourceData, meta inte

func resourceArmStreamAnalyticsJobRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).StreamAnalytics.JobsClient
transformationsClient := meta.(*clients.Client).StreamAnalytics.TransformationsClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand All @@ -236,7 +242,7 @@ func resourceArmStreamAnalyticsJobRead(d *schema.ResourceData, meta interface{})
resourceGroup := id.ResourceGroup
name := id.Path["streamingjobs"]

resp, err := client.Get(ctx, resourceGroup, name, "")
resp, err := client.Get(ctx, resourceGroup, name, "transformation")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[DEBUG] Stream Analytics Job %q was not found in Resource Group %q - removing from state!", name, resourceGroup)
Expand All @@ -247,17 +253,6 @@ func resourceArmStreamAnalyticsJobRead(d *schema.ResourceData, meta interface{})
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) {
log.Printf("[DEBUG] Transformation for Stream Analytics Job %q was not found in Resource Group %q - removing from state!", name, resourceGroup)
d.SetId("")
return nil
}

return fmt.Errorf("Error retrieving Transformation for Stream Analytics Job %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.Set("name", name)
d.Set("resource_group_name", resourceGroup)

Expand All @@ -281,11 +276,11 @@ func resourceArmStreamAnalyticsJobRead(d *schema.ResourceData, meta interface{})
d.Set("job_id", props.JobID)
}

if props := transformation.TransformationProperties; props != nil {
if units := props.StreamingUnits; units != nil {
if transformation := resp.StreamingJobProperties.Transformation; transformation != nil {
if units := transformation.StreamingUnits; units != nil {
d.Set("streaming_units", int(*units))
}
d.Set("transformation_query", props.Query)
d.Set("transformation_query", transformation.Query)
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down

0 comments on commit 12d38a9

Please sign in to comment.