-
Notifications
You must be signed in to change notification settings - Fork 66
Tenant Project variable optimistic concurrency exceptions #777
Description
Describe the bug
We have a list of Tenant variable which we override per tenant let say CPU and Memory config. We are using octopusdeploy_tenant_project
with for_each
loop to create create project and octopusdeploy_tenant_project_variable
with for_each
to create variable for it.
We are dynamically looping through all the tenant variables and creating an octopusdeploy_tenant_project_variable per each config value since they are all unique and doesn't have any dependency on each other terraform makes parallel request to Octopus to create these resources
Looks like the recent release have added lock on database, so as to allow only one variable update at at time and failing with below error.
resource "octopusdeploy_tenant" "tenant" {
name = var.name
tenant_tags = local.tenants_tags
}
resource "octopusdeploy_tenant_project" "tenant_projects" {
for_each = local.project_set
project_id = each.key
tenant_id = octopusdeploy_tenant.tenant.id
environment_ids = each.value
}
resource "octopusdeploy_tenant_project_variable" "tenant_project_variable" {
for_each = local.templates
environment_id = each.value.environment_id
project_id = each.value.project_id
template_id = each.value.template_id
tenant_id = octopusdeploy_tenant.tenant.id
value = each.value.value
depends_on = [
octopusdeploy_tenant_project.tenant_projects
]
}
But its failing with concurrency error.
Steps to reproduce
- Create a new tenant via terraform
- Attach a project to that tenant which has 3-4 variables to override via terraform
- Attach variable variable values using for_each loop via terraform
- See error
Expected behavior
I can update individual/independent variables without seeing any concurrency issue
Logs and other supporting information
Error: Error updating tenant variables
with module.tenant.octopusdeploy_tenant_project_variable.tenant_project_variable["<some-key>-resources_limits_memory"]
on .terraform/modules/tenant/octopus/tenant/main.tf line 82, in resource "octopusdeploy_tenant_project_variable" "tenant_project_variable":
resource "octopusdeploy_tenant_project_variable" "tenant_project_variable" {
octopus deploy api returned an error on endpoint /api/Spaces-<space-id>/tenants/Tenants-<tenant-id>/variables - [The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded. See https://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.]
So issue with optimistic concurrency
Screenshots
Environment and versions:
- OS:
Linux
,OSX
- Octopus Server Version:
2024.3.12251
- Terraform Version:
1.9.5
- Octopus Terraform Provider Version:
0.30.2
Additional context
We can't go back to previous versions as there are multiple bugs like when tenant tags gets updated all the associated project were being removed have been solved in latest version 0.30