From 99a92c04626888453ae1e5719df39f9390fed7af Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Mon, 4 Mar 2019 18:33:37 +0800 Subject: [PATCH 01/34] Add API Management Logger Client. --- azurerm/config.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/azurerm/config.go b/azurerm/config.go index e1811f539d6e..1bf5f65e6f3a 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -129,6 +129,7 @@ type ArmClient struct { // API Management apiManagementGroupClient apimanagement.GroupClient apiManagementGroupUsersClient apimanagement.GroupUserClient + apiManagementLoggerClient apimanagement.LoggerClient apiManagementProductsClient apimanagement.ProductClient apiManagementServiceClient apimanagement.ServiceClient apiManagementUsersClient apimanagement.UserClient @@ -500,6 +501,10 @@ func (c *ArmClient) registerApiManagementServiceClients(endpoint, subscriptionId c.configureClient(&groupUsersClient.Client, auth) c.apiManagementGroupUsersClient = groupUsersClient + loggerClient := apimanagement.NewLoggerClientWithBaseURI(endpoint, subscriptionId) + c.configureClient(&loggerClient.Client, auth) + c.apiManagementLoggerClient = loggerClient + serviceClient := apimanagement.NewServiceClientWithBaseURI(endpoint, subscriptionId) c.configureClient(&serviceClient.Client, auth) c.apiManagementServiceClient = serviceClient From 258f4d983e5d24ca9562b5bf5502a7a5e98a48e2 Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Mon, 4 Mar 2019 21:51:12 +0800 Subject: [PATCH 02/34] Implement API Management Logger. --- azurerm/provider.go | 1 + azurerm/resource_arm_api_management_logger.go | 230 ++++++++++++++++++ 2 files changed, 231 insertions(+) create mode 100644 azurerm/resource_arm_api_management_logger.go diff --git a/azurerm/provider.go b/azurerm/provider.go index 4a8696fb73d9..a3c6093b29b7 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -170,6 +170,7 @@ func Provider() terraform.ResourceProvider { "azurerm_api_management": resourceArmApiManagementService(), "azurerm_api_management_group": resourceArmApiManagementGroup(), "azurerm_api_management_group_user": resourceArmApiManagementGroupUser(), + "azurerm_api_management_logger": resourceArmApiManagementLogger(), "azurerm_api_management_product": resourceArmApiManagementProduct(), "azurerm_api_management_user": resourceArmApiManagementUser(), "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/resource_arm_api_management_logger.go new file mode 100644 index 000000000000..bd4973b10ccc --- /dev/null +++ b/azurerm/resource_arm_api_management_logger.go @@ -0,0 +1,230 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement" + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmApiManagementLogger() *schema.Resource { + return &schema.Resource{ + Create: resourceArmApiManagementLoggerCreateUpdate, + Read: resourceArmApiManagementLoggerRead, + Update: resourceArmApiManagementLoggerCreateUpdate, + Delete: resourceArmApiManagementLoggerDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": azure.SchemaApiManagementChildName(), + + "resource_group_name": resourceGroupNameSchema(), + + "api_management_name": azure.SchemaApiManagementName(), + + "eventhub": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + ForceNew: true, + ConflictsWith: []string{"application_insights"}, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: azure.ValidateEventHubName(), + }, + + "connection_string": { + Type: schema.TypeString, + Required: true, + Sensitive: true, + ValidateFunc: validate.NoEmptyStrings, + }, + }, + }, + }, + + "application_insights": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + ForceNew: true, + ConflictsWith: []string{"eventhub"}, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "instrumentation_key": { + Type: schema.TypeString, + Required: true, + Sensitive: true, + ValidateFunc: validate.NoEmptyStrings, + }, + }, + }, + }, + + "buffered": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + }, + }, + } +} + +func resourceArmApiManagementLoggerCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).apiManagementLoggerClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + serviceName := d.Get("api_management_name").(string) + + eventHubRaw, hasEventHub := d.GetOk("eventhub") + appInsightsRaw, hasAppInsights := d.GetOk("application_insights") + if !hasEventHub && !hasAppInsights { + return fmt.Errorf("Either `eventhub` or `application_insights` is required") + } + + parameters := apimanagement.LoggerContract{ + LoggerContractProperties: &apimanagement.LoggerContractProperties{ + IsBuffered: utils.Bool(d.Get("buffered").(bool)), + Description: utils.String(d.Get("description").(string)), + }, + } + + if hasEventHub { + parameters.LoggerType = apimanagement.AzureEventHub + parameters.Credentials = expandArmApiManagementLoggerEventHub(eventHubRaw.([]interface{})) + } else if hasAppInsights { + parameters.LoggerType = apimanagement.ApplicationInsights + parameters.Credentials = expandArmApiManagementLoggerApplicationInsights(appInsightsRaw.([]interface{})) + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, serviceName, name, parameters, ""); err != nil { + return fmt.Errorf("Error creating Logger %q (Resource Group %q / API Management Service %q): %+v", name, resourceGroup, serviceName, err) + } + + resp, err := client.Get(ctx, resourceGroup, serviceName, name) + if err != nil { + return fmt.Errorf("Error retrieving Logger %q (Resource Group %q / API Management Service %q): %+v", name, resourceGroup, serviceName, err) + } + if resp.ID == nil { + return fmt.Errorf("Cannot read Logger %q (Resource Group %q / API Management Service %q) ID", name, resourceGroup, serviceName) + } + d.SetId(*resp.ID) + + return resourceArmApiManagementLoggerRead(d, meta) +} + +func resourceArmApiManagementLoggerRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).apiManagementLoggerClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return fmt.Errorf("Error parsing API Management Logger ID %q: %+v", d.Id(), err) + } + resourceGroup := id.ResourceGroup + serviceName := id.Path["service"] + name := id.Path["loggers"] + + resp, err := client.Get(ctx, resourceGroup, serviceName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Logger %q (Resource Group %q / API Management Name %q) was not found - removing from state", name, resourceGroup, serviceName) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading Logger %q (Resource Group %q / API Management Name %q): %+v", name, resourceGroup, serviceName, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + d.Set("api_management_name", serviceName) + + if properties := resp.LoggerContractProperties; properties != nil { + d.Set("buffered", properties.IsBuffered) + d.Set("description", properties.Description) + + if properties.LoggerType == apimanagement.AzureEventHub { + if err := d.Set("eventhub", flattenArmApiManagementLoggerEventHub(d, properties.Credentials)); err != nil { + return fmt.Errorf("Error setting `eventhub` for Logger %q (Resource Group %q / API Management Name %q): %s", name, resourceGroup, serviceName, err) + } + } else if properties.LoggerType == apimanagement.ApplicationInsights { + if err := d.Set("application_insights", flattenArmApiManagementLoggerApplicationInsights(d, properties.Credentials)); err != nil { + return fmt.Errorf("Error setting `application_insights` for Logger %q (Resource Group %q / API Management Name %q): %s", name, resourceGroup, serviceName, err) + } + } + } + + return nil +} + +func resourceArmApiManagementLoggerDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).apiManagementLoggerClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return fmt.Errorf("Error parsing API Management Logger ID %q: %+v", d.Id(), err) + } + resourceGroup := id.ResourceGroup + serviceName := id.Path["service"] + name := id.Path["loggers"] + + if resp, err := client.Delete(ctx, resourceGroup, serviceName, name, ""); err != nil { + if !utils.ResponseWasNotFound(resp) { + return fmt.Errorf("Error deleting Logger %q (Resource Group %q / API Management Service %q): %+v", name, resourceGroup, serviceName, err) + } + } + + return nil +} + +func expandArmApiManagementLoggerEventHub(input []interface{}) map[string]*string { + credentials := make(map[string]*string) + eventHub := input[0].(map[string]interface{}) + credentials["name"] = utils.String(eventHub["name"].(string)) + credentials["connectionString"] = utils.String(eventHub["connection_string"].(string)) + return credentials +} + +func expandArmApiManagementLoggerApplicationInsights(input []interface{}) map[string]*string { + credentials := make(map[string]*string) + ai := input[0].(map[string]interface{}) + credentials["instrumentationKey"] = utils.String(ai["instrumentation_key"].(string)) + return credentials +} + +func flattenArmApiManagementLoggerEventHub(d *schema.ResourceData, credentials map[string]*string) []interface{} { + eventHub := make(map[string]interface{}) + if name := credentials["name"]; name != nil { + eventHub["name"] = *name + } + if conn, ok := d.GetOk("eventhub.0.connection_string"); ok { + eventHub["connection_string"] = conn.(string) + } + return []interface{}{eventHub} +} + +func flattenArmApiManagementLoggerApplicationInsights(d *schema.ResourceData, credentials map[string]*string) []interface{} { + appInsights := make(map[string]interface{}) + if conn, ok := d.GetOk("application_insights.0.instrumentation_key"); ok { + appInsights["instrumentation_key"] = conn.(string) + } + return []interface{}{appInsights} +} From f49572b6248cd16b9630ebdea945e35dc34919d3 Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Mon, 4 Mar 2019 22:32:47 +0800 Subject: [PATCH 03/34] Add acceptance tests to API Management Logger --- ...resource_arm_api_management_logger_test.go | 428 ++++++++++++++++++ 1 file changed, 428 insertions(+) create mode 100644 azurerm/resource_arm_api_management_logger_test.go diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go new file mode 100644 index 000000000000..189372e645fb --- /dev/null +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -0,0 +1,428 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMApiManagementLogger_basicEventHub(t *testing.T) { + resourceName := "azurerm_api_management_logger.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), + resource.TestCheckNoResourceAttr(resourceName, "application_insights.#"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMApiManagementLogger_basicApplicationInsights(t *testing.T) { + resourceName := "azurerm_api_management_logger.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementLogger_basicApplicationInsights(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMApiManagementLogger_basicEventHubAppInsightsUpdate(t *testing.T) { + resourceName := "azurerm_api_management_logger.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), + resource.TestCheckNoResourceAttr(resourceName, "application_insights.#"), + ), + }, + { + Config: testAccAzureRMApiManagementLogger_basicApplicationInsights(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + ), + }, + { + Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), + resource.TestCheckNoResourceAttr(resourceName, "application_insights.#"), + ), + }, + }, + }) +} + +func TestAccAzureRMApiManagementLogger_complete(t *testing.T) { + resourceName := "azurerm_api_management_logger.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform test", "false"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), + resource.TestCheckResourceAttr(resourceName, "buffered", "false"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMApiManagementLogger_completeUpdate(t *testing.T) { + resourceName := "azurerm_api_management_logger.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform test", "false"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), + resource.TestCheckResourceAttr(resourceName, "buffered", "false"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + ), + }, + { + Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform update test", "true"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform update test"), + resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + ), + }, + { + Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform test", "false"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), + resource.TestCheckResourceAttr(resourceName, "buffered", "false"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + ), + }, + }, + }) +} + +func TestAccAzureRMApiManagementLogger_basicCompleteUpdate(t *testing.T) { + resourceName := "azurerm_api_management_logger.test" + ri := tf.AccRandTimeInt() + location := testLocation() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementLogger_basicApplicationInsights(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + ), + }, + { + Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform test", "false"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), + resource.TestCheckResourceAttr(resourceName, "buffered", "false"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + ), + }, + { + Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), + resource.TestCheckNoResourceAttr(resourceName, "application_insights.#"), + ), + }, + { + Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform update test", "true"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform update test"), + resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + ), + }, + }, + }) +} + +func testCheckAzureRMApiManagementLoggerExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("API Management Logger not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + serviceName := rs.Primary.Attributes["api_management_name"] + + client := testAccProvider.Meta().(*ArmClient).apiManagementLoggerClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + if resp, err := client.Get(ctx, resourceGroup, serviceName, name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Logger %q (Resource Group %q / API Management Service %q) does not exist", name, resourceGroup, serviceName) + } + return fmt.Errorf("Bad: Get on apiManagementLoggerClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMApiManagementLoggerDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).apiManagementLoggerClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_api_management_logger" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + serviceName := rs.Primary.Attributes["api_management_name"] + + if resp, err := client.Get(ctx, resourceGroup, serviceName, name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on apiManagementLoggerClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMApiManagementLogger_basicEventHub(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_eventhub_namespace" "test" { + name = "acctesteventhubnamespace-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "Basic" +} + +resource "azurerm_eventhub" "test" { + name = "acctesteventhub-%d" + namespace_name = "${azurerm_eventhub_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + partition_count = 2 + message_retention = 1 +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + publisher_name = "pub1" + publisher_email = "pub1@email.com" + + sku { + name = "Developer" + capacity = 1 + } +} + +resource "azurerm_api_management_logger" "test" { + name = "acctestapimnglogger-%d" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + + eventhub { + name = "${azurerm_eventhub.test.name}" + connection_string = "${azurerm_eventhub_namespace.test.default_primary_connection_string}" + } +} +`, rInt, location, rInt, rInt, rInt, rInt) +} + +func testAccAzureRMApiManagementLogger_basicApplicationInsights(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_application_insights" "test" { + name = "acctestappinsights-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + application_type = "Other" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + publisher_name = "pub1" + publisher_email = "pub1@email.com" + + sku { + name = "Developer" + capacity = 1 + } +} + +resource "azurerm_api_management_logger" "test" { + name = "acctestapimnglogger-%d" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + + application_insights { + instrumentation_key = "${azurerm_application_insights.test.instrumentation_key}" + } +} +`, rInt, location, rInt, rInt, rInt) +} + +func testAccAzureRMApiManagementLogger_complete(rInt int, location string, description, buffered string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_application_insights" "test" { + name = "acctestappinsights-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + application_type = "Other" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + publisher_name = "pub1" + publisher_email = "pub1@email.com" + + sku { + name = "Developer" + capacity = 1 + } +} + +resource "azurerm_api_management_logger" "test" { + name = "acctestapimnglogger-%d" + api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + description = "%s" + buffered = %s + + application_insights { + instrumentation_key = "${azurerm_application_insights.test.instrumentation_key}" + } +} +`, rInt, location, rInt, rInt, rInt, description, buffered) +} From 352ed776255576dd9ea2eb299d48fc1c7a7e1ea7 Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Tue, 5 Mar 2019 00:07:04 +0800 Subject: [PATCH 04/34] Add documentation of API Management Logger --- ...resource_arm_api_management_logger_test.go | 21 ++-- website/azurerm.erb | 4 + .../r/api_management_logger.html.markdown | 101 ++++++++++++++++++ 3 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 website/docs/r/api_management_logger.html.markdown diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index 189372e645fb..ab7c269d9eed 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -32,9 +32,10 @@ func TestAccAzureRMApiManagementLogger_basicEventHub(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"eventhub.0.connection_string"}, }, }, }) @@ -61,9 +62,10 @@ func TestAccAzureRMApiManagementLogger_basicApplicationInsights(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"application_insights.0.instrumentation_key"}, }, }, }) @@ -137,9 +139,10 @@ func TestAccAzureRMApiManagementLogger_complete(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"application_insights.0.instrumentation_key"}, }, }, }) diff --git a/website/azurerm.erb b/website/azurerm.erb index 7463396c0272..c2858933a137 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -338,6 +338,10 @@ azurerm_api_management_group_user + > + azurerm_api_management_logger + + > azurerm_api_management_product diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown new file mode 100644 index 000000000000..b45f3ccd732b --- /dev/null +++ b/website/docs/r/api_management_logger.html.markdown @@ -0,0 +1,101 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_api_management_logger" +sidebar_current: "docs-azurerm-resource-api-management-logger" +description: |- + Manages an API Management Logger. +--- + +# azurerm_api_management_logger + +Manages an API Management Logger. + + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West US" +} + +resource "azurerm_application_insights" "example" { + name = "example-appinsights" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + application_type = "Other" +} + +resource "azurerm_api_management" "example" { + name = "example-apim" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + publisher_name = "My Company" + publisher_email = "company@terraform.io" + + sku { + name = "Developer" + capacity = 1 + } +} + +resource "azurerm_api_management_logger" "example" { + name = "example-logger" + api_management_name = "${azurerm_api_management.example.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + description = "This logger is created by Terraform." + + application_insights { + instrumentation_key = "${azurerm_application_insights.example.instrumentation_key}" + } +} +``` + + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of this Logger, which must be unique within the API Management Service. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the Resource Group in which the API Management Service should be exist. Changing this forces a new resource to be created. + +* `api_management_name` - (Required) The name of the API Management Service. Changing this forces a new resource to be created. + +* `eventhub` - (Optional) An `eventhub` block is documented below. + +* `application_insights` - (Optional) An `application_insights` block is documented below. + +* `buffered` - (Optional) Indicates whether records are buffered in the Logger before publishing. Defaults to `true`. + +* `description` - (Optional) A description of this Logger. + +--- + +An `eventhub` block supports the following: + +* `name` - (Required) The name of an `azurerm_eventhub`. + +* `connection_string` - (Required) The connection string of an `azurerm_eventhub_namespace`. + +--- + +An `application_insights` block supports the following: + +* `instrumentation_key` - (Required) The instrumentation key of an `azurerm_application_insights`. + + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The ID of the API Management Logger. + + +## Import + +API Management Loggers can be imported using the `resource id`, e.g. + +```shell +$ terraform import azurerm_api_management_logger.example /subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/example-rg/Microsoft.ApiManagement/service/example-apim/loggers/example-logger +``` From 1b7c4b93481d9eef5f341dd433af9530f83ee912 Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Tue, 5 Mar 2019 16:25:43 +0800 Subject: [PATCH 05/34] Fix IsBuffered not updatable by using Update method --- azurerm/resource_arm_api_management_logger.go | 55 +++++++++++++++++-- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/resource_arm_api_management_logger.go index bd4973b10ccc..5cacf0b89e15 100644 --- a/azurerm/resource_arm_api_management_logger.go +++ b/azurerm/resource_arm_api_management_logger.go @@ -13,9 +13,9 @@ import ( func resourceArmApiManagementLogger() *schema.Resource { return &schema.Resource{ - Create: resourceArmApiManagementLoggerCreateUpdate, + Create: resourceArmApiManagementLoggerCreate, Read: resourceArmApiManagementLoggerRead, - Update: resourceArmApiManagementLoggerCreateUpdate, + Update: resourceArmApiManagementLoggerUpdate, Delete: resourceArmApiManagementLoggerDelete, Importer: &schema.ResourceImporter{ @@ -82,10 +82,19 @@ func resourceArmApiManagementLogger() *schema.Resource { Optional: true, }, }, + + CustomizeDiff: func(d *schema.ResourceDiff, v interface{}) error { + _, hasEventHub := d.GetOk("eventhub") + _, hasAppInsights := d.GetOk("application_insights") + if !hasEventHub && !hasAppInsights { + return fmt.Errorf("Either `eventhub` or `application_insights` is required") + } + return nil + }, } } -func resourceArmApiManagementLoggerCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceArmApiManagementLoggerCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient).apiManagementLoggerClient ctx := meta.(*ArmClient).StopContext @@ -95,9 +104,6 @@ func resourceArmApiManagementLoggerCreateUpdate(d *schema.ResourceData, meta int eventHubRaw, hasEventHub := d.GetOk("eventhub") appInsightsRaw, hasAppInsights := d.GetOk("application_insights") - if !hasEventHub && !hasAppInsights { - return fmt.Errorf("Either `eventhub` or `application_insights` is required") - } parameters := apimanagement.LoggerContract{ LoggerContractProperties: &apimanagement.LoggerContractProperties{ @@ -174,6 +180,43 @@ func resourceArmApiManagementLoggerRead(d *schema.ResourceData, meta interface{} return nil } +func resourceArmApiManagementLoggerUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).apiManagementLoggerClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return fmt.Errorf("Error parsing API Management Logger ID %q: %+v", d.Id(), err) + } + resourceGroup := id.ResourceGroup + serviceName := id.Path["service"] + name := id.Path["loggers"] + + eventHubRaw, hasEventHub := d.GetOk("eventhub") + appInsightsRaw, hasAppInsights := d.GetOk("application_insights") + + parameters := apimanagement.LoggerUpdateContract{ + LoggerUpdateParameters: &apimanagement.LoggerUpdateParameters{ + IsBuffered: utils.Bool(d.Get("buffered").(bool)), + Description: utils.String(d.Get("description").(string)), + }, + } + + if hasEventHub { + parameters.LoggerType = apimanagement.AzureEventHub + parameters.Credentials = expandArmApiManagementLoggerEventHub(eventHubRaw.([]interface{})) + } else if hasAppInsights { + parameters.LoggerType = apimanagement.ApplicationInsights + parameters.Credentials = expandArmApiManagementLoggerApplicationInsights(appInsightsRaw.([]interface{})) + } + + if _, err := client.Update(ctx, resourceGroup, serviceName, name, parameters, ""); err != nil { + return fmt.Errorf("Error updating Logger %q (Resource Group %q / API Management Service %q): %+v", name, resourceGroup, serviceName, err) + } + + return resourceArmApiManagementLoggerRead(d, meta) +} + func resourceArmApiManagementLoggerDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient).apiManagementLoggerClient ctx := meta.(*ArmClient).StopContext From 7a61ac746dedb9e28b13d499307f73815d94f6a6 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 00:06:26 +0800 Subject: [PATCH 06/34] Update azurerm/resource_arm_api_management_logger.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/resource_arm_api_management_logger.go index 5cacf0b89e15..9959baa545b7 100644 --- a/azurerm/resource_arm_api_management_logger.go +++ b/azurerm/resource_arm_api_management_logger.go @@ -142,7 +142,7 @@ func resourceArmApiManagementLoggerRead(d *schema.ResourceData, meta interface{} id, err := parseAzureResourceID(d.Id()) if err != nil { - return fmt.Errorf("Error parsing API Management Logger ID %q: %+v", d.Id(), err) + return err } resourceGroup := id.ResourceGroup serviceName := id.Path["service"] From 8ccac1dc679557c56533870a14d828119d7e5879 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 00:08:49 +0800 Subject: [PATCH 07/34] Update website/docs/r/api_management_logger.html.markdown Co-Authored-By: JunyiYi --- website/docs/r/api_management_logger.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown index b45f3ccd732b..c9e442c7088d 100644 --- a/website/docs/r/api_management_logger.html.markdown +++ b/website/docs/r/api_management_logger.html.markdown @@ -62,7 +62,7 @@ The following arguments are supported: * `api_management_name` - (Required) The name of the API Management Service. Changing this forces a new resource to be created. -* `eventhub` - (Optional) An `eventhub` block is documented below. +* `eventhub` - (Optional) An `eventhub` block as documented below. * `application_insights` - (Optional) An `application_insights` block is documented below. From 8bf46e8f2bf35e7bf6def1a24a3ebf47be68bda0 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 00:12:11 +0800 Subject: [PATCH 08/34] Update website/docs/r/api_management_logger.html.markdown Co-Authored-By: JunyiYi --- website/docs/r/api_management_logger.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown index c9e442c7088d..184004352631 100644 --- a/website/docs/r/api_management_logger.html.markdown +++ b/website/docs/r/api_management_logger.html.markdown @@ -74,7 +74,7 @@ The following arguments are supported: An `eventhub` block supports the following: -* `name` - (Required) The name of an `azurerm_eventhub`. +* `name` - (Required) The name of an EventHub. * `connection_string` - (Required) The connection string of an `azurerm_eventhub_namespace`. From 26b0e8e7c45129f48b829fe8b07f5e6eb2978505 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 00:13:59 +0800 Subject: [PATCH 09/34] Update website/docs/r/api_management_logger.html.markdown Co-Authored-By: JunyiYi --- website/docs/r/api_management_logger.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown index 184004352631..021dd70bd72d 100644 --- a/website/docs/r/api_management_logger.html.markdown +++ b/website/docs/r/api_management_logger.html.markdown @@ -76,7 +76,7 @@ An `eventhub` block supports the following: * `name` - (Required) The name of an EventHub. -* `connection_string` - (Required) The connection string of an `azurerm_eventhub_namespace`. +* `connection_string` - (Required) The connection string of an EventHub Namespace. --- From 16087606e6b1a58697cba3569699287fd8dc3aa7 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 00:16:15 +0800 Subject: [PATCH 10/34] Update website/docs/r/api_management_logger.html.markdown Co-Authored-By: JunyiYi --- website/docs/r/api_management_logger.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown index 021dd70bd72d..d70b7f4f62f9 100644 --- a/website/docs/r/api_management_logger.html.markdown +++ b/website/docs/r/api_management_logger.html.markdown @@ -82,7 +82,7 @@ An `eventhub` block supports the following: An `application_insights` block supports the following: -* `instrumentation_key` - (Required) The instrumentation key of an `azurerm_application_insights`. +* `instrumentation_key` - (Required) The instrumentation key used to push data to Application Insights. ## Attributes Reference From a77ccee4d8e9963d9b0a878c5e65f884d707f8aa Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 00:18:39 +0800 Subject: [PATCH 11/34] Update website/docs/r/api_management_logger.html.markdown Co-Authored-By: JunyiYi --- website/docs/r/api_management_logger.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown index d70b7f4f62f9..fd5b361736f3 100644 --- a/website/docs/r/api_management_logger.html.markdown +++ b/website/docs/r/api_management_logger.html.markdown @@ -64,7 +64,7 @@ The following arguments are supported: * `eventhub` - (Optional) An `eventhub` block as documented below. -* `application_insights` - (Optional) An `application_insights` block is documented below. +* `application_insights` - (Optional) An `application_insights` block as documented below. * `buffered` - (Optional) Indicates whether records are buffered in the Logger before publishing. Defaults to `true`. From 614c93be08056e0b69807689dbabe2da84bdeaef Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 00:20:00 +0800 Subject: [PATCH 12/34] Update azurerm/resource_arm_api_management_logger.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/resource_arm_api_management_logger.go index 9959baa545b7..e107e1fe7dbc 100644 --- a/azurerm/resource_arm_api_management_logger.go +++ b/azurerm/resource_arm_api_management_logger.go @@ -151,7 +151,7 @@ func resourceArmApiManagementLoggerRead(d *schema.ResourceData, meta interface{} resp, err := client.Get(ctx, resourceGroup, serviceName, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] Logger %q (Resource Group %q / API Management Name %q) was not found - removing from state", name, resourceGroup, serviceName) + log.Printf("[INFO] Logger %q (API Management Service %q / Resource Group %q) was not found - removing from state", name, serviceName, resourceGroup) d.SetId("") return nil } From f45985817ba27f22ed63bcc49208bfd09b8329c7 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 00:20:33 +0800 Subject: [PATCH 13/34] Update azurerm/resource_arm_api_management_logger.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/resource_arm_api_management_logger.go index e107e1fe7dbc..4ace34230a95 100644 --- a/azurerm/resource_arm_api_management_logger.go +++ b/azurerm/resource_arm_api_management_logger.go @@ -155,7 +155,7 @@ func resourceArmApiManagementLoggerRead(d *schema.ResourceData, meta interface{} d.SetId("") return nil } - return fmt.Errorf("Error reading Logger %q (Resource Group %q / API Management Name %q): %+v", name, resourceGroup, serviceName, err) + return fmt.Errorf("Error reading Logger %q (API Management Service %q / Resource Group %q): %+v", name, serviceName, resourceGroup, err) } d.Set("name", resp.Name) From 7aaa7a985f610d0b852c0428e52d0216d826666e Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 19 Mar 2019 14:20:47 -0700 Subject: [PATCH 14/34] Update azurerm/resource_arm_api_management_logger.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/resource_arm_api_management_logger.go index 4ace34230a95..b53241bd29f0 100644 --- a/azurerm/resource_arm_api_management_logger.go +++ b/azurerm/resource_arm_api_management_logger.go @@ -190,7 +190,9 @@ func resourceArmApiManagementLoggerUpdate(d *schema.ResourceData, meta interface } resourceGroup := id.ResourceGroup serviceName := id.Path["service"] - name := id.Path["loggers"] + resourceGroup := d.Get("resource_group_name").(string) + serviceName := d.Get("api_management_name").(string) + name := d.Get("name").(string) eventHubRaw, hasEventHub := d.GetOk("eventhub") appInsightsRaw, hasAppInsights := d.GetOk("application_insights") From d4436b79c71391c877df088937e56f9446a90571 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 19 Mar 2019 17:36:28 -0700 Subject: [PATCH 15/34] Update azurerm/resource_arm_api_management_logger_test.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index ab7c269d9eed..9fce9f9cf643 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -188,7 +188,7 @@ func TestAccAzureRMApiManagementLogger_completeUpdate(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "buffered", "false"), resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), - resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, }, From 1b6b10d34d28709bf6cb1d5c3e5abeb024cbb67d Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 19 Mar 2019 17:36:54 -0700 Subject: [PATCH 16/34] Update azurerm/resource_arm_api_management_logger_test.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index 9fce9f9cf643..f62af98e608e 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -177,7 +177,7 @@ func TestAccAzureRMApiManagementLogger_completeUpdate(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "buffered", "true"), resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), - resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, { From 290d830d8e072522256f8acfd4654b25e208f74f Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 19 Mar 2019 17:37:11 -0700 Subject: [PATCH 17/34] Update azurerm/resource_arm_api_management_logger_test.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index f62af98e608e..fdc8dcd83d15 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -135,7 +135,7 @@ func TestAccAzureRMApiManagementLogger_complete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "buffered", "false"), resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), - resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, { From f454e9ff9c0b7eb3e2da7679ed9acc8caed2990a Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 19 Mar 2019 17:37:22 -0700 Subject: [PATCH 18/34] Update azurerm/resource_arm_api_management_logger_test.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index fdc8dcd83d15..9cd629ecdcd3 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -166,7 +166,7 @@ func TestAccAzureRMApiManagementLogger_completeUpdate(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "buffered", "false"), resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), - resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, { From aa9d34790a4791058cf263c39336985b8f332636 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 19 Mar 2019 17:37:33 -0700 Subject: [PATCH 19/34] Update azurerm/resource_arm_api_management_logger_test.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index 9cd629ecdcd3..c24b7535ff7e 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -110,7 +110,7 @@ func TestAccAzureRMApiManagementLogger_basicEventHubAppInsightsUpdate(t *testing resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), - resource.TestCheckNoResourceAttr(resourceName, "application_insights.#"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "0"), ), }, }, From 20f8c5366948d3ee6ceb8f517171f0317fc37752 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 19 Mar 2019 17:37:44 -0700 Subject: [PATCH 20/34] Update azurerm/resource_arm_api_management_logger_test.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index c24b7535ff7e..68ab6c2c18cf 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -89,7 +89,7 @@ func TestAccAzureRMApiManagementLogger_basicEventHubAppInsightsUpdate(t *testing resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), - resource.TestCheckNoResourceAttr(resourceName, "application_insights.#"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "0"), ), }, { From 2099d062ca5159794a8f85cdb9f745d600a299b6 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 19 Mar 2019 17:37:54 -0700 Subject: [PATCH 21/34] Update azurerm/resource_arm_api_management_logger_test.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index 68ab6c2c18cf..855ece47db0c 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -99,7 +99,7 @@ func TestAccAzureRMApiManagementLogger_basicEventHubAppInsightsUpdate(t *testing resource.TestCheckResourceAttr(resourceName, "buffered", "true"), resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), - resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, { From 2fc7ab209fa1d62859d41160cceb7428b917c60d Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 19 Mar 2019 17:38:06 -0700 Subject: [PATCH 22/34] Update azurerm/resource_arm_api_management_logger_test.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index 855ece47db0c..d63b85f97bd1 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -58,7 +58,7 @@ func TestAccAzureRMApiManagementLogger_basicApplicationInsights(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "buffered", "true"), resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), - resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, { From a32a5872d9be1830039c9beec37b0c2cb22220b8 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 19 Mar 2019 17:38:16 -0700 Subject: [PATCH 23/34] Update azurerm/resource_arm_api_management_logger_test.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index d63b85f97bd1..3b0348c79c0e 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -28,7 +28,7 @@ func TestAccAzureRMApiManagementLogger_basicEventHub(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), - resource.TestCheckNoResourceAttr(resourceName, "application_insights.#"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "0"), ), }, { From 6027033ba5a19ca364db81f7083027b53d9d972e Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Tue, 19 Mar 2019 17:39:37 -0700 Subject: [PATCH 24/34] Resolve comments from code review. --- azurerm/resource_arm_api_management_logger.go | 59 ++++++++----------- .../r/api_management_logger.html.markdown | 4 +- 2 files changed, 25 insertions(+), 38 deletions(-) diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/resource_arm_api_management_logger.go index 4ace34230a95..932f73afc823 100644 --- a/azurerm/resource_arm_api_management_logger.go +++ b/azurerm/resource_arm_api_management_logger.go @@ -82,15 +82,6 @@ func resourceArmApiManagementLogger() *schema.Resource { Optional: true, }, }, - - CustomizeDiff: func(d *schema.ResourceDiff, v interface{}) error { - _, hasEventHub := d.GetOk("eventhub") - _, hasAppInsights := d.GetOk("application_insights") - if !hasEventHub && !hasAppInsights { - return fmt.Errorf("Either `eventhub` or `application_insights` is required") - } - return nil - }, } } @@ -102,8 +93,12 @@ func resourceArmApiManagementLoggerCreate(d *schema.ResourceData, meta interface resourceGroup := d.Get("resource_group_name").(string) serviceName := d.Get("api_management_name").(string) - eventHubRaw, hasEventHub := d.GetOk("eventhub") - appInsightsRaw, hasAppInsights := d.GetOk("application_insights") + eventHubRaw := d.Get("eventhub").([]interface{}) + appInsightsRaw := d.Get("application_insights").([]interface{}) + + if len(eventHubRaw) == 0 && len(appInsightsRaw) == 0 { + return fmt.Errorf("Either `eventhub` or `application_insights` is required") + } parameters := apimanagement.LoggerContract{ LoggerContractProperties: &apimanagement.LoggerContractProperties{ @@ -112,12 +107,12 @@ func resourceArmApiManagementLoggerCreate(d *schema.ResourceData, meta interface }, } - if hasEventHub { + if len(eventHubRaw) > 0 { parameters.LoggerType = apimanagement.AzureEventHub - parameters.Credentials = expandArmApiManagementLoggerEventHub(eventHubRaw.([]interface{})) - } else if hasAppInsights { + parameters.Credentials = expandArmApiManagementLoggerEventHub(eventHubRaw) + } else if len(appInsightsRaw) > 0 { parameters.LoggerType = apimanagement.ApplicationInsights - parameters.Credentials = expandArmApiManagementLoggerApplicationInsights(appInsightsRaw.([]interface{})) + parameters.Credentials = expandArmApiManagementLoggerApplicationInsights(appInsightsRaw) } if _, err := client.CreateOrUpdate(ctx, resourceGroup, serviceName, name, parameters, ""); err != nil { @@ -165,15 +160,8 @@ func resourceArmApiManagementLoggerRead(d *schema.ResourceData, meta interface{} if properties := resp.LoggerContractProperties; properties != nil { d.Set("buffered", properties.IsBuffered) d.Set("description", properties.Description) - - if properties.LoggerType == apimanagement.AzureEventHub { - if err := d.Set("eventhub", flattenArmApiManagementLoggerEventHub(d, properties.Credentials)); err != nil { - return fmt.Errorf("Error setting `eventhub` for Logger %q (Resource Group %q / API Management Name %q): %s", name, resourceGroup, serviceName, err) - } - } else if properties.LoggerType == apimanagement.ApplicationInsights { - if err := d.Set("application_insights", flattenArmApiManagementLoggerApplicationInsights(d, properties.Credentials)); err != nil { - return fmt.Errorf("Error setting `application_insights` for Logger %q (Resource Group %q / API Management Name %q): %s", name, resourceGroup, serviceName, err) - } + if err := d.Set("eventhub", flattenArmApiManagementLoggerEventHub(d, properties)); err != nil { + return fmt.Errorf("Error setting `eventhub` for Logger %q (Resource Group %q / API Management Name %q): %s", name, resourceGroup, serviceName, err) } } @@ -253,21 +241,20 @@ func expandArmApiManagementLoggerApplicationInsights(input []interface{}) map[st return credentials } -func flattenArmApiManagementLoggerEventHub(d *schema.ResourceData, credentials map[string]*string) []interface{} { +func flattenArmApiManagementLoggerEventHub(d *schema.ResourceData, properties *apimanagement.LoggerContractProperties) []interface{} { + if properties.LoggerType != apimanagement.AzureEventHub { + return []interface{}{} + } eventHub := make(map[string]interface{}) - if name := credentials["name"]; name != nil { + if name := properties.Credentials["name"]; name != nil { eventHub["name"] = *name } - if conn, ok := d.GetOk("eventhub.0.connection_string"); ok { - eventHub["connection_string"] = conn.(string) + if existing := d.Get("eventhub").([]interface{}); len(existing) > 0 { + existingEventHub := existing[0].(map[string]interface{}) + if conn, ok := existingEventHub["connection_string"]; ok { + eventHub["connection_string"] = conn.(string) + } } - return []interface{}{eventHub} -} -func flattenArmApiManagementLoggerApplicationInsights(d *schema.ResourceData, credentials map[string]*string) []interface{} { - appInsights := make(map[string]interface{}) - if conn, ok := d.GetOk("application_insights.0.instrumentation_key"); ok { - appInsights["instrumentation_key"] = conn.(string) - } - return []interface{}{appInsights} + return []interface{}{eventHub} } diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown index fd5b361736f3..062843b61b20 100644 --- a/website/docs/r/api_management_logger.html.markdown +++ b/website/docs/r/api_management_logger.html.markdown @@ -62,14 +62,14 @@ The following arguments are supported: * `api_management_name` - (Required) The name of the API Management Service. Changing this forces a new resource to be created. -* `eventhub` - (Optional) An `eventhub` block as documented below. - * `application_insights` - (Optional) An `application_insights` block as documented below. * `buffered` - (Optional) Indicates whether records are buffered in the Logger before publishing. Defaults to `true`. * `description` - (Optional) A description of this Logger. +* `eventhub` - (Optional) An `eventhub` block as documented below. + --- An `eventhub` block supports the following: From 35e07bdaf5e0d66255fd43a0eb606d9cfbe3e213 Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Tue, 19 Mar 2019 17:55:38 -0700 Subject: [PATCH 25/34] Remove application insights property checks --- azurerm/resource_arm_api_management_logger.go | 6 --- ...resource_arm_api_management_logger_test.go | 49 +++++-------------- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/resource_arm_api_management_logger.go index cfdddda1ad48..1ed5c4f50337 100644 --- a/azurerm/resource_arm_api_management_logger.go +++ b/azurerm/resource_arm_api_management_logger.go @@ -172,12 +172,6 @@ func resourceArmApiManagementLoggerUpdate(d *schema.ResourceData, meta interface client := meta.(*ArmClient).apiManagementLoggerClient ctx := meta.(*ArmClient).StopContext - id, err := parseAzureResourceID(d.Id()) - if err != nil { - return fmt.Errorf("Error parsing API Management Logger ID %q: %+v", d.Id(), err) - } - resourceGroup := id.ResourceGroup - serviceName := id.Path["service"] resourceGroup := d.Get("resource_group_name").(string) serviceName := d.Get("api_management_name").(string) name := d.Get("name").(string) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index 3b0348c79c0e..02ba44618373 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -28,14 +28,12 @@ func TestAccAzureRMApiManagementLogger_basicEventHub(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "0"), ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"eventhub.0.connection_string"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -56,16 +54,13 @@ func TestAccAzureRMApiManagementLogger_basicApplicationInsights(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"application_insights.0.instrumentation_key"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -89,7 +84,6 @@ func TestAccAzureRMApiManagementLogger_basicEventHubAppInsightsUpdate(t *testing resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "0"), ), }, { @@ -97,8 +91,6 @@ func TestAccAzureRMApiManagementLogger_basicEventHubAppInsightsUpdate(t *testing Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, @@ -110,7 +102,6 @@ func TestAccAzureRMApiManagementLogger_basicEventHubAppInsightsUpdate(t *testing resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "0"), ), }, }, @@ -133,16 +124,13 @@ func TestAccAzureRMApiManagementLogger_complete(t *testing.T) { testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), resource.TestCheckResourceAttr(resourceName, "buffered", "false"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"application_insights.0.instrumentation_key"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -164,8 +152,6 @@ func TestAccAzureRMApiManagementLogger_completeUpdate(t *testing.T) { testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), resource.TestCheckResourceAttr(resourceName, "buffered", "false"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, @@ -175,8 +161,6 @@ func TestAccAzureRMApiManagementLogger_completeUpdate(t *testing.T) { testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform update test"), resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, @@ -186,8 +170,6 @@ func TestAccAzureRMApiManagementLogger_completeUpdate(t *testing.T) { testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), resource.TestCheckResourceAttr(resourceName, "buffered", "false"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, @@ -210,9 +192,7 @@ func TestAccAzureRMApiManagementLogger_basicCompleteUpdate(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), - resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, { @@ -221,9 +201,7 @@ func TestAccAzureRMApiManagementLogger_basicCompleteUpdate(t *testing.T) { testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), resource.TestCheckResourceAttr(resourceName, "buffered", "false"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), - resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, { @@ -234,7 +212,6 @@ func TestAccAzureRMApiManagementLogger_basicCompleteUpdate(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), - resource.TestCheckNoResourceAttr(resourceName, "application_insights.#"), ), }, { @@ -243,9 +220,7 @@ func TestAccAzureRMApiManagementLogger_basicCompleteUpdate(t *testing.T) { testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform update test"), resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), - resource.TestCheckNoResourceAttr(resourceName, "eventhub.#"), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), ), }, }, From 78c94e6938217a23a4063b11181e6a23c5b7612e Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Tue, 19 Mar 2019 22:58:15 -0700 Subject: [PATCH 26/34] Fix acceptance import errors. --- azurerm/resource_arm_api_management_logger_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index 02ba44618373..c5229b99e37f 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -34,6 +34,7 @@ func TestAccAzureRMApiManagementLogger_basicEventHub(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"eventhub.0.connection_string"}, }, }, }) @@ -61,6 +62,7 @@ func TestAccAzureRMApiManagementLogger_basicApplicationInsights(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"application_insights.0.instrumentation_key"}, }, }, }) @@ -131,6 +133,7 @@ func TestAccAzureRMApiManagementLogger_complete(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"application_insights.0.instrumentation_key"}, }, }, }) From 0a4593567fba471180eb0d78d05c9748bdeb53b4 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 09:45:44 -0700 Subject: [PATCH 27/34] Update azurerm/resource_arm_api_management_logger.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/resource_arm_api_management_logger.go index 1ed5c4f50337..e6ddfb5ab979 100644 --- a/azurerm/resource_arm_api_management_logger.go +++ b/azurerm/resource_arm_api_management_logger.go @@ -161,7 +161,7 @@ func resourceArmApiManagementLoggerRead(d *schema.ResourceData, meta interface{} d.Set("buffered", properties.IsBuffered) d.Set("description", properties.Description) if err := d.Set("eventhub", flattenArmApiManagementLoggerEventHub(d, properties)); err != nil { - return fmt.Errorf("Error setting `eventhub` for Logger %q (Resource Group %q / API Management Name %q): %s", name, resourceGroup, serviceName, err) + return fmt.Errorf("Error setting `eventhub`: %s", err) } } From b56e4ccda9fab8af8a821bc74dc201909856ef84 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 09:52:38 -0700 Subject: [PATCH 28/34] Update azurerm/resource_arm_api_management_logger_test.go Co-Authored-By: JunyiYi --- azurerm/resource_arm_api_management_logger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index c5229b99e37f..1aa5ae20e881 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -68,7 +68,7 @@ func TestAccAzureRMApiManagementLogger_basicApplicationInsights(t *testing.T) { }) } -func TestAccAzureRMApiManagementLogger_basicEventHubAppInsightsUpdate(t *testing.T) { +func TestAccAzureRMApiManagementLogger_update(t *testing.T) { resourceName := "azurerm_api_management_logger.test" ri := tf.AccRandTimeInt() location := testLocation() From ddbacf88b22c1cb11804a9f6ae5603b53bde0919 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 09:54:34 -0700 Subject: [PATCH 29/34] Update website/docs/r/api_management_logger.html.markdown Co-Authored-By: JunyiYi --- website/docs/r/api_management_logger.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown index 062843b61b20..d8d5dc88092d 100644 --- a/website/docs/r/api_management_logger.html.markdown +++ b/website/docs/r/api_management_logger.html.markdown @@ -3,7 +3,7 @@ layout: "azurerm" page_title: "Azure Resource Manager: azurerm_api_management_logger" sidebar_current: "docs-azurerm-resource-api-management-logger" description: |- - Manages an API Management Logger. + Manages a Logger within an API Management Service. --- # azurerm_api_management_logger From e1b51f645e633c1cef930c5bc2fd1e799dd089aa Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 09:54:52 -0700 Subject: [PATCH 30/34] Update website/docs/r/api_management_logger.html.markdown Co-Authored-By: JunyiYi --- website/docs/r/api_management_logger.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown index d8d5dc88092d..734a0444a260 100644 --- a/website/docs/r/api_management_logger.html.markdown +++ b/website/docs/r/api_management_logger.html.markdown @@ -8,7 +8,7 @@ description: |- # azurerm_api_management_logger -Manages an API Management Logger. +Manages a Logger within an API Management Service. ## Example Usage From 38c3f86a874b531d5e17bc7d347dafad0dfbd0b8 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 09:55:47 -0700 Subject: [PATCH 31/34] Update website/docs/r/api_management_logger.html.markdown Co-Authored-By: JunyiYi --- website/docs/r/api_management_logger.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown index 734a0444a260..81a6e5dfcd64 100644 --- a/website/docs/r/api_management_logger.html.markdown +++ b/website/docs/r/api_management_logger.html.markdown @@ -58,7 +58,7 @@ The following arguments are supported: * `name` - (Required) The name of this Logger, which must be unique within the API Management Service. Changing this forces a new resource to be created. -* `resource_group_name` - (Required) The name of the Resource Group in which the API Management Service should be exist. Changing this forces a new resource to be created. +* `resource_group_name` - (Required) The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created. * `api_management_name` - (Required) The name of the API Management Service. Changing this forces a new resource to be created. From 24b252831c8bbaf9871a3dc2745e94f712b39f84 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 20 Mar 2019 09:56:25 -0700 Subject: [PATCH 32/34] Update website/docs/r/api_management_logger.html.markdown Co-Authored-By: JunyiYi --- website/docs/r/api_management_logger.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown index 81a6e5dfcd64..00b1cf590688 100644 --- a/website/docs/r/api_management_logger.html.markdown +++ b/website/docs/r/api_management_logger.html.markdown @@ -64,7 +64,7 @@ The following arguments are supported: * `application_insights` - (Optional) An `application_insights` block as documented below. -* `buffered` - (Optional) Indicates whether records are buffered in the Logger before publishing. Defaults to `true`. +* `buffered` - (Optional) Specifies whether records should be buffered in the Logger prior to publishing. Defaults to `true`. * `description` - (Optional) A description of this Logger. From 88b1bea9c0ae0102b99a5e93626f8fa8f67e9834 Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Wed, 20 Mar 2019 11:11:04 -0700 Subject: [PATCH 33/34] Resolve minor comments in PR [round 2] --- azurerm/resource_arm_api_management_logger.go | 20 ++-- ...resource_arm_api_management_logger_test.go | 109 +++++------------- .../r/api_management_logger.html.markdown | 13 +-- 3 files changed, 44 insertions(+), 98 deletions(-) diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/resource_arm_api_management_logger.go index e6ddfb5ab979..7d556d8edf5f 100644 --- a/azurerm/resource_arm_api_management_logger.go +++ b/azurerm/resource_arm_api_management_logger.go @@ -238,19 +238,17 @@ func expandArmApiManagementLoggerApplicationInsights(input []interface{}) map[st } func flattenArmApiManagementLoggerEventHub(d *schema.ResourceData, properties *apimanagement.LoggerContractProperties) []interface{} { - if properties.LoggerType != apimanagement.AzureEventHub { - return []interface{}{} - } - eventHub := make(map[string]interface{}) + result := make([]interface{}, 0) if name := properties.Credentials["name"]; name != nil { + eventHub := make(map[string]interface{}) eventHub["name"] = *name - } - if existing := d.Get("eventhub").([]interface{}); len(existing) > 0 { - existingEventHub := existing[0].(map[string]interface{}) - if conn, ok := existingEventHub["connection_string"]; ok { - eventHub["connection_string"] = conn.(string) + if existing := d.Get("eventhub").([]interface{}); len(existing) > 0 { + existingEventHub := existing[0].(map[string]interface{}) + if conn, ok := existingEventHub["connection_string"]; ok { + eventHub["connection_string"] = conn.(string) + } } + result = append(result, eventHub) } - - return []interface{}{eventHub} + return result } diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index 1aa5ae20e881..da0a394bae2b 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -31,9 +31,9 @@ func TestAccAzureRMApiManagementLogger_basicEventHub(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, ImportStateVerifyIgnore: []string{"eventhub.0.connection_string"}, }, }, @@ -56,55 +56,14 @@ func TestAccAzureRMApiManagementLogger_basicApplicationInsights(t *testing.T) { testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "buffered", "true"), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), ), }, { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"application_insights.0.instrumentation_key"}, - }, - }, - }) -} - -func TestAccAzureRMApiManagementLogger_update(t *testing.T) { - resourceName := "azurerm_api_management_logger.test" - ri := tf.AccRandTimeInt() - location := testLocation() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), - ), - }, - { - Config: testAccAzureRMApiManagementLogger_basicApplicationInsights(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), - ), - }, - { - Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), - ), }, }, }) @@ -127,19 +86,20 @@ func TestAccAzureRMApiManagementLogger_complete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), resource.TestCheckResourceAttr(resourceName, "buffered", "false"), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), ), }, { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"application_insights.0.instrumentation_key"}, }, }, }) } -func TestAccAzureRMApiManagementLogger_completeUpdate(t *testing.T) { +func TestAccAzureRMApiManagementLogger_update(t *testing.T) { resourceName := "azurerm_api_management_logger.test" ri := tf.AccRandTimeInt() location := testLocation() @@ -150,61 +110,58 @@ func TestAccAzureRMApiManagementLogger_completeUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform test", "false"), + Config: testAccAzureRMApiManagementLogger_basicApplicationInsights(ri, location), Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), - resource.TestCheckResourceAttr(resourceName, "buffered", "false"), + resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "description", ""), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), ), }, { - Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform update test", "true"), + Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform update test"), resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(resourceName, "description", ""), + resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), ), }, { Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform test", "false"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), resource.TestCheckResourceAttr(resourceName, "buffered", "false"), + resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), ), }, - }, - }) -} - -func TestAccAzureRMApiManagementLogger_basicCompleteUpdate(t *testing.T) { - resourceName := "azurerm_api_management_logger.test" - ri := tf.AccRandTimeInt() - location := testLocation() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, - Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementLogger_basicApplicationInsights(ri, location), + Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform update test", "true"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform update test"), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), ), }, { Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform test", "false"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), resource.TestCheckResourceAttr(resourceName, "buffered", "false"), + resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), ), }, { @@ -212,20 +169,12 @@ func TestAccAzureRMApiManagementLogger_basicCompleteUpdate(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementLoggerExists(resourceName), resource.TestCheckResourceAttr(resourceName, "buffered", "true"), + resource.TestCheckResourceAttr(resourceName, "description", ""), resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), ), }, - { - Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform update test", "true"), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform update test"), - resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), - ), - }, }, }) } diff --git a/website/docs/r/api_management_logger.html.markdown b/website/docs/r/api_management_logger.html.markdown index 00b1cf590688..c35c07ac8ff1 100644 --- a/website/docs/r/api_management_logger.html.markdown +++ b/website/docs/r/api_management_logger.html.markdown @@ -43,7 +43,6 @@ resource "azurerm_api_management_logger" "example" { name = "example-logger" api_management_name = "${azurerm_api_management.example.name}" resource_group_name = "${azurerm_resource_group.example.name}" - description = "This logger is created by Terraform." application_insights { instrumentation_key = "${azurerm_application_insights.example.instrumentation_key}" @@ -72,17 +71,17 @@ The following arguments are supported: --- -An `eventhub` block supports the following: - -* `name` - (Required) The name of an EventHub. +An `application_insights` block supports the following: -* `connection_string` - (Required) The connection string of an EventHub Namespace. +* `instrumentation_key` - (Required) The instrumentation key used to push data to Application Insights. --- -An `application_insights` block supports the following: +An `eventhub` block supports the following: -* `instrumentation_key` - (Required) The instrumentation key used to push data to Application Insights. +* `name` - (Required) The name of an EventHub. + +* `connection_string` - (Required) The connection string of an EventHub Namespace. ## Attributes Reference From d09a04ec13855ed779cf03be88c9ef6515304669 Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Wed, 20 Mar 2019 12:07:27 -0700 Subject: [PATCH 34/34] Ignore AI properties in Import tests --- azurerm/resource_arm_api_management_logger_test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/resource_arm_api_management_logger_test.go index da0a394bae2b..b41ec978832e 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -61,9 +61,10 @@ func TestAccAzureRMApiManagementLogger_basicApplicationInsights(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"application_insights.#", "application_insights.0.instrumentation_key"}, }, }, }) @@ -91,9 +92,10 @@ func TestAccAzureRMApiManagementLogger_complete(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"application_insights.#", "application_insights.0.instrumentation_key"}, }, }, })