azurermAppService
Manages an App Service (within an App Service Plan).
!> NOTE: This resource has been deprecated in version 3.0 of the AzureRM provider and will be removed in version 4.0. Please use azurermLinuxWebApp and azurermWindowsWebApp resources instead.
-> Note: When using Slots - the appSettings, connectionString and siteConfig blocks on the azurermAppService resource will be overwritten when promoting a Slot using the azurermAppServiceActiveSlot resource.
Example Usage
This example provisions a Windows App Service. Other examples of the azurermAppService resource can be found in the /examples/appService directory within the GitHub Repository
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
this,
"example",
{
location: "West Europe",
name: "example-resources",
}
);
const azurermAppServicePlanExample = new azurerm.appServicePlan.AppServicePlan(
this,
"example_1",
{
location: azurermResourceGroupExample.location,
name: "example-appserviceplan",
resource_group_name: azurermResourceGroupExample.name,
sku: [
{
size: "S1",
tier: "Standard",
},
],
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermAppServicePlanExample.overrideLogicalId("example");
const azurermAppServiceExample = new azurerm.appService.AppService(
this,
"example_2",
{
app_service_plan_id: azurermAppServicePlanExample.id,
app_settings: [
{
SOME_KEY: "some-value",
},
],
connection_string: [
{
name: "Database",
type: "SQLServer",
value: "Server=some-server.mydomain.com;Integrated Security=SSPI",
},
],
location: azurermResourceGroupExample.location,
name: "example-app-service",
resource_group_name: azurermResourceGroupExample.name,
site_config: [
{
dotnet_framework_version: "v4.0",
scm_type: "LocalGit",
},
],
}
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermAppServiceExample.overrideLogicalId("example");
Argument Reference
The following arguments are supported:
-
name- (Required) Specifies the name of the App Service. Changing this forces a new resource to be created. -
resourceGroupName- (Required) The name of the resource group in which to create the App Service. Changing this forces a new resource to be created. -
location- (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -
appServicePlanId- (Required) The ID of the App Service Plan within which to create this App Service. -
appSettings- (Optional) A key-value pair of App Settings. -
authSettings- (Optional) AauthSettingsblock as defined below. -
backup- (Optional) Abackupblock as defined below. -
connectionString- (Optional) One or moreconnectionStringblocks as defined below. -
clientAffinityEnabled- (Optional) Should the App Service send session affinity cookies, which route client requests in the same session to the same instance? -
clientCertEnabled- (Optional) Does the App Service require client certificates for incoming requests? Defaults tofalse. -
clientCertMode- (Optional) Mode of client certificates for this App Service. Possible values arerequired,optionalandoptionalInteractiveUser. If this parameter is set,clientCertEnabledmust be set totrue, otherwise this parameter is ignored. -
enabled- (Optional) Is the App Service Enabled? Defaults totrue. -
identity- (Optional) Anidentityblock as defined below. -
httpsOnly- (Optional) Can the App Service only be accessed via HTTPS? Defaults tofalse. -
keyVaultReferenceIdentityId- (Optional) The User Assigned Identity Id used for looking up KeyVault secrets. The identity must be assigned to the application. For more information see - Access vaults with a user-assigned identity -
logs- (Optional) Alogsblock as defined below. -
storageAccount- (Optional) One or morestorageAccountblocks as defined below. -
siteConfig- (Optional) AsiteConfigblock as defined below. -
sourceControl- (Optional) A Source Control block as defined below -
tags- (Optional) A mapping of tags to assign to the resource.
A storageAccount block supports the following:
-
name- (Required) The name of the storage account identifier. -
type- (Required) The type of storage. Possible values areazureBlobandazureFiles. -
accountName- (Required) The name of the storage account. -
shareName- (Required) The name of the file share (container name, for Blob storage). -
accessKey- (Required) The access key for the storage account. -
mountPath- (Optional) The path to mount the storage within the site's runtime environment.
A connectionString block supports the following:
-
name- (Required) The name of the Connection String. -
type- (Required) The type of the Connection String. Possible values areapiHub,custom,docDb,eventHub,mySql,notificationHub,postgreSql,redisCache,serviceBus,sqlAzureandsqlServer. -
value- (Required) The value for the Connection String.
A identity block supports the following:
type- (Required) Specifies the identity type of the App Service. Possible values aresystemAssigned(where Azure will generate a Service Principal for you),userAssignedwhere you can specify the Service Principal IDs in theidentityIdsfield, andsystemAssigned,UserAssignedwhich assigns both a system managed identity as well as the specified user assigned identities.
\~> NOTE: When type is set to systemAssigned, The assigned principalId and tenantId can be retrieved after the App Service has been created. More details are available below.
identityIds- (Optional) Specifies a list of user managed identity ids to be assigned. Required iftypeisuserAssigned.
A logs block supports the following:
-
applicationLogs- (Optional) AnapplicationLogsblock as defined below. -
httpLogs- (Optional) AnhttpLogsblock as defined below. -
detailedErrorMessagesEnabled- (Optional) ShoulddetailedErrorMessagesbe enabled on this App Service? Defaults tofalse. -
failedRequestTracingEnabled- (Optional) ShouldfailedRequestTracingbe enabled on this App Service? Defaults tofalse.
An applicationLogs block supports the following:
-
azureBlobStorage- (Optional) AnazureBlobStorageblock as defined below. -
fileSystemLevel- (Optional) Log level for filesystem based logging. Supported values areerror,information,verbose,warningandoff. Defaults tooff.
An httpLogs block supports one of the following:
-
fileSystem- (Optional) AfileSystemblock as defined below. -
azureBlobStorage- (Optional) AnazureBlobStorageblock as defined below.
An azureBlobStorage block supports the following:
-
level- (Required) The level at which to log. Possible values includeerror,warning,information,verboseandoff. NOTE: this field is not available forhttpLogs -
sasUrl- (Required) The URL to the storage container with a shared access signature token appended. -
retentionInDays- (Required) The number of days to retain logs for.
A fileSystem block supports the following:
-
retentionInDays- (Required) The number of days to retain logs for. -
retentionInMb- (Required) The maximum size in megabytes that HTTP log files can use before being removed.
A siteConfig block supports the following:
-
acrUseManagedIdentityCredentials- (Optional) Are Managed Identity Credentials used for Azure Container Registry pull -
acrUserManagedIdentityClientId- (Optional) If using User Managed Identity, the User Managed Identity Client Id
\~> NOTE: When using User Managed Identity with Azure Container Registry the Identity will need to have the ACRPull role assigned
alwaysOn- (Optional) Should the app be loaded at all times? Defaults tofalse.
\~> NOTE: when using an App Service Plan in the free or shared Tiers alwaysOn must be set to false.
-
appCommandLine- (Optional) App command line to launch, e.g./sbin/myserverB0000. -
autoSwapSlotName- (Optional) The name of the slot to automatically swap to during deployment -
cors- (Optional) Acorsblock as defined below. -
defaultDocuments- (Optional) The ordering of default documents to load, if an address isn't specified. -
dotnetFrameworkVersion- (Optional) The version of the .NET framework's CLR used in this App Service. Possible values arev20(which will use the latest version of the .NET framework for the .NET CLR v2 - currentlynet35),v40(which corresponds to the latest version of the .NET CLR v4 - which at the time of writing isnet471),v50andv60. For more information on which .NET CLR version to use based on the .NET framework you're targeting - please see this table. Defaults tov40. -
ftpsState- (Optional) State of FTP / FTPS service for this App Service. Possible values include:allAllowed,ftpsOnlyanddisabled. -
healthCheckPath- (Optional) The health check path to be pinged by App Service. For more information - please see App Service health check announcement. -
numberOfWorkers- (Optional) The scaled number of workers (for per site scaling) of this App Service. Requires thatperSiteScalingis enabled on theazurermAppServicePlan. For more information - please see Microsoft documentation on high-density hosting. -
http2Enabled- (Optional) Is HTTP2 Enabled on this App Service? Defaults tofalse. -
ipRestriction- (Optional) A List of objects representing IP restrictions as defined below.
-> NOTE User has to explicitly set ipRestriction to empty slice ([]) to remove it.
scmUseMainIpRestriction- (Optional) IP security restrictions for scm to use main. Defaults tofalse.
-> NOTE Any scmIpRestriction blocks configured are ignored by the service when scmUseMainIpRestriction is set to true. Any scm restrictions will become active if this is subsequently set to false or removed.
scmIpRestriction- (Optional) A List of objects representing IP restrictions as defined below.
-> NOTE User has to explicitly set scmIpRestriction to empty slice ([]) to remove it.
-
javaVersion- (Optional) The version of Java to use. If specifiedjavaContainerandjavaContainerVersionmust also be specified. Possible values are17,18and11and their specific versions - except for Java 11 (e.g.17080,180181,11) -
javaContainer- (Optional) The Java Container to use. If specifiedjavaVersionandjavaContainerVersionmust also be specified. Possible values arejava,jetty, andtomcat. -
javaContainerVersion- (Optional) The version of the Java Container to use. If specifiedjavaVersionandjavaContainermust also be specified. -
localMysqlEnabled- (Optional) Is "MySQL In App" Enabled? This runs a local MySQL instance with your app and shares resources from the App Service plan.
\~> NOTE: MySQL In App is not intended for production environments and will not scale beyond a single instance. Instead you may wish to use Azure Database for MySQL.
linuxFxVersion- (Optional) Linux App Framework and version for the App Service. Possible options are a Docker container (docker|<user/image:tag>), a base-64 encoded Docker Compose file (compose|${filebase64("composeYml")}) or a base-64 encoded Kubernetes Manifest (kube|${filebase64("kubernetesYml")}).
\~> NOTE: To set this property the App Service Plan to which the App belongs must be configured with kind = "linux", and reserved =True or the API will reject any value supplied.
windowsFxVersion- (Optional) The Windows Docker container image (docker|<user/image:tag>)
Additional examples of how to run Containers via the azurermAppService resource can be found in the /examples/appService directory within the GitHub Repository.
-
managedPipelineMode- (Optional) The Managed Pipeline Mode. Possible values areintegratedandclassic. Defaults tointegrated. -
minTlsVersion- (Optional) The minimum supported TLS version for the app service. Possible values are10,11, and12. Defaults to12for new app services. -
phpVersion- (Optional) The version of PHP to use in this App Service. Possible values are55,56,70,71,72,73and74. -
pythonVersion- (Optional) The version of Python to use in this App Service. Possible values are27and34. -
remoteDebuggingEnabled- (Optional) Is Remote Debugging Enabled? Defaults tofalse. -
remoteDebuggingVersion- (Optional) Which version of Visual Studio should the Remote Debugger be compatible with? Possible values arevs2017andvs2019. -
scmType- (Optional) The type of Source Control enabled for this App Service. Defaults tonone. Possible values are:bitbucketGit,bitbucketHg,codePlexGit,codePlexHg,dropbox,externalGit,externalHg,gitHub,localGit,none,oneDrive,tfs,vso, andvstsrm -
use32BitWorkerProcess- (Optional) Should the App Service run in 32 bit mode, rather than 64 bit mode?
\~> NOTE: when using an App Service Plan in the free or shared Tiers use32BitWorkerProcess must be set to true.
vnetRouteAllEnabled- (Optional) Should all outbound traffic to have Virtual Network Security Groups and User Defined Routes applied? Defaults tofalse.
\~> NOTE: This setting supersedes the previous mechanism of setting the appSettings value of websiteVnetRouteAll. However, to prevent older configurations breaking Terraform will update this value if it not explicitly set to the value in appSettingsWebsiteVnetRouteAll.
websocketsEnabled- (Optional) Should WebSockets be enabled?
A cors block supports the following:
-
allowedOrigins- (Required) A list of origins which should be able to make cross-origin calls.*can be used to allow all calls. -
supportCredentials- (Optional) Are credentials supported?
A authSettings block supports the following:
-
enabled- (Required) Is Authentication enabled? -
activeDirectory- (Optional) AactiveDirectoryblock as defined below. -
additionalLoginParams- (Optional) Login parameters to send to the OpenID Connect authorization endpoint when a user logs in. Each parameter must be in the form "key=value". -
allowedExternalRedirectUrls- (Optional) External URLs that can be redirected to as part of logging in or logging out of the app. -
defaultProvider- (Optional) The default provider to use when multiple providers have been set up. Possible values areazureActiveDirectory,facebook,google,microsoftAccountandtwitter.
\~> NOTE: When using multiple providers, the default provider must be set for settings like unauthenticatedClientAction to work.
-
facebook- (Optional) Afacebookblock as defined below. -
google- (Optional) Agoogleblock as defined below. -
issuer- (Optional) Issuer URI. When using Azure Active Directory, this value is the URI of the directory tenant, e.g. https://sts.windows.net/{tenant-guid}/. -
microsoft- (Optional) Amicrosoftblock as defined below. -
runtimeVersion- (Optional) The runtime version of the Authentication/Authorization module. -
tokenRefreshExtensionHours- (Optional) The number of hours after session token expiration that a session token can be used to call the token refresh API. Defaults to72. -
tokenStoreEnabled- (Optional) If enabled the module will durably store platform-specific security tokens that are obtained during login flows. Defaults tofalse. -
twitter- (Optional) Atwitterblock as defined below. -
unauthenticatedClientAction- (Optional) The action to take when an unauthenticated client attempts to access the app. Possible values areallowAnonymousandredirectToLoginPage.
A activeDirectory block supports the following:
-
clientId- (Required) The Client ID of this relying party application. Enables OpenIDConnection authentication with Azure Active Directory. -
clientSecret- (Optional) The Client Secret of this relying party application. If no secret is provided, implicit flow will be used. -
allowedAudiences- (Optional) Allowed audience values to consider when validating JWTs issued by Azure Active Directory.
A facebook block supports the following:
-
appId- (Required) The App ID of the Facebook app used for login -
appSecret- (Required) The App Secret of the Facebook app used for Facebook login. -
oauthScopes- (Optional) The OAuth 2.0 scopes that will be requested as part of Facebook login authentication. https://developers.facebook.com/docs/facebook-login
A google block supports the following:
-
clientId- (Required) The OpenID Connect Client ID for the Google web application. -
clientSecret- (Required) The client secret associated with the Google web application. -
oauthScopes- (Optional) The OAuth 2.0 scopes that will be requested as part of Google Sign-In authentication. https://developers.google.com/identity/sign-in/web/
A twitter block supports the following:
-
consumerKey- (Required) The consumer key of the Twitter app used for login -
consumerSecret- (Required) The consumer secret of the Twitter app used for login.
A ipRestriction block supports the following:
-
ipAddress- (Optional) The IP Address used for this IP Restriction in CIDR notation. -
serviceTag- (Optional) The Service Tag used for this IP Restriction. -
virtualNetworkSubnetId- (Optional) The Virtual Network Subnet ID used for this IP Restriction.
-> NOTE: One of either ipAddress, serviceTag or virtualNetworkSubnetId must be specified
-
name- (Optional) The name for this IP Restriction. -
priority- (Optional) The priority for this IP Restriction. Restrictions are enforced in priority order. By default, priority is set to 65000 if not specified. -
action- (Optional) Does this restrictionallowordenyaccess for this IP range. Defaults toallow. -
headers- (Optional) The headers for this specificipRestrictionas defined below.
A scmIpRestriction block supports the following:
-
ipAddress- (Optional) The IP Address used for this IP Restriction in CIDR notation. -
serviceTag- (Optional) The Service Tag used for this IP Restriction. -
virtualNetworkSubnetId- (Optional) The Virtual Network Subnet ID used for this IP Restriction.
-> NOTE: One of either ipAddress, serviceTag or virtualNetworkSubnetId must be specified
-
name- (Optional) The name for this IP Restriction. -
priority- (Optional) The priority for this IP Restriction. Restrictions are enforced in priority order. By default, priority is set to 65000 if not specified. -
action- (Optional) Allow or Deny access for this IP range. Defaults toallow. -
headers- (Optional) The headers for this specificscmIpRestrictionas defined below.
A headers block supports the following:
-
xAzureFdid- (Optional) A list of allowed Azure FrontDoor IDs in UUID notation with a maximum of 8. -
xFdHealthProbe- (Optional) A list to allow the Azure FrontDoor health probe header. Only allowed value is "1". -
xForwardedFor- (Optional) A list of allowed 'X-Forwarded-For' IPs in CIDR notation with a maximum of 8 -
xForwardedHost- (Optional) A list of allowed 'X-Forwarded-Host' domains with a maximum of 8.
A microsoft block supports the following:
-
clientId- (Required) The OAuth 2.0 client ID that was created for the app used for authentication. -
clientSecret- (Required) The OAuth 2.0 client secret that was created for the app used for authentication. -
oauthScopes- (Optional) The OAuth 2.0 scopes that will be requested as part of Microsoft Account authentication. https://msdn.microsoft.com/en-us/library/dn631845.aspx
A backup block supports the following:
-
name- (Required) Specifies the name for this Backup. -
enabled- (Optional) Is this Backup enabled? Defaults totrue. -
storageAccountUrl- (Required) The SAS URL to a Storage Container where Backups should be saved. -
schedule- (Required) Ascheduleblock as defined below.
A schedule block supports the following:
-
frequencyInterval- (Required) Sets how often the backup should be executed. -
frequencyUnit- (Required) Sets the unit of time for how often the backup should be executed. Possible values aredayorhour. -
keepAtLeastOneBackup- (Optional) Should at least one backup always be kept in the Storage Account by the Retention Policy, regardless of how old it is? -
retentionPeriodInDays- (Optional) Specifies the number of days after which Backups should be deleted. Defaults to30. -
startTime- (Optional) Sets when the schedule should start working.
A sourceControl block supports the following:
-
repoUrl- (Optional) The URL of the source code repository. -
branch- (Optional) The branch of the remote repository to use. Defaults to 'master'. -
manualIntegration- (Optional) Limits to manual integration. Defaults tofalseif not specified. -
rollbackEnabled- (Optional) Enable roll-back for the repository. Defaults tofalseif not specified. -
useMercurial- (Optional) Use Mercurial iftrue, otherwise uses Git.
Attributes Reference
The following attributes are exported:
-
id- The ID of the App Service. -
customDomainVerificationId- An identifier used by App Service to perform domain ownership verification via DNS TXT record. -
defaultSiteHostname- The Default Hostname associated with the App Service - such asmysiteAzurewebsitesNet -
outboundIpAddresses- A comma separated list of outbound IP addresses - such as5223253,521434312 -
outboundIpAddressList- A list of outbound IP addresses - such as["5223253", "521434312"] -
possibleOutboundIpAddresses- A comma separated list of outbound IP addresses - such as5223253,521434312,521434317- not all of which are necessarily in use. Superset ofoutboundIpAddresses. -
possibleOutboundIpAddressList- A list of outbound IP addresses - such as["5223253", "521434312", "521434317"]- not all of which are necessarily in use. Superset ofoutboundIpAddressList. -
sourceControl- AsourceControlblock as defined below, which contains the Source Control information whenscmTypeis set tolocalGit. -
siteCredential- AsiteCredentialblock as defined below, which contains the site-level credentials used to publish to this App Service. -
identity- Anidentityblock as defined below, which contains the Managed Service Identity information for this App Service.
A identity block exports the following:
-
principalId- The Principal ID for the Service Principal associated with the Managed Service Identity of this App Service. -
tenantId- The Tenant ID for the Service Principal associated with the Managed Service Identity of this App Service.
-> You can access the Principal ID via azurermAppServiceExampleIdentity0PrincipalId and the Tenant ID via azurermAppServiceExampleIdentity0TenantId
A siteCredential block exports the following:
-
username- The username which can be used to publish to this App Service -
password- The password associated with the username, which can be used to publish to this App Service.
\~> NOTE: both username and password for the siteCredential block are only exported when scmType is set to localGit
A sourceControl block exports the following:
repoUrl- URL of the Git repository for this App Service.branch- Branch name of the Git repository for this App Service.
Timeouts
The timeouts block allows you to specify timeouts for certain actions:
create- (Defaults to 30 minutes) Used when creating the App Service.update- (Defaults to 30 minutes) Used when updating the App Service.read- (Defaults to 5 minutes) Used when retrieving the App Service.delete- (Defaults to 30 minutes) Used when deleting the App Service.
Import
App Services can be imported using the resourceId, e.g.