data "azurerm_container_app_environment" "containerappenv_data" {
name = "development"
resource_group_name = data.azurerm_resource_group.rg_data.name
}
output "container_app_environment_name" {
value = data.azurerm_container_app_environment.containerappenv_data
}
Terraform Plan returns with following error
Planning failed. Terraform encountered an error while generating this plan,
╷
│ Error: retrieving Log Analytics Workspace: no matching workspace found
│
│ with data.azurerm_container_app_environment.containerappenv_data,
│ on main.tf line 68, in data "azurerm_container_app_environment" "containerappenv_data":
│ 68: data "azurerm_container_app_environment" "containerappenv_data" {
│
│ retrieving Log Analytics Workspace: no matching workspace found
Note :I deleted log analytics workpace due to some heavy logging but I still want to fetch env name and use it for multiple container instead of creating new workspace
data "azurerm_container_app_environment" "containerappenv_data" {
name = "development"
resource_group_name = data.azurerm_resource_group.rg_data.name
}
output "container_app_environment_name" {
value = data.azurerm_container_app_environment.containerappenv_data
}
Terraform Plan returns with following error
Planning failed. Terraform encountered an error while generating this plan,
╷
│ Error: retrieving Log Analytics Workspace: no matching workspace found
│
│ with data.azurerm_container_app_environment.containerappenv_data,
│ on main.tf line 68, in data "azurerm_container_app_environment" "containerappenv_data":
│ 68: data "azurerm_container_app_environment" "containerappenv_data" {
│
│ retrieving Log Analytics Workspace: no matching workspace found
Note :I deleted log analytics workpace due to some heavy logging but I still want to fetch env name and use it for multiple container instead of creating new workspace
Share Improve this question edited Mar 26 at 8:19 margusl 18.3k3 gold badges22 silver badges29 bronze badges asked Mar 25 at 20:57 DatfreakDatfreak 11 bronze badge 02 Answers
Reset to default 0Fetch Azure container app environment name using Terraform data block moul
The issue seems is occurring while fetching container app environment name because of deletion of log analytics workspace. This is because Terraform is attempting to fetch information about a Log Analytics Workspace tied to your Azure Container App environment.
But it failed to fetch the information related to log analytics workspace, as it doesn't exist as it deleted.
I tried the same configuration from my end to fetch the same as requirement and faced the blocker mentioned below
So to overcome this issue, without recreating the workspace you can try to follow approach.
You just need its name at output as name of container app environment so you could use an external tool to fetch the name and pass it to Terraform, then you will be able to fetch the name and use the output in the code moving forward.
Configuration:
data "azurerm_resource_group" "rg_data" {
name = "vinay-rg"
}
data "external" "container_app_env" {
program = [
"pwsh", "-Command",
"az containerapp env show --name development --resource-group ${data.azurerm_resource_group.rg_data.name} --query name --output tsv | ForEach-Object { '{ \"name\": \"' + $_ + '\" }' }"
]
}
output "container_app_environment_name" {
value = data.external.container_app_env.result["name"]
}
Deployment:
Here, the data "external"
block runs custom external scripts and handles output directly, while data "azurerm_container_app_environment"
uses the Azure Terraform provider, which requires all associated resources to exist and be accessible.
Once these requirements are sorted, then only it works. Since workspace is deleted so it fails to fetch the associations ended up giving error.
Refer:
external_external | Data Sources | HashiCorp/external | Terraform | Terraform Registry
Thanks Vinay for the the workaround and It is really helpful to know that we can use azure cli in terraform data block but I was able to fetch container app env using same data block but this time I fetched calling container app and retrieved its nested element without relying App environment resource
data "azurerm_container_app" "ca_data" {
name = "containerappname"
resource_group_name = data.azurerm_resource_group.rg_data.name
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744168862a4561434.html
评论列表(0条)