Open felipmiguel opened 1 year ago
Generatlly, I agree with the "Potential Terraform Configuration" provided by @manicminer . According to currently API spec, my suggestion is having a data resource for Microsoft.AppPlatform/Spring/BuildServices/Builds
, that can retrive the latest build result id
. Then the configuration can be written as below. Everytime the configuration executed, the Deployment will consume the latest build result id.
cc @ms-henglu @smile37773 @showpune
data "azurerm_spring_cloud_buildservice_build" "example" {
name = azurerm_spring_cloud_buildservice_build.example.name
resource_group_name = azurerm_spring_cloud_buildservice_build.example.resource_group_name
service_name = azurerm_spring_cloud_buildservice_build.example.service_name
buildservice_name = azurerm_spring_cloud_buildservice_build.example.buildservice_name
}
resource "azurerm_spring_cloud_build_deployment" "application_deployment" {
name = "default"
spring_cloud_app_id = azurerm_spring_cloud_app.application.id
build_result_id = data.azurerm_spring_cloud_buildservice_build.example.triggeredBuildResult.id
# other params
}
Hi is this feature being implemented or is there a work around right now which we can use to get the latest correct build?
@smile37773, can you help to update here?
Hi is this feature being implemented or is there a work around right now which we can use to get the latest correct build?
Yes, you can get the latest result id by calling the GET API of the build. You can get the triggeredBuildResult
in the response, which is the latest result id. And then you can use this id as the BuildResultId in the deployment.
Looks like the data is not added yet. You can try the azapi
for a quick work. @d-desai cc @ms-henglu
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.7.0"
}
azapi = {
source = "Azure/azapi"
}
}
}
resource "azurerm_spring_cloud_service" "spring" {
name = var.service_name
resource_group_name = var.resource_group_name
location = var.location
sku_name = "E0"
build_agent_pool_size = "S1"
}
data "azapi_resource" "buildservice" {
type = "Microsoft.AppPlatform/Spring/buildServices@2023-03-01-preview"
name = "default"
parent_id = azurerm_spring_cloud_service.spring.id
}
data "azapi_resource" "build" {
type = "Microsoft.AppPlatform/Spring/buildServices/builds@2023-03-01-preview"
name = var.build_name
parent_id = data.azapi_resource.buildservice.id
response_export_values = ["*"]
}
resource "azurerm_spring_cloud_app" "demo-time-app" {
name = "demo-time"
resource_group_name = var.resource_group_name
service_name = var.service_name
is_public = true
}
resource "azurerm_spring_cloud_build_deployment" "blue" {
name = "blue"
spring_cloud_app_id = azurerm_spring_cloud_app.demo-time-app.id
build_result_id = jsondecode(data.azapi_resource.build.output).properties.triggeredBuildResult.id
instance_count = 2
quota {
cpu = "2"
memory = "2Gi"
}
}
@yuwzho , is it possible to change the behavior of <default>
build_result_id? The solution that you provided can work when there is already an existing build. However if you deploy Terraform configuration for the first time there is no build, hence the deployment will fail. I changing the behavior of <default>
to the latest available or at least that do not overwrite if there a build assigned can work better.
Ideally the steps to follow would be:
<default>
. Doesn't work yet as there is no build.<default>
overwrites the working build id. If <default>
doesn't overwrite it would continue working.
Is there an existing issue for this?
Community Note
Description
When using
azurerm_spring_cloud_build_deployment
it is necessary to specifybuild_result_id
. It is possible to specify a build id, but there is no way to retrieve that value using terraform. Another option is specifying<default>
. The problem with the default value is that it is not the latest or the current deployment, causing a kind of uninstallation of the application. In my environment it causes the application to stop working.Some proposals:
<default>
to do not change the current deployment or provide another value,<latest>
to use the latest correct version.New or Affected Resource(s)/Data Source(s)
azurerm_spring_cloud_build_deployment, azurerm_spring_cloud_build
Potential Terraform Configuration
References
No response