Open phillipstr opened 2 years ago
@phillipstr What problems have you encountered with azure_rm_appserviceplan? Can you describe it in detail? Will this help solve the problem? Thank you very much!
kindly ping!
@Fred-sun Sorry for the delay, and thank you for the reply.
It isn't an issue, so much as a nice to have. The azure_rm_appserviceplan module in it's current state doesn't appear to support creating App Service Plans on Azure App Service Environments for private networks.
We have a decent workaround using a combination of Ansible & Terraform, but it would be nice to use azure_rm_appserviceplan to create plans for private environments.
@phillipstr Hi, we are in the same situation. Did you ever find a way to create an Azure App Service Environment using a module? azure_rm_appserviceplan or other?
If not could you share how you are doing it with azure_rm and/or terraform.
Thank you.
Hey @mexicanopelon, I ended up with a workaround using the azapi_resource module, it wasn't ideal but was at least functional. Below is a (very) sanitized version of the code.
That said, the azurerm_app_service_plan module we wanted to do this with has been deprecated and replaced by azurerm_service_plan, which does have an option for providing an App Service Environment ID. I haven't tried the new module out yet, but it very well may be the solution we're looking for.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
}
azapi = {
source = "Azure/azapi"
}
}
}
provider "azurerm" {
subscription_id = ""
tenant_id = ""
features {}
}
provider "azapi" {
subscription_id = ""
tenant_id = ""
}
resource "azurerm_resource_group" "asp_rsg" {
name = "rg-asp-test"
location = "eastus2"
}
data "azurerm_app_service_environment_v3" "ase" {
name = "private_ase"
resource_group_name = "rg-ase-test"
}
resource "azapi_resource" "asp" {
name = "test-asp-on-asev3"
parent_id = azurerm_resource_group.asp_rsg.id
type = "Microsoft.Web/serverFarms@2020-08-01"
location = "eastus2"
body = jsonencode({
sku = {
name = "I1v2"
capacity = "1"
}
properties = {
maximumElasticWorkerCount = 10
hostingEnvironmentProfile = {
id = data.azurerm_app_service_environment_v3.ase.id
}
}
})
}
@mexicanopelon in the spirit of the Issue, here's the Ansible workaround
- name: Create Azure App Service Plan on ASE
azurerm.azcollection.azure_rm_resource:
cloud_environment: AzureCloud
tenant: "{{ tenant_id }}"
subscription_id: "{{ subscription_id }}"
client_id: "{{ client_id }}"
secret: "{{ client_secret }}"
resource_group: "{{ rg }}"
provider: "Web"
resource_type: serverfarms
resource_name: "asp-test"
api_version: "2020-08-01"
body:
location: "eastus2"
sku:
name: "{{ sku }}"
capacity: "{{ workers }}"
properties:
maximumElasticWorkerCount: 10
hostingEnvironmentProfile:
id: "{{ ase_id }}"
@phillipstr Thanks for providing both approaches. We are currently working to configure our Azure environment with Ansible, so I'll give that one a shot first. Thanks you so much for your help. I'll let you know how it goes.
@phillipstr Good morning. I am trying the Ansible script. I am unclear about the hostingEnvironmentProfile.id. Where is this value coming from? I apologize if my question is trivial. I am pretty new to Azure.
Thanks.
@phillipstr
I think we figure what the hostingEnvironmentProfile.id was. We tried running it with something like this:
- name: "Create Azure App Service Plan on ASE"
azure.azcollection.azure_rm_resource:
cloud_environment: AzureCloud
tenant: ########-####-####-####-##########
subscription_id: ########-####-####-####-##########
client_id: ########-####-####-####-##########
secret: ########-####-####-####-##########
resource_group: rg-dev
provider: "Web"
resource_type: serverfarms
resource_name: "asp-test"
api_version: "2020-08-01"
body:
location: southcentralus
sku:
name: I3
capacity: 1
properties:
maximumElasticWorkerCount: 1
hostingEnvironmentProfile:
id: "/subscriptions/########-####-####-####-##########/resourceGroups/rg-dev/providers/Microsoft.Web/hostingEnvironments/ase-dev"
We get the following error:
File \"/tmp/ansible_azure.azcollection.azure_rm_resource_payload_bkwptqao/ansible_azure.azcollection.azure_rm_resource_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common_rest.py\", line 87, in query
msrestazure.azure_exceptions.CloudError: 404 Client Error: Not Found for url: https://management.azure.com/subscriptions/########-####-####-####-##########/resourceGroups/rg-dev/providers/Microsoft.Web/serverfarms/asp-test?api-version=2022-03-01"
Any thoughts?
hostingEnvironmentProfile: id: "/subscriptions/########-####-####-####-##########/resourceGroups/rg-dev/providers/Microsoft.Web/hostingEnvironments/ase-dev"
To start with you're missing an indent on the id
line, it is an attribute of hostingEnvironmentProfile.
SUMMARY
Add support to the azure_rm_appserviceplan module to specify a hosting environment (ASE).
ISSUE TYPE
COMPONENT NAME
azure_rm_appserviceplan
ADDITIONAL INFORMATION
To create an App Service Plan on an App Service Environment with Ansible you cannot use the azure_rm_appserviceplan module. We are currently using the generic azure_rm_resource module to deploy an App Service Plan and providing it the hostingEnvironmentProfile property to set the App Service Environment.
It would be ideal to be able to specify the ASE ID as an optional variable or in a property value in the azure_rm_appserviceplan module.