Skip to content

Parallel Creation of stackit_server_backup_schedule Fails #760

@rswrz

Description

@rswrz

Description

Creating multiple stackit_server_backup_schedule resources in parallel fails with 409 Conflict errors.

Terraform Code

resource "stackit_server_backup_schedule" "hourly" {
  project_id = var.project_id
  server_id  = stackit_server.this.server_id

  enabled = true
  name    = "hourly"
  rrule   = "DTSTART;TZID=Europe/Berlin:19700101T000000 RRULE:FREQ=HOURLY;INTERVAL=1"

  backup_properties = {
    name             = "hourly"
    retention_period = 1
  }
}

resource "stackit_server_backup_schedule" "daily" {
  project_id = var.project_id
  server_id  = stackit_server.this.server_id

  enabled = true
  name    = "daily"
  rrule   = "DTSTART;TZID=Europe/Berlin:19700101T000000 RRULE:FREQ=DAILY;INTERVAL=1"

  backup_properties = {
    name             = "daily"
    retention_period = 7
  }
}

resource "stackit_server_backup_schedule" "weekly" {
  project_id = var.project_id
  server_id  = stackit_server.this.server_id

  enabled = true
  name    = "weekly"
  rrule   = "DTSTART;TZID=Europe/Berlin:19700101T000000 RRULE:FREQ=WEEKLY;INTERVAL=1"

  backup_properties = {
    name             = "weekly"
    retention_period = (7 * 5)
  }
}

resource "stackit_server_backup_schedule" "monthly" {
  project_id = var.project_id
  server_id  = stackit_server.this.server_id

  enabled = true
  name    = "monthly"
  rrule   = "DTSTART;TZID=Europe/Berlin:19700101T000000 RRULE:FREQ=MONTHLY;INTERVAL=1"

  backup_properties = {
    name             = "monthly"
    retention_period = (31 * 3)
  }
}

Error Output

Three out of four stackit_server_backup_schedule resources fail with the following error:

╷
│ Error: Error creating server backup schedule
│
│   with stackit_server_backup_schedule.hourly,
│   on main.tf line 116, in resource "stackit_server_backup_schedule" "hourly":
│  116: resource "stackit_server_backup_schedule" "hourly" {
│
│ Enabling server backup project before creation: enable server backup service: 409 Conflict, status code 409, Body: {"timestamp":"2025-04-03T12:57:55.465501275Z","status":"CONFLICT","message":"Request failed"}
│
╵
╷
│ Error: Error creating server backup schedule
│
│   with stackit_server_backup_schedule.weekly,
│   on main.tf line 147, in resource "stackit_server_backup_schedule" "weekly":
│  147: resource "stackit_server_backup_schedule" "weekly" {
│
│ Enabling server backup project before creation: enable server backup service: 409 Conflict, status code 409, Body: {"timestamp":"2025-04-03T12:57:55.465501012Z","status":"CONFLICT","message":"Request failed"}
│
╵
╷
│ Error: Error creating server backup schedule
│
│   with stackit_server_backup_schedule.monthly,
│   on main.tf line 164, in resource "stackit_server_backup_schedule" "monthly":
│  164: resource "stackit_server_backup_schedule" "monthly" {
│
│ Enabling server backup project before creation: enable server backup service: 409 Conflict, status code 409, Body: {"timestamp":"2025-04-03T12:57:55.416570619Z","status":"CONFLICT","message":"Request failed"}
│
╵

Additional Findings

  • Running terraform apply immediately after the failed attempt successfully creates the remaining three backup schedules.
  • The issue is likely due to the stackit_server_backup_schedule resource enabling the backup service on the server. Concurrent attempts to enable the service may conflict if the activation process is already in progress.

Workaround

Adding dependencies between the backup schedule resources prevents concurrent activation conflicts:

resource "stackit_server_backup_schedule" "hourly" {
  project_id = var.project_id
  server_id  = stackit_server.this.server_id

  enabled = true
  name    = "hourly"
  rrule   = "DTSTART;TZID=Europe/Berlin:19700101T000000 RRULE:FREQ=HOURLY;INTERVAL=1"

  backup_properties = {
    name             = "hourly"
    retention_period = 1
  }
}

resource "stackit_server_backup_schedule" "daily" {
  project_id = var.project_id
  server_id  = stackit_server.this.server_id

  enabled = true
  name    = "daily"
  rrule   = "DTSTART;TZID=Europe/Berlin:19700101T000000 RRULE:FREQ=DAILY;INTERVAL=1"

  backup_properties = {
    name             = "daily"
    retention_period = 7
  }

  # Workaround
  depends_on = [stackit_server_backup_schedule.hourly]
}

resource "stackit_server_backup_schedule" "weekly" {
  project_id = var.project_id
  server_id  = stackit_server.this.server_id

  enabled = true
  name    = "weekly"
  rrule   = "DTSTART;TZID=Europe/Berlin:19700101T000000 RRULE:FREQ=WEEKLY;INTERVAL=1"

  backup_properties = {
    name             = "weekly"
    retention_period = (7 * 5)
  }

  # Workaround
  depends_on = [stackit_server_backup_schedule.hourly]
}

resource "stackit_server_backup_schedule" "monthly" {
  project_id = var.project_id
  server_id  = stackit_server.this.server_id

  enabled = true
  name    = "monthly"
  rrule   = "DTSTART;TZID=Europe/Berlin:19700101T000000 RRULE:FREQ=MONTHLY;INTERVAL=1"

  backup_properties = {
    name             = "monthly"
    retention_period = (31 * 3)
  }

  # Workaround
  depends_on = [stackit_server_backup_schedule.hourly]
}

Expected Behavior

Multiple stackit_server_backup_schedule resources should be creatable within a single Terraform apply operation without failing due to conflicts. Currently, the issue is resolved only by reapplying the configuration or introducing explicit dependencies.

Environment

$ terraform -version
Terraform v1.11.3
on darwin_arm64
+ provider registry.terraform.io/stackitcloud/stackit v0.48.0

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions