terraformterraform-provider-azureazure-automationazure-runbook

Content of the Azure Runbook not getting updated when the content link referred to by the Terraform script is updated


I'm using the azurerm_automation_runbook module to create an Azure Automation Runbook. Below is the code I'm using.

resource "azurerm_automation_runbook" "automation_runbook" {
  name                    = var.automation_runbook_name
  location                = var.location
  resource_group_name     = var.resource_group_name
  automation_account_name = var.automation_account_name
  runbook_type            = "PowerShell"
  log_verbose             = "true"
  log_progress            = "true"

  publish_content_link {
    uri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/c4935ffb69246a6058eb24f54640f53f69d3ac9f/101-automation-runbook-getvms/Runbooks/Get-AzureVMTutorial.ps1"
  }
}

I was able to create a Runbook using the above code successfully. But the problem is when I change the uri within the publish_content_link block to https://raw.githubusercontent.com/azureautomation/automation-packs/master/200-connect-azure-vm/Runbooks/Connect-AzureVM.ps1 and apply (terraform apply detects the change and apply it successfully), the new PowerShell script is not getting reflected in the Azure Automation Runbook in the Azure Portal and it still shows the old PowerShell script.

Any help on how to fix this issue would be appreciated.


Solution

  • I tested this on my environment and I noticed that simply changing the uri in publish_content_link doesn't really do any changes in the runbook script.

    enter image description here

    enter image description here


    In order to apply the changes in the script you have to change the name of the runbook too instead of only changing the uri.

    So, after you change the name and uri both in the terraform code and do a apply. It will recreate the runbook with the new name and content in the portal.

    Outputs:

    enter image description here

    enter image description here

    OR

    If you want to change just the content and not the name , then you can save the script from that link locally and pass the content to the already created runbook and it will successfully update the content.

    I tested this as well with the below code:

    provider "azurerm"{
      features{}
    }
    
    provider "local" {}
    data "azurerm_resource_group" "example" {
      name     = "ansumantest"
    }
    
    resource "azurerm_automation_account" "example" {
      name                = "account1"
      location            = data.azurerm_resource_group.example.location
      resource_group_name = data.azurerm_resource_group.example.name
    
      sku_name = "Basic"
    }
    
    # added after the runbook was created
    data "local_file" "pscript" {
      filename = "C:/Users/user/terraform/runbook automation/connect-vm.ps1"
    }
    
    resource "azurerm_automation_runbook" "example" {
      name                    = "Get-AzureVMTutorial"
      location                = data.azurerm_resource_group.example.location
      resource_group_name     = data.azurerm_resource_group.example.name
      automation_account_name = azurerm_automation_account.example.name
      log_verbose             = "true"
      log_progress            = "true"
      description             = "This is an example runbook"
      runbook_type            = "PowerShell"
    
     content = data.local_file.pscript.content # added this to update the content
    }
    

    Output:

    enter image description here

    enter image description here