diff --git a/azurerm/config.go b/azurerm/config.go index f5c602875be8..c63b9751e5ab 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 apiManagementProductGroupsClient apimanagement.ProductGroupClient apiManagementServiceClient apimanagement.ServiceClient @@ -501,6 +502,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 diff --git a/azurerm/provider.go b/azurerm/provider.go index 46b0865704c5..a4aac0a4ff6f 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_product_group": resourceArmApiManagementProductGroup(), "azurerm_api_management_user": resourceArmApiManagementUser(), diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/resource_arm_api_management_logger.go new file mode 100644 index 000000000000..7d556d8edf5f --- /dev/null +++ b/azurerm/resource_arm_api_management_logger.go @@ -0,0 +1,254 @@ +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: resourceArmApiManagementLoggerCreate, + Read: resourceArmApiManagementLoggerRead, + Update: resourceArmApiManagementLoggerUpdate, + 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 resourceArmApiManagementLoggerCreate(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 := 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{ + IsBuffered: utils.Bool(d.Get("buffered").(bool)), + Description: utils.String(d.Get("description").(string)), + }, + } + + if len(eventHubRaw) > 0 { + parameters.LoggerType = apimanagement.AzureEventHub + parameters.Credentials = expandArmApiManagementLoggerEventHub(eventHubRaw) + } else if len(appInsightsRaw) > 0 { + parameters.LoggerType = apimanagement.ApplicationInsights + parameters.Credentials = expandArmApiManagementLoggerApplicationInsights(appInsightsRaw) + } + + 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 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 (API Management Service %q / Resource Group %q) was not found - removing from state", name, serviceName, resourceGroup) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading Logger %q (API Management Service %q / Resource Group %q): %+v", name, serviceName, resourceGroup, 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 err := d.Set("eventhub", flattenArmApiManagementLoggerEventHub(d, properties)); err != nil { + return fmt.Errorf("Error setting `eventhub`: %s", err) + } + } + + return nil +} + +func resourceArmApiManagementLoggerUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).apiManagementLoggerClient + ctx := meta.(*ArmClient).StopContext + + 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") + + 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 + + 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, properties *apimanagement.LoggerContractProperties) []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) + } + } + result = append(result, eventHub) + } + return result +} 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..b41ec978832e --- /dev/null +++ b/azurerm/resource_arm_api_management_logger_test.go @@ -0,0 +1,360 @@ +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"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"eventhub.0.connection_string"}, + }, + }, + }) +} + +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, "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.#", "application_insights.0.instrumentation_key"}, + }, + }, + }) +} + +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, "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.#", "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_basicApplicationInsights(ri, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + 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_basicEventHub(ri, location), + 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 test", "false"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementLoggerExists(resourceName), + 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"), + ), + }, + { + 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, "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"), + ), + }, + { + Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), + 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"), + ), + }, + }, + }) +} + +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) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index fbf41b5d216e..85b02736cb86 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..c35c07ac8ff1 --- /dev/null +++ b/website/docs/r/api_management_logger.html.markdown @@ -0,0 +1,100 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_api_management_logger" +sidebar_current: "docs-azurerm-resource-api-management-logger" +description: |- + Manages a Logger within an API Management Service. +--- + +# azurerm_api_management_logger + +Manages a Logger within an API Management Service. + + +## 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}" + + 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 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. + +* `application_insights` - (Optional) An `application_insights` block as documented below. + +* `buffered` - (Optional) Specifies whether records should be buffered in the Logger prior to publishing. Defaults to `true`. + +* `description` - (Optional) A description of this Logger. + +* `eventhub` - (Optional) An `eventhub` block as documented below. + +--- + +An `application_insights` block supports the following: + +* `instrumentation_key` - (Required) The instrumentation key used to push data to Application Insights. + +--- + +An `eventhub` block supports the following: + +* `name` - (Required) The name of an EventHub. + +* `connection_string` - (Required) The connection string of an EventHub Namespace. + + +## 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 +```