Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for using latest correct build deployment for Azure Spring Apps #20980

Open
1 task done
felipmiguel opened this issue Mar 16, 2023 · 6 comments
Open
1 task done

Comments

@felipmiguel
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

When using azurerm_spring_cloud_build_deployment it is necessary to specify build_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:

  • provide a data source to retrieve the builds, providing the possibility to find the "latest".
  • change the behavior of <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

# Using a new data source named azure_spring_cloud_build
data "azurerm_spring_cloud_build_deployment" "latest_build" {
     spring_cloud_app_id = azurerm_spring_cloud_app.application.id
     build_id = "<latest>"
}
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_build_deployment.latest_build.id
  # other params
}

# Asumming a new value for build_result_id
resource "azurerm_spring_cloud_build_deployment" "application_deployment" {
  name                = "default"
  spring_cloud_app_id = azurerm_spring_cloud_app.application.id
  build_result_id     = "<latest>"
  # other params
}

References

No response

@yuwzho
Copy link

yuwzho commented Mar 20, 2023

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
}

@d-desai
Copy link

d-desai commented May 1, 2023

Hi is this feature being implemented or is there a work around right now which we can use to get the latest correct build?

@showpune
Copy link

showpune commented May 4, 2023

@smile37773, can you help to update here?

@smile37773
Copy link

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.

@yuwzho
Copy link

yuwzho commented May 8, 2023

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"
  }
}

@felipmiguel
Copy link
Author

@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:

  1. Deploy Terraform. build_result_id=<default>. Doesn't work yet as there is no build.
  2. Deploy the application, for instance using az cli. It works now as it is assigned a build to the deployment.
  3. If changes in the Terraform configuration are required, for instance for other components, not the application, then apply Terraform. Right now, using <default> overwrites the working build id. If <default> doesn't overwrite it would continue working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants