Skip to content

Commit

Permalink
start moving log_analytics to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfrahry authored and tombuildsstuff committed Feb 17, 2020
1 parent 6e2924e commit 93f5b18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tests
import (
"fmt"
"net/http"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 93f5b18

Please sign in to comment.