azurerm_automation_job_scheduleazurerm_automation_runbook
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
}
}
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.
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.
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" {
content of azurerm_automation_runbook resourceterraform apply, you will see it works as expected to update runbook resourceterraform apply again you will see that azurerm_automation_job_schedule needs to be created.azurerm_automation_job_schedule resources already/still exist in Azure Maybe related #6466 #4851
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!