Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Tenant Project variable optimistic concurrency exceptions #777

@snigdhasjg

Description

@snigdhasjg

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

  1. Create a new tenant via terraform
  2. Attach a project to that tenant which has 3-4 variables to override via terraform
  3. Attach variable variable values using for_each loop via terraform
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions