Refactor Terraform
Replace your Terraform resources with a module¶
For reference, you can find the module itself in TFE here. Note: in the module documentation is a link to the module source code. In the case that the docs are not fully up to date, the code is the source of truth for any fixes you may need to make.
The first thing to note on the page above are the Provision Instructions which will give you a skeleton of the module definition that you need.
Edit your main.tf
file to utilize Cloud Platform's Azure App Service Module. You can look at the Cloud Platform module README for examples, and utilize the Inputs section to determine what is required and what isn't.
In the summary of the module, Cloud Platform states that this module creates both an App Service Plan and an App Service. We will replace our two resource definitions with one module.
Add the required inputs as variables¶
After you have finished implementing the module in the main.tf
, you must now update your variables.tf
with the new variables used in the Cloud Platform app-service-Cloud Platform module. You will need all of your variables from before, plus any new required variables introduced by utilizing the new module.
Cloud Platform's documentation outlines the required variables that we need to define for the app service module. Notice the complex appservices
map. This large data object has multiple inputs which allow for you to configure the app service to your needs.
Discussion: Do I need to use all the variables listed in TFE? What do the four tag variables do and where do they get their values?
There are no changes to the versions.tf
file so we can leave it as is.
Did you give up trying to copy and format your
appservices
variable declaration?
Hint: App Service map
variable "appservices" {
type = map(object({ connectionstrings = list(object({
connstrname = string
connstrtype = string
connstrvalue = string
}))
appsettings = object({})
sitesettings = object({
dotnet_framework_version = string
min_tls_version = string
always_on = bool
ftps_state = string
http2_enabled = bool
managed_pipeline_mode = string
remote_debugging_enabled = bool
remote_debugging_version = string
scm_type = string
scm_use_main_ip_restriction = bool
websockets_enabled = bool
default_documents = list(string)
})
generalsettings = object({
client_affinity_enabled = bool
})
managed_identity = object({
type = string
id = list(string)
})
}))
description = "The Azure location where all resources should be created"
}
variable "app_service_size" {
description = "The Azure App Service Size"
type = string
}
variable "app_service_tier" {
description = "The Azure App Service Tier"
type = string
}