From bcec4fcf54864c5995ccd678065838144e877d2e Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Sun, 16 Feb 2020 09:13:49 -0700 Subject: [PATCH] start moving log_analytics to 2.0 --- ...source_arm_log_analytics_linked_service.go | 67 ++----------------- ..._log_analytics_workspace_linked_service.go | 67 ++----------------- ...e_arm_log_analytics_linked_service_test.go | 38 ----------- ...analytics_workspace_linked_service_test.go | 38 ----------- 4 files changed, 10 insertions(+), 200 deletions(-) diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go index a97b22fc6eda7..7cf97810b9d7c 100644 --- a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go @@ -58,32 +58,11 @@ func resourceArmLogAnalyticsLinkedService() *schema.Resource { }, "resource_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - ConflictsWith: []string{"linked_service_properties.0"}, - }, - - "linked_service_properties": { - Type: schema.TypeList, - Optional: true, - Computed: true, - ForceNew: true, - ConflictsWith: []string{"resource_id"}, - MaxItems: 1, - Deprecated: "This property has been deprecated in favour of the 'resource_id' property and will be removed in version 2.0 of the provider", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "resource_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - }, - }, - }, + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, }, // Exported properties @@ -122,13 +101,6 @@ func resourceArmLogAnalyticsLinkedServiceCreateUpdate(d *schema.ResourceData, me } resourceId := d.Get("resource_id").(string) - if resourceId == "" { - props := d.Get("linked_service_properties").([]interface{}) - resourceId = expandLogAnalyticsLinkedServiceProperties(props) - if resourceId == "" { - return fmt.Errorf("A `resource_id` must be specified either using the `resource_id` field at the top level or within the `linked_service_properties` block") - } - } t := d.Get("tags").(map[string]interface{}) parameters := operationalinsights.LinkedService{ @@ -187,11 +159,6 @@ func resourceArmLogAnalyticsLinkedServiceRead(d *schema.ResourceData, meta inter d.Set("resource_id", props.ResourceID) } - linkedServiceProperties := flattenLogAnalyticsLinkedServiceProperties(resp.LinkedServiceProperties) - if err := d.Set("linked_service_properties", linkedServiceProperties); err != nil { - return fmt.Errorf("Error setting `linked_service_properties`: %+v", err) - } - return tags.FlattenAndSet(d, resp.Tags) } @@ -220,27 +187,3 @@ func resourceArmLogAnalyticsLinkedServiceDelete(d *schema.ResourceData, meta int return nil } - -func expandLogAnalyticsLinkedServiceProperties(input []interface{}) string { - if len(input) == 0 { - return "" - } - - props := input[0].(map[string]interface{}) - return props["resource_id"].(string) -} - -func flattenLogAnalyticsLinkedServiceProperties(input *operationalinsights.LinkedServiceProperties) []interface{} { - if input == nil { - return []interface{}{} - } - - properties := make(map[string]interface{}) - - // resource id linked service - if resourceID := input.ResourceID; resourceID != nil { - properties["resource_id"] = interface{}(*resourceID) - } - - return []interface{}{properties} -} diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service.go index a4377a5957c9e..6e848087093ae 100644 --- a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service.go @@ -65,32 +65,11 @@ As such the existing 'azurerm_log_analytics_workspace_linked_service' resource i }, "resource_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - ConflictsWith: []string{"linked_service_properties.0"}, - }, - - "linked_service_properties": { - Type: schema.TypeList, - Optional: true, - Computed: true, - ForceNew: true, - ConflictsWith: []string{"resource_id"}, - MaxItems: 1, - Deprecated: "This property has been deprecated in favour of the 'resource_id' property and will be removed in version 2.0 of the provider", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "resource_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - }, - }, - }, + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, }, // Exported properties @@ -129,13 +108,6 @@ func resourceArmLogAnalyticsWorkspaceLinkedServiceCreateUpdate(d *schema.Resourc } resourceId := d.Get("resource_id").(string) - if resourceId == "" { - props := d.Get("linked_service_properties").([]interface{}) - resourceId = expandLogAnalyticsWorkspaceLinkedServiceProperties(props) - if resourceId == "" { - return fmt.Errorf("A `resource_id` must be specified either using the `resource_id` field at the top level or within the `linked_service_properties` block") - } - } t := d.Get("tags").(map[string]interface{}) parameters := operationalinsights.LinkedService{ @@ -194,11 +166,6 @@ func resourceArmLogAnalyticsWorkspaceLinkedServiceRead(d *schema.ResourceData, m d.Set("resource_id", props.ResourceID) } - linkedServiceProperties := flattenLogAnalyticsWorkspaceLinkedServiceProperties(resp.LinkedServiceProperties) - if err := d.Set("linked_service_properties", linkedServiceProperties); err != nil { - return fmt.Errorf("Error setting `linked_service_properties`: %+v", err) - } - return tags.FlattenAndSet(d, resp.Tags) } @@ -227,27 +194,3 @@ func resourceArmLogAnalyticsWorkspaceLinkedServiceDelete(d *schema.ResourceData, return nil } - -func expandLogAnalyticsWorkspaceLinkedServiceProperties(input []interface{}) string { - if len(input) == 0 { - return "" - } - - props := input[0].(map[string]interface{}) - return props["resource_id"].(string) -} - -func flattenLogAnalyticsWorkspaceLinkedServiceProperties(input *operationalinsights.LinkedServiceProperties) []interface{} { - if input == nil { - return []interface{}{} - } - - properties := make(map[string]interface{}) - - // resource id linked service - if resourceID := input.ResourceID; resourceID != nil { - properties["resource_id"] = interface{}(*resourceID) - } - - return []interface{}{properties} -} diff --git a/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_linked_service_test.go b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_linked_service_test.go index d2bf0d4afb052..4b5e593d18ac8 100644 --- a/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_linked_service_test.go +++ b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_linked_service_test.go @@ -3,7 +3,6 @@ package tests import ( "fmt" "net/http" - "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -85,43 +84,6 @@ func TestAccAzureRMLogAnalyticsLinkedService_complete(t *testing.T) { }) } -// Deprecated - remove in 2.0 -func TestAccAzureRMLogAnalyticsLinkedService_noResourceID(t *testing.T) { - data := acceptance.BuildTestData(t, "ignored", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogAnalyticsLinkedServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogAnalyticsLinkedService_noResourceID(data), - ExpectError: regexp.MustCompile("A `resource_id` must be specified either using the `resource_id` field at the top level or within the `linked_service_properties` block"), - }, - }, - }) -} - -// Deprecated - remove in 2.0 -func TestAccAzureRMLogAnalyticsLinkedService_linkedServiceProperties(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_log_analytics_linked_service", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogAnalyticsLinkedServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogAnalyticsLinkedService_linkedServiceProperties(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsLinkedServiceExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - func testCheckAzureRMLogAnalyticsLinkedServiceDestroy(s *terraform.State) error { conn := acceptance.AzureProvider.Meta().(*clients.Client).LogAnalytics.LinkedServicesClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext diff --git a/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_linked_service_test.go b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_linked_service_test.go index abe93f3ce8f5b..a7bd2bf654e5f 100644 --- a/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_linked_service_test.go +++ b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_linked_service_test.go @@ -3,7 +3,6 @@ package tests import ( "fmt" "net/http" - "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -85,43 +84,6 @@ func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_complete(t *testing.T) { }) } -// Deprecated - remove in 2.0 -func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_noResourceID(t *testing.T) { - data := acceptance.BuildTestData(t, "ignored", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_noResourceID(data), - ExpectError: regexp.MustCompile("A `resource_id` must be specified either using the `resource_id` field at the top level or within the `linked_service_properties` block"), - }, - }, - }) -} - -// Deprecated - remove in 2.0 -func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_linkedServiceProperties(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace_linked_service", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogAnalyticsLinkedServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_linkedServiceProperties(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - func testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceDestroy(s *terraform.State) error { conn := acceptance.AzureProvider.Meta().(*clients.Client).LogAnalytics.LinkedServicesClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext