Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add health_check_path to site_config #6661

Merged
merged 4 commits into from May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions azurerm/helpers/azure/app_service.go
Expand Up @@ -450,6 +450,11 @@ func SchemaAppServiceSiteConfig() *schema.Schema {
}, false),
},

"health_check_path": {
Type: schema.TypeString,
Optional: true,
},

"linux_fx_version": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -749,6 +754,11 @@ func SchemaAppServiceDataSourceSiteConfig() *schema.Schema {
Computed: true,
},

"health_check_path": {
Type: schema.TypeString,
Computed: true,
},

"linux_fx_version": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -1486,6 +1496,10 @@ func ExpandAppServiceSiteConfig(input interface{}) (*web.SiteConfig, error) {
siteConfig.FtpsState = web.FtpsState(v.(string))
}

if v, ok := config["health_check_path"]; ok {
siteConfig.HealthCheckPath = utils.String(v.(string))
}

if v, ok := config["min_tls_version"]; ok {
siteConfig.MinTLSVersion = web.SupportedTLSVersions(v.(string))
}
Expand Down Expand Up @@ -1606,6 +1620,11 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} {

result["scm_type"] = string(input.ScmType)
result["ftps_state"] = string(input.FtpsState)

if input.HealthCheckPath != nil {
result["health_check_path"] = *input.HealthCheckPath
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general we need to set a value for every key inside a dictionary, which helps us catch when Azure doesn't return a value from the API (otherwise Terraform Core will show a diff between "null" and "empty") e.g.

Suggested change
}
healthCheckPath := ""
if input.HealthCheckPath != nil {
healthCheckPath = *input.HealthCheckPath
}
result["health_check_path"] = healthCheckPath

however since the rest of this class doesn't, we can ignore this for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API explicitly supports null as the value for this field, so I assumed that was what not setting the field would represent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I can change the above to explicitly set result["health_check_path"] = nil when input.HealthCheckPath == nil if that is supported.


result["min_tls_version"] = string(input.MinTLSVersion)

result["cors"] = FlattenWebCorsSettings(input.Cors)
Expand Down
Expand Up @@ -1201,6 +1201,25 @@ func TestAccAzureRMAppService_ftpsState(t *testing.T) {
})
}

func TestAccAzureRMAppService_healthCheckPath(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service", "test")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMAppServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMAppService_healthCheckPath(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.health_check_path", "/health"),
),
},
data.ImportStep(),
},
})
}

// todo - linuxFxVersion seems to reject all supplied values - needs more detailed investigation.
// error message simply reads: Original Error: Code="BadRequest" Message="The parameter LinuxFxVersion has an invalid value."
func TestAccAzureRMAppService_linuxFxVersion(t *testing.T) {
Expand Down Expand Up @@ -3391,6 +3410,41 @@ resource "azurerm_app_service" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMAppService_healthCheckPath(data acceptance.TestData) 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

site_config {
health_check_path = "/health"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMAppService_linuxFxVersion(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/app_service.html.markdown
Expand Up @@ -103,6 +103,8 @@ A `ip_restriction` block exports the following:

* `ftps_state` - State of FTP / FTPS service for this AppService.

* `health_check_path` - The health check path to be pinged by App Service.

* `ip_restriction` - One or more `ip_restriction` blocks as defined above.

* `java_version` - The version of Java in use.
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/app_service.html.markdown
Expand Up @@ -187,6 +187,10 @@ A `site_config` block supports the following:

* `ftps_state` - (Optional) State of FTP / FTPS service for this App Service. Possible values include: `AllAllowed`, `FtpsOnly` and `Disabled`.

* `health_check_path` - (Optional) The health check path to be pinged by App Service. [For more information - please see the corresponding Kudu Wiki page](https://github.com/projectkudu/kudu/wiki/Health-Check-(Preview)).
sirlatrom marked this conversation as resolved.
Show resolved Hide resolved

~> **Note:** This functionality is in Preview and is subject to changes (including breaking changes) on Azure's end

* `http2_enabled` - (Optional) Is HTTP2 Enabled on this App Service? Defaults to `false`.

* `ip_restriction` - (Optional) A [List of objects](/docs/configuration/attr-as-blocks.html) representing ip restrictions as defined below.
Expand Down