From 62de371b67935cb0e91a69d9c6d7c8b456097cea Mon Sep 17 00:00:00 2001 From: Lingyu Tang Date: Thu, 16 Apr 2026 14:18:58 +1000 Subject: [PATCH 1/3] rename `moniter_metrics_after_duration` to `monitor_metrics_after_duration` --- .../data_factory_pipeline_resource.go | 48 +++++++- .../data_factory_pipeline_resource_test.go | 107 ++++++++++++++++-- website/docs/5.0-upgrade-guide.html.markdown | 4 + .../r/data_factory_pipeline.html.markdown | 2 +- 4 files changed, 146 insertions(+), 15 deletions(-) diff --git a/internal/services/datafactory/data_factory_pipeline_resource.go b/internal/services/datafactory/data_factory_pipeline_resource.go index 18f2b45b33d3..7bc58cd2b1cd 100644 --- a/internal/services/datafactory/data_factory_pipeline_resource.go +++ b/internal/services/datafactory/data_factory_pipeline_resource.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/pipelines" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datafactory/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -23,7 +24,7 @@ import ( ) func resourceDataFactoryPipeline() *pluginsdk.Resource { - return &pluginsdk.Resource{ + resource := &pluginsdk.Resource{ Create: resourceDataFactoryPipelineCreateUpdate, Read: resourceDataFactoryPipelineRead, Update: resourceDataFactoryPipelineCreateUpdate, @@ -104,12 +105,33 @@ func resourceDataFactoryPipeline() *pluginsdk.Resource { ValidateFunc: validation.StringIsNotEmpty, }, - "moniter_metrics_after_duration": { - Type: pluginsdk.TypeString, - Optional: true, + "monitor_metrics_after_duration": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, }, }, } + + if !features.FivePointOh() { + resource.Schema["moniter_metrics_after_duration"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringIsNotEmpty, + ConflictsWith: []string{"monitor_metrics_after_duration"}, + Deprecated: "`moniter_metrics_after_duration` has been deprecated in favour of `monitor_metrics_after_duration` and will be removed in v5.0 of the AzureRM Provider", + } + resource.Schema["monitor_metrics_after_duration"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringIsNotEmpty, + ConflictsWith: []string{"moniter_metrics_after_duration"}, + } + } + + return resource } func resourceDataFactoryPipelineCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { @@ -187,7 +209,7 @@ func resourceDataFactoryPipelineCreateUpdate(d *pluginsdk.ResourceData, meta int payload.Properties.Concurrency = pointer.To(int64(v.(int))) } - if v, ok := d.GetOk("moniter_metrics_after_duration"); ok { + if v, ok := d.GetOk("monitor_metrics_after_duration"); ok { payload.Properties.Policy = &pipelines.PipelinePolicy{ ElapsedTimeMetric: &pipelines.PipelineElapsedTimeMetricPolicy{ Duration: pointer.To(v), @@ -195,6 +217,16 @@ func resourceDataFactoryPipelineCreateUpdate(d *pluginsdk.ResourceData, meta int } } + if !features.FivePointOh() { + if !pluginsdk.IsExplicitlyNullInConfig(d, "moniter_metrics_after_duration") { + payload.Properties.Policy = &pipelines.PipelinePolicy{ + ElapsedTimeMetric: &pipelines.PipelineElapsedTimeMetricPolicy{ + Duration: pointer.To(d.Get("moniter_metrics_after_duration")), + }, + } + } + } + if v, ok := d.GetOk("folder"); ok { payload.Properties.Folder = &pipelines.PipelineFolder{ Name: pointer.To(v.(string)), @@ -258,7 +290,11 @@ func resourceDataFactoryPipelineRead(d *pluginsdk.ResourceData, meta interface{} elapsedTimeMetricDuration = v } } - d.Set("moniter_metrics_after_duration", elapsedTimeMetricDuration) + + d.Set("monitor_metrics_after_duration", elapsedTimeMetricDuration) + if !features.FivePointOh() { + d.Set("moniter_metrics_after_duration", elapsedTimeMetricDuration) + } if folder := props.Folder; folder != nil { d.Set("folder", pointer.From(folder.Name)) diff --git a/internal/services/datafactory/data_factory_pipeline_resource_test.go b/internal/services/datafactory/data_factory_pipeline_resource_test.go index 3c603138a051..d31b343811c8 100644 --- a/internal/services/datafactory/data_factory_pipeline_resource_test.go +++ b/internal/services/datafactory/data_factory_pipeline_resource_test.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" ) @@ -184,6 +185,94 @@ resource "azurerm_data_factory_pipeline" "test" { } func (PipelineResource) complete(data acceptance.TestData) string { + if !features.FivePointOh() { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-df-%d" + location = "%s" +} + +resource "azurerm_data_factory" "test" { + name = "acctestdfv2%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_data_factory_pipeline" "test" { + name = "acctest%d" + data_factory_id = azurerm_data_factory.test.id + annotations = ["test1", "test2", "test3"] + description = "test description" + moniter_metrics_after_duration = "00:01:00" + + parameters = { + test = "testparameter" + } + + variables = { + foo = "test1" + bar = "test2" + } + + activities_json = < Date: Wed, 22 Apr 2026 18:48:34 +1000 Subject: [PATCH 2/3] remove duplication in test, add release version change in update --- .../data_factory_pipeline_resource_test.go | 275 ++++++------------ 1 file changed, 96 insertions(+), 179 deletions(-) diff --git a/internal/services/datafactory/data_factory_pipeline_resource_test.go b/internal/services/datafactory/data_factory_pipeline_resource_test.go index d31b343811c8..a741704d8f60 100644 --- a/internal/services/datafactory/data_factory_pipeline_resource_test.go +++ b/internal/services/datafactory/data_factory_pipeline_resource_test.go @@ -77,6 +77,35 @@ func TestAccDataFactoryPipeline_update(t *testing.T) { }) } +func TestAccDataFactoryPipeline_migrateDeprecatedToNewField(t *testing.T) { + if features.FivePointOh() { + t.Skip("skipping since `moniter_metrics_after_duration` is removed in 5.0") + } + + data := acceptance.BuildTestData(t, "azurerm_data_factory_pipeline", "test") + r := PipelineResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.monitorMetricsDeprecated(data, "00:01:00"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("moniter_metrics_after_duration").HasValue("00:01:00"), + check.That(data.ResourceName).Key("monitor_metrics_after_duration").HasValue("00:01:00"), + ), + }, + data.ImportStep(), + { + Config: r.monitorMetricsNew(data, "00:02:00"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("monitor_metrics_after_duration").HasValue("00:02:00"), + ), + }, + data.ImportStep(), + }) +} + func TestAccDataFactoryPipeline_activities(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_data_factory_pipeline", "test") r := PipelineResource{} @@ -160,7 +189,7 @@ func (t PipelineResource) appendVariableActivityNameIs(expected string) func(inp } } -func (PipelineResource) basic(data acceptance.TestData) string { +func (PipelineResource) template(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -177,124 +206,35 @@ resource "azurerm_data_factory" "test" { resource_group_name = azurerm_resource_group.test.name } -resource "azurerm_data_factory_pipeline" "test" { - name = "acctest%d" - data_factory_id = azurerm_data_factory.test.id -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func (PipelineResource) complete(data acceptance.TestData) string { - if !features.FivePointOh() { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-df-%d" - location = "%s" -} - -resource "azurerm_data_factory" "test" { - name = "acctestdfv2%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name -} +func (r PipelineResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s resource "azurerm_data_factory_pipeline" "test" { - name = "acctest%d" - data_factory_id = azurerm_data_factory.test.id - annotations = ["test1", "test2", "test3"] - description = "test description" - moniter_metrics_after_duration = "00:01:00" - - parameters = { - test = "testparameter" - } - - variables = { - foo = "test1" - bar = "test2" - } - - activities_json = < Date: Wed, 22 Apr 2026 19:19:40 +1000 Subject: [PATCH 3/3] remove unconventional test --- .../data_factory_pipeline_resource_test.go | 53 ------------------- 1 file changed, 53 deletions(-) diff --git a/internal/services/datafactory/data_factory_pipeline_resource_test.go b/internal/services/datafactory/data_factory_pipeline_resource_test.go index a741704d8f60..550c195c5676 100644 --- a/internal/services/datafactory/data_factory_pipeline_resource_test.go +++ b/internal/services/datafactory/data_factory_pipeline_resource_test.go @@ -77,35 +77,6 @@ func TestAccDataFactoryPipeline_update(t *testing.T) { }) } -func TestAccDataFactoryPipeline_migrateDeprecatedToNewField(t *testing.T) { - if features.FivePointOh() { - t.Skip("skipping since `moniter_metrics_after_duration` is removed in 5.0") - } - - data := acceptance.BuildTestData(t, "azurerm_data_factory_pipeline", "test") - r := PipelineResource{} - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.monitorMetricsDeprecated(data, "00:01:00"), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("moniter_metrics_after_duration").HasValue("00:01:00"), - check.That(data.ResourceName).Key("monitor_metrics_after_duration").HasValue("00:01:00"), - ), - }, - data.ImportStep(), - { - Config: r.monitorMetricsNew(data, "00:02:00"), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("monitor_metrics_after_duration").HasValue("00:02:00"), - ), - }, - data.ImportStep(), - }) -} - func TestAccDataFactoryPipeline_activities(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_data_factory_pipeline", "test") r := PipelineResource{} @@ -426,30 +397,6 @@ JSON `, r.template(data), data.RandomInteger, headerBlock) } -func (r PipelineResource) monitorMetricsDeprecated(data acceptance.TestData, duration string) string { - return fmt.Sprintf(` -%[1]s - -resource "azurerm_data_factory_pipeline" "test" { - name = "acctest%[2]d" - data_factory_id = azurerm_data_factory.test.id - moniter_metrics_after_duration = %[3]q -} -`, r.template(data), data.RandomInteger, duration) -} - -func (r PipelineResource) monitorMetricsNew(data acceptance.TestData, duration string) string { - return fmt.Sprintf(` -%[1]s - -resource "azurerm_data_factory_pipeline" "test" { - name = "acctest%[2]d" - data_factory_id = azurerm_data_factory.test.id - monitor_metrics_after_duration = %[3]q -} -`, r.template(data), data.RandomInteger, duration) -} - func (r PipelineResource) activitiesUpdated(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s