0

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.

0

2 Answers 2

0

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

0

you need to add another property after uri which is version and give it some version number. every time you need to update the content you need to give it a new version number

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 8, 2023 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.