Skip to content

Commit

Permalink
Addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfrahry committed Apr 15, 2019
1 parent 9f1445d commit 72f2633
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
25 changes: 14 additions & 11 deletions azurerm/resource_arm_data_factory_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand All @@ -33,6 +34,10 @@ func resourceArmDataFactoryPipeline() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringMatch(
regexp.MustCompile(`^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`),
`Invalid data_factory_name, see https://docs.microsoft.com/en-us/azure/data-factory/naming-rules`,
),
},

"resource_group_name": resourceGroupNameSchema(),
Expand Down Expand Up @@ -96,14 +101,16 @@ func resourceArmDataFactoryPipelineCreateUpdate(d *schema.ResourceData, meta int
if v, ok := d.GetOk("annotations"); ok {
annotations := v.([]interface{})
pipeline.Annotations = &annotations
} else {
annotations := make([]interface{}, 0)
pipeline.Annotations = &annotations
}

config := datafactory.PipelineResource{
Pipeline: pipeline,
}

_, err := client.CreateOrUpdate(ctx, resourceGroupName, dataFactoryName, name, config, "")
if err != nil {
if _, err := client.CreateOrUpdate(ctx, resourceGroupName, dataFactoryName, name, config, ""); err != nil {
return fmt.Errorf("Error creating Data Factory Pipeline %q (Resource Group %q / Data Factory %q): %+v", name, resourceGroupName, dataFactoryName, err)
}

Expand Down Expand Up @@ -131,26 +138,23 @@ func resourceArmDataFactoryPipelineRead(d *schema.ResourceData, meta interface{}
}
dataFactoryName := id.Path["factories"]
name := id.Path["pipelines"]
resourceGroupName := id.ResourceGroup

resp, err := client.Get(ctx, resourceGroupName, dataFactoryName, name, "")
resp, err := client.Get(ctx, id.ResourceGroup, dataFactoryName, name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
log.Printf("[DEBUG] Data Factory Pipeline %q was not found in Resource Group %q - removing from state!", name, resourceGroupName)
log.Printf("[DEBUG] Data Factory Pipeline %q was not found in Resource Group %q - removing from state!", name, id.ResourceGroup)
return nil
}
return fmt.Errorf("Error reading the state of Data Factory Pipeline %q: %+v", name, err)
}

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroupName)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("data_factory_name", dataFactoryName)

if props := resp.Pipeline; props != nil {
if props.Description != nil {
d.Set("description", props.Description)
}
d.Set("description", props.Description)

parameters := flattenDataFactoryParameters(props.Parameters)
if err := d.Set("parameters", parameters); err != nil {
Expand Down Expand Up @@ -184,8 +188,7 @@ func resourceArmDataFactoryPipelineDelete(d *schema.ResourceData, meta interface
name := id.Path["pipelines"]
resourceGroupName := id.ResourceGroup

_, err = client.Delete(ctx, resourceGroupName, dataFactoryName, name)
if err != nil {
if _, err = client.Delete(ctx, resourceGroupName, dataFactoryName, name); err != nil {
return fmt.Errorf("Error deleting Data Factory Pipeline %q (Resource Group %q / Data Factory %q): %+v", name, resourceGroupName, dataFactoryName, err)
}

Expand Down
10 changes: 6 additions & 4 deletions azurerm/resource_arm_data_factory_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
func TestAccAzureRMDataFactoryPipeline_basic(t *testing.T) {
resourceName := "azurerm_data_factory_pipeline.test"
ri := tf.AccRandTimeInt()
config := testAccAzureRMDataFactoryPipeline_basic(ri, testLocation())
location := testLocation()
config := testAccAzureRMDataFactoryPipeline_basic(ri, location)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -38,8 +39,9 @@ func TestAccAzureRMDataFactoryPipeline_basic(t *testing.T) {
func TestAccAzureRMDataFactoryPipeline_update(t *testing.T) {
resourceName := "azurerm_data_factory_pipeline.test"
ri := tf.AccRandTimeInt()
config := testAccAzureRMDataFactoryPipeline_update1(ri, testLocation())
config2 := testAccAzureRMDataFactoryPipeline_update2(ri, testLocation())
location := testLocation()
config := testAccAzureRMDataFactoryPipeline_update1(ri, location)
config2 := testAccAzureRMDataFactoryPipeline_update2(ri, location)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -116,7 +118,7 @@ func testCheckAzureRMDataFactoryPipelineExists(resourceName string) resource.Tes
resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Bad: API Management Property %q (Resource Group %q / Data Factory %q) does not exist", name, resourceGroup, dataFactoryName)
return fmt.Errorf("Bad: Data Factory Pipeline %q (Resource Group %q / Data Factory %q) does not exist", name, resourceGroup, dataFactoryName)
}
return fmt.Errorf("Bad: Get on DataFactoryPipelineClient: %+v", err)
}
Expand Down

0 comments on commit 72f2633

Please sign in to comment.