Skip to content

Commit

Permalink
Add fields for App Service and App Service Slot (#9162)
Browse files Browse the repository at this point in the history
Co-authored-by: jackofallops <[email protected]>
  • Loading branch information
daxsorbito and jackofallops authored Jan 7, 2021
1 parent d5705fe commit 528dba7
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 0 deletions.
29 changes: 29 additions & 0 deletions azurerm/internal/services/web/app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,16 @@ func schemaAppServiceLogsConfig() *schema.Schema {
},
},
},
"detailed_error_messages_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"failed_request_tracing_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
}
Expand Down Expand Up @@ -1336,6 +1346,13 @@ func flattenAppServiceLogs(input *web.SiteLogsConfigProperties) []interface{} {
}
result["http_logs"] = httpLogs

if input.DetailedErrorMessages != nil && input.DetailedErrorMessages.Enabled != nil {
result["detailed_error_messages_enabled"] = *input.DetailedErrorMessages.Enabled
}
if input.FailedRequestsTracing != nil && input.FailedRequestsTracing.Enabled != nil {
result["failed_request_tracing_enabled"] = *input.FailedRequestsTracing.Enabled
}

return append(results, result)
}

Expand Down Expand Up @@ -1417,6 +1434,18 @@ func expandAppServiceLogs(input interface{}) web.SiteLogsConfigProperties {
}
}

if v, ok := config["detailed_error_messages_enabled"]; ok {
logs.DetailedErrorMessages = &web.EnabledConfig{
Enabled: utils.Bool(v.(bool)),
}
}

if v, ok := config["failed_request_tracing_enabled"]; ok {
logs.FailedRequestsTracing = &web.EnabledConfig{
Enabled: utils.Bool(v.(bool)),
}
}

return logs
}

Expand Down
116 changes: 116 additions & 0 deletions azurerm/internal/services/web/app_service_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,52 @@ func TestAccAppService_managedPipelineMode(t *testing.T) {
})
}

func TestAccAppService_detailedErrorMessagesLogs(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service", "test")
r := AppServiceResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.detailedErrorMessages(data, true),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("logs.0.detailed_error_messages_enabled").HasValue("true"),
),
},
{
Config: r.detailedErrorMessages(data, false),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
resource.TestCheckResourceAttr(data.ResourceName, "logs.0.detailed_error_messages_enabled", "false"),
),
},
data.ImportStep(),
})
}

func TestAccAzureRMAppService_failedRequestTracingLogs(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service", "test")
r := AppServiceResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.failedRequestTracing(data, true),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("logs.0.failed_request_tracing_enabled").HasValue("true"),
),
},
{
Config: r.failedRequestTracing(data, false),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("logs.0.failed_request_tracing_enabled").HasValue("false"),
),
},
data.ImportStep(),
})
}

func TestAccAppService_tagsUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service", "test")
r := AppServiceResource{}
Expand Down Expand Up @@ -3482,6 +3528,76 @@ resource "azurerm_app_service" "test" {
`, template, data.RandomInteger)
}

func (r AppServiceResource) detailedErrorMessages(data acceptance.TestData, detailedErrorEnabled bool) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
app_service_plan_id = azurerm_app_service_plan.test.id
logs {
detailed_error_messages_enabled = %t
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, detailedErrorEnabled)
}

func (r AppServiceResource) failedRequestTracing(data acceptance.TestData, failedRequestEnabled bool) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
app_service_plan_id = azurerm_app_service_plan.test.id
logs {
failed_request_tracing_enabled = %t
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, failedRequestEnabled)
}

func (r AppServiceResource) managedPipelineMode(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
129 changes: 129 additions & 0 deletions azurerm/internal/services/web/app_service_slot_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,49 @@ func TestAccAppServiceSlot_httpBlobStorageLogs(t *testing.T) {
})
}

func TestAccAppServiceSlot_detailedErrorMessagesLogs(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test")
r := AppServiceSlotResource{}
data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.detailedErrorMessages(data, true),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.detailedErrorMessages(data, false),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccAppServiceSlot_failedRequestTracingLogs(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test")
r := AppServiceSlotResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.failedRequestTracing(data, true),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.failedRequestTracing(data, false),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccAppServiceSlot_autoSwap(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test")
r := AppServiceSlotResource{}
Expand Down Expand Up @@ -3496,6 +3539,92 @@ resource "azurerm_app_service_slot" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (r AppServiceSlotResource) detailedErrorMessages(data acceptance.TestData, detailedErrorEnabled bool) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
app_service_plan_id = azurerm_app_service_plan.test.id
}
resource "azurerm_app_service_slot" "test" {
name = "acctestASSlot-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
app_service_plan_id = azurerm_app_service_plan.test.id
app_service_name = azurerm_app_service.test.name
logs {
detailed_error_messages_enabled = %t
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, detailedErrorEnabled)
}

func (r AppServiceSlotResource) failedRequestTracing(data acceptance.TestData, failedRequestEnabled bool) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_app_service_plan" "test" {
name = "acctestASP-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "test" {
name = "acctestAS-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
app_service_plan_id = azurerm_app_service_plan.test.id
}
resource "azurerm_app_service_slot" "test" {
name = "acctestASSlot-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
app_service_plan_id = azurerm_app_service_plan.test.id
app_service_name = azurerm_app_service.test.name
logs {
failed_request_tracing_enabled = %t
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, failedRequestEnabled)
}

func (r AppServiceSlotResource) autoSwap(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/app_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ A `logs` block supports the following:

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

* `detailed_error_messages_enabled` - (Optional) Should `Detailed error messages` be enabled on this App Service? Defaults to `false`.

* `failed_request_tracing_enabled` - (Optional) Should `Failed request tracing` be enabled on this App Service? Defaults to `false`.

---

An `application_logs` block supports the following:
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/app_service_slot.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ The following arguments are supported:

* `site_config` - (Optional) A `site_config` object as defined below.

* `logs` - (Optional) A `logs` block as defined below.

* `identity` - (Optional) A Managed Service Identity block as defined below.

* `tags` - (Optional) A mapping of tags to assign to the resource.
Expand Down Expand Up @@ -350,6 +352,10 @@ A `logs` block supports the following:

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

* `detailed_error_messages_enabled` - (Optional) Should `Detailed error messages` be enabled on this App Service slot? Defaults to `false`.

* `failed_request_tracing_enabled` - (Optional) Should `Failed request tracing` be enabled on this App Service slot? Defaults to `false`.

---

An `application_logs` block supports the following:
Expand Down

0 comments on commit 528dba7

Please sign in to comment.