Skip to content

Commit

Permalink
Merge pull request #2268 from terraform-providers/functionapp_builtinlog
Browse files Browse the repository at this point in the history
Add `enable_builtin_logging` to `azurerm_function_app`
  • Loading branch information
katbyte authored Nov 9, 2018
2 parents c873b1f + edc8c40 commit b7eb318
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 1 deletion.
17 changes: 16 additions & 1 deletion azurerm/resource_arm_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func resourceArmFunctionApp() *schema.Resource {
Optional: true,
},

"enable_builtin_logging": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},

"connection_string": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -452,6 +458,9 @@ func resourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) error
d.Set("storage_connection_string", appSettings["AzureWebJobsStorage"])
d.Set("version", appSettings["FUNCTIONS_EXTENSION_VERSION"])

dashboard, ok := appSettings["AzureWebJobsDashboard"]
d.Set("enable_builtin_logging", ok && dashboard != "")

delete(appSettings, "AzureWebJobsDashboard")
delete(appSettings, "AzureWebJobsStorage")
delete(appSettings, "FUNCTIONS_EXTENSION_VERSION")
Expand Down Expand Up @@ -524,11 +533,17 @@ func getBasicFunctionAppAppSettings(d *schema.ResourceData, appServiceTier strin
contentShare := strings.ToLower(d.Get("name").(string)) + "-content"

basicSettings := []web.NameValuePair{
{Name: &dashboardPropName, Value: &storageConnection},
{Name: &storagePropName, Value: &storageConnection},
{Name: &functionVersionPropName, Value: &functionVersion},
}

if d.Get("enable_builtin_logging").(bool) {
basicSettings = append(basicSettings, web.NameValuePair{
Name: &dashboardPropName,
Value: &storageConnection,
})
}

consumptionSettings := []web.NameValuePair{
{Name: &contentSharePropName, Value: &contentShare},
{Name: &contentFileConnStringPropName, Value: &storageConnection},
Expand Down
102 changes: 102 additions & 0 deletions azurerm/resource_arm_function_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,73 @@ func TestAccAzureRMFunctionApp_updateIdentity(t *testing.T) {
})
}

func TestAccAzureRMFunctionApp_loggingDisabled(t *testing.T) {
resourceName := "azurerm_function_app.test"
ri := acctest.RandInt()
rs := strings.ToLower(acctest.RandString(11))
config := testAccAzureRMFunctionApp_loggingDisabled(ri, rs, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMFunctionAppDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMFunctionAppExists(resourceName),
testCheckAzureRMFunctionAppHasNoContentShare(resourceName),
resource.TestCheckResourceAttr(resourceName, "enable_builtin_logging", "false"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMFunctionApp_updateLogging(t *testing.T) {
resourceName := "azurerm_function_app.test"
ri := acctest.RandInt()
rs := strings.ToLower(acctest.RandString(11))
location := testLocation()

enabledConfig := testAccAzureRMFunctionApp_basic(ri, rs, location)
disabledConfig := testAccAzureRMFunctionApp_loggingDisabled(ri, rs, location)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMFunctionAppDestroy,
Steps: []resource.TestStep{
{
Config: enabledConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "enable_builtin_logging", "true"),
),
},
{
Config: disabledConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMFunctionAppExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "enable_builtin_logging", "false"),
),
},
{
Config: enabledConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "enable_builtin_logging", "true"),
),
},
},
})
}

func testCheckAzureRMFunctionAppDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).appServicesClient

Expand Down Expand Up @@ -1126,3 +1193,38 @@ resource "azurerm_function_app" "test" {
}
`, rInt, location, storage)
}

func testAccAzureRMFunctionApp_loggingDisabled(rInt int, storage string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}
resource "azurerm_storage_account" "test" {
name = "acctestsa%[3]s"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%[1]d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_function_app" "test" {
name = "acctest-%[1]d-func"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
app_service_plan_id = "${azurerm_app_service_plan.test.id}"
storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}"
enable_builtin_logging = false
}`, rInt, location, storage)
}
2 changes: 2 additions & 0 deletions website/docs/r/function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ The following arguments are supported:

* `app_settings` - (Optional) A key-value pair of App Settings.

* `enable_builtin_logging` - (Optional) Should the built-in logging of this Function App be enabled? Defaults to `true`.

* `connection_string` - (Optional) An `connection_string` block as defined below.

* `client_affinity_enabled` - (Optional) Should the Function App send session affinity cookies, which route client requests in the same session to the same instance?
Expand Down

0 comments on commit b7eb318

Please sign in to comment.