From abed7bff4859838bc43156166649aea99a30717d Mon Sep 17 00:00:00 2001 From: rob Date: Sat, 25 Jan 2020 13:10:04 +0100 Subject: [PATCH] rename default transformation name from Transformation to main (like the portal does); enable import of not jobs which were not created in TF; keep backwards compatibility --- .../resource_arm_stream_analytics_job.go | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job.go index 92ecd186f261..fa8a83e68153 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job.go @@ -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), @@ -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) + } } } @@ -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() @@ -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) @@ -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) @@ -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)