Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start moving log_analytics to 2.0 #5775

Merged
merged 4 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
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