Project: Chef InSpec (Provisioning / Security & Compliance)
File: azurerm_webapp.md

+++ title = "azurerm_webapp resource" draft = false gh_repo = "inspec" platform = "azure" [menu] [menu.inspec] title = "azurerm_webapp" identifier = "inspec/resources/azure/azurermwebapp.md azurermwebapp resource" parent = "inspec/resources/azure" +++ {{< inspec/azurermdeprecated resource="azurewebapp" >}} Use the `azurerm_webapp` InSpec audit resource to test properties of an Azure Webapp. This resource interacts with version `2016-08-01` of the Azure Management API. For more information see the . At the moment, there doesn't appear to be a way to select the version of the Azure API docs. If you notice a newer version being referenced in the official documentation please open an issue or submit a pull request using the updated version. This resource is available in the `inspec-azure` [resource pack](/inspec/glossary/#resource-pack). To use it, add the following to your `inspec.yml` in your top-level profile: depends: inspec-azure: git: https://github.com/inspec/inspec-azure.git You'll also need to setup your Azure credentials; see the resource pack . An `azurerm_webapp` resource block identifies an AppService Webapp by name and Resource Group. describe azurermappservicewebapp(resource_group: 'example', name: 'webapp name') do ... end Test that an example Resource Group has the specified Webapp and verify it's authentication settings are enabled. Verify HTTP 2.0 is enabled. describe azurermwebapp(resourcegroup: 'example', name: 'webapp_name') do it { should exist } its('authsettings.properties') { should haveattributes(enabled: false) } its('configuration.properties') { should have_attributes(http20Enabled: true) } end describe azurermwebapp(resourcegroup: resourcegroup, name: waname) do it { should beusinglatest('aspnet') } end describe azurermwebapp(resourcegroup: resourcegroup, name: waname) do it { should beusinglatest('python') } end `name` `resource_group` The Resource Group as well as the Webapp name. describe azurermwebapp(resourcegroup: 'example', name: 'webapp_name') do it { should exist } end describe azurermwebapp(resourcegroup: 'example', name: 'webappname').authsettings do its('properties') { should have_attributes(enabled: true) } end `id` `name` `location` `properties` `identity` `auth_settings` `configuration` All of the attributes are available via dot notation. This is an example of the currently available attributes. ```ruby control 'azurerm_webapp' do describe azurermwebapp(resourcegroup: 'example', name: 'webapp_name') do it { should exist } its('properties.enabled') { should cmp true } its('properties.clientCertEnabled') { should cmp true } its('properties.enabledHostNames') { should cmp 'webapp_name.azurewebsites.net' } its('properties.httpsOnly') { should cmp true } end end ``` There are additional attributes that may be accessed that we have not documented. Please take a look at the . Any attribute in the response may be accessed with the key names separated by dots (`.`). The API may not always return keys that do not have any associated data. There may be cases where the deeply nested property may not have the desired attribute along your call chain. If you find yourself writing tests against properties that may be nil, fork this resource pack and add an accessor to the resource. Within that accessor you'll be able to guard against nil keys. Pull requests are always welcome. {{< readfile file="content/inspec/reusable/md/inspecmatcherslink.md" >}} This resource has the following special matchers. Asserts whether the deployed Azure WebApp is using the latest supported version of the given language/stack. Supported stacks (i.e. python, java, php, node) can be found in the `properties` section of WebApp Configuration . ```ruby it { should beusinglatest('php') } it { should beusinglatest('java') } it { should beusinglatest('python') } it { should beusinglatest('aspnet') } it { should beusinglatest('dotnetcore') } ``` The control will pass if the resource returns a result. Use `should_not` if you expect zero matches. describe azurermwebapp(resourcegroup: 'example', name: 'webapp_name') do it { should have_identity } end Your [Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) must be setup with a `contributor` role on the subscription you wish to test.