Terraform-provider-azurerm: Updating `azurerm_automation_runbook` configuration removes `azurerm_automation_job_schedule` and needs to be recreated

Created on 29 May 2020  ·  4Comments  ·  Source: terraform-providers/terraform-provider-azurerm

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

Terraform 0.12.25 and AzureRM Provider Version 2.11

Affected Resource(s)

  • azurerm_automation_job_schedule
  • azurerm_automation_runbook

Terraform Configuration Files


resource "azurerm_automation_runbook" "disk_snapshot" {
  name                    = "DiskSnapshots"
  location                = azurerm_resource_group.backup_rsg.location
  resource_group_name     = azurerm_resource_group.backup_rsg.name
  automation_account_name = azurerm_automation_account.backup_automation.name
  log_verbose             = "true"
  log_progress            = "true"
  description             = "Snapshot disk runbook"
  runbook_type            = "PowerShell"
  content = file("./DiskSnapshot.ps1")
  publish_content_link{
    uri = ""
  }
}

resource "azurerm_automation_schedule" "daily_schedule" {
  name                    = "Daily"
  resource_group_name     = azurerm_resource_group.backup_rsg.name
  automation_account_name = azurerm_automation_account.backup_automation.name
  frequency               = "Day"
  interval                = 1
  timezone                = "UTC"
  start_time              = "2020-05-29T18:00:00Z"
  description             = "Daily Schedule"
}

resource "azurerm_automation_job_schedule" "daily_job" {
  resource_group_name     = azurerm_resource_group.backup_rsg.name
  automation_account_name = azurerm_automation_account.backup_automation.name
  schedule_name           = azurerm_automation_schedule.daily_schedule.name
  runbook_name            = azurerm_automation_runbook.disk_snapshot.name
  parameters = {
    retentionindays      = 14
  }
}

Description of Issue

All of the resources are managed by Terraform, on first create everything works as expected. Then when one updates azurerm_automation_runbook configuration then applying it, this works as expected. The problem arises in next subsequent terraform apply because it tries to create
azurerm_automation_job_schedule again, but it already exists correctly in Azure.

Expected Behavior

azurerm_automation_job_schedule resources are kept in state and do not need to be created again when azurerm_automation_runbook was updated in-place.

Actual Behavior

terraform apply after updating azurerm_automation_runbook

  # azurerm_automation_job_schedule.daily_job will be created
  + resource "azurerm_automation_job_schedule" "daily_job" {
      + automation_account_name = "automation-account"
      + id                      = (known after apply)
      + job_schedule_id         = (known after apply)
      + parameters              = {
          + "retentionindays"      = "14"
          + "snapshotfrequencytag" = "Daily"
        }
      + resource_group_name     = "disk-backups"
      + runbook_name            = "DiskSnapshots"
      + schedule_name           = "Daily"
    }

Agree to the changes then error is thrown sometime during the run:

azurerm_automation_job_schedule.daily_job: Creating...

Error: automation.JobScheduleClient#Create: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="A job schedule for the specified runbook and schedule already exists."

  on runbook.tf line 71, in resource "azurerm_automation_job_schedule" "daily_job":
  71: resource "azurerm_automation_job_schedule" "daily_job" {

Steps to Reproduce

  1. Update configuration and/or content of azurerm_automation_runbook resource
  2. terraform apply, you will see it works as expected to update runbook resource
  3. terraform apply again you will see that azurerm_automation_job_schedule needs to be created.
  4. Cannot apply because azurerm_automation_job_schedule resources already/still exist in Azure

References

Maybe related #6466 #4851

bug servicautomation

All 4 comments

Any update on this issue? It's a real pain when you have a lot of runbooks / schedules / schedule links.

Hi @alikhtag , thanks for opening this issue. I'm fixing this.

This has been released in version 2.21.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.21.0"
}
# ... other configuration ...

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings