Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error setting the draft Automation Runbook, azurerm_automation_runbook fails with 404 Error - Unless Published version of runbook already exists #4403

Closed
Mounika0207 opened this issue Sep 20, 2019 · 15 comments

Comments

@Mounika0207
Copy link

Mounika0207 commented Sep 20, 2019

Terraform Configuration Files

resource "azurerm_resource_group" "example" {
  name     = "loggingRG"
  location = "eastus2"
}

resource "azurerm_automation_account" "example" {
  name                = "testaccount"
  location            = "${azurerm_resource_group.example.location}"
  resource_group_name = "${azurerm_resource_group.example.name}"

  sku {
    name = "Basic"
  }
}

data "local_file" "example" {
  filename = "${path.module}/Users/testuser/tftest/Conncetionscript.ps1"
}

resource "azurerm_automation_runbook" "example" {
  name                             = "Conncetionscript"
  location                         = "${azurerm_resource_group.example.location}"
  resource_group_name = "${azurerm_resource_group.example.name}"
  account_name              = "${azurerm_automation_account.example.name}"
  log_verbose                  = "true"
  log_progress                = "true"
  description                    = "testing tf template"
  runbook_type                = "PowerShell"

  depends_on = ["azurerm_automation_account.example"]

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

  content = "${data.local_file.example.filename}"
}

Debug Output

  • azurerm_automation_runbook.runbook_start: Error setting the draft Automation Runbook automation.RunbookDraftClient#ReplaceContent: Failure sending request: StatusCode=404 -- Original Error: Code="ResourceNotFound" Message="The Resource 'Microsoft.Automation/automationAccounts/testaccount/runbooks/Conncetionscript' under resource group 'loggingRG' was not found." "

Expected Behavior
Runbook should be created

Actual Behavior
Looking for creating runbook which doesn't exist

Steps to Reproduce
terraform apply

Terraform Version
Terraform v0.12.7

  • provider.azurerm v1.34.0
  • provider.local v1.3.0
@ratmav
Copy link

ratmav commented Oct 1, 2019

i ran into this today with the both the regular and custom content examples listed in the documentation.

@MathieuBuisson
Copy link

I ran into this problem as well, using the content argument in my case.
Terraform version : 0.12.9
Azurerm provider version : 1.35.0

@hbastosc
Copy link

hbastosc commented Oct 4, 2019

I am running into the same problem

terraform --version
Terraform v0.12.9
+ provider.azurerm v1.32.1
+ provider.local v1.3.0
Error: Error setting the draft Automation Runbook "redacted" (Account "avm-automation-account" / Resource Group "redacted"): automation.RunbookDraftClient#ReplaceContent: Failure sending request: StatusCode=404 -- Original Error: Code="ResourceNotFound" Message="The Resource 'Microsoft.Automation/automationAccounts/redacted/runbooks/redacted' under resource group 'redacted' was not found."

  on modules/automation_runbooks.tf line 56, in resource "azurerm_automation_runbook" "redacted":
  56: resource "azurerm_automation_runbook" "redacted" {

@draggeta
Copy link
Contributor

Yeah, for MR #3386 I've noticed that this started happening. This is due to the fact that MS basically removed the file the examples and tests were pointing to.

If you are using the content parameter, a workaround is to point the url to any location as long as it exists. Even something like http://google.com/ works.

@erlacherl-city
Copy link

erlacherl-city commented Oct 17, 2019

Hi @draggeta, I can't reproduce that it has anything to do with the publish_content_link. Creating a new runbook just always fails, period.

As far as I can see this is just a failure of terraform to perform the correct AzureRM operations.

I just retried this and it seems I was wrong. I must've made a mistake when running apply.

@draggeta
Copy link
Contributor

draggeta commented Oct 18, 2019

@erlacherl-city good to hear. The examples will hopefully be fixed once the MR is merged.

@joshschmitter
Copy link

joshschmitter commented Nov 19, 2019

Experiencing the same issue regardless of the publish_contentLlink uri and regardless of whether the content string is populated:
Screen Shot 2019-11-18 at 10 45 03 PM

@joshschmitter
Copy link

I think the runbook_type enum is case specific. It needs to be "PowerShell" with a capital "S"

@Cpcrook
Copy link

Cpcrook commented Dec 17, 2019

Having the same issue here:

Terraform v0.12.16
+ provider.azurerm v1.37.0

This is when creating a PowerShellWorkflow runbook

@jknash
Copy link
Contributor

jknash commented Mar 8, 2020

I can confirm that setting the uri in the publish_conent_link block to something generic like https://google.com works. I had a fake URL that doesn't exist before. This may just need some error handling or maybe does not need to be required if setting the content for the script inline? I'm using heredoc content for the script content so I can fill in parameters from references to other resources in my file. Here is what my azurerm_automation_runbook resource looks like for reference:

`resource "azurerm_automation_runbook" "start-bastion" {
count = var.aa_count
name = "Start-Bastion"
location = azurerm_resource_group.prd-mgmt.location
resource_group_name = azurerm_resource_group.prd-mgmt.name
automation_account_name = "${element(azurerm_automation_account.aa-mgmt.*.name, count.index)}"
log_verbose = "true"
log_progress = "true"
description = "Runbook for creating an Azure Bastion host"
runbook_type = "PowerShell"

publish_content_link {
uri = "https://google.com"
}

content = <<EOC
New-AzBastion -Name azb-prdmgmt01 -VirtualNetworkName ${element(azurerm_virtual_network.vn-mgmt.*.name, count.index)} -VirtualNetworkResourceGroupName ${azurerm_resource_group.prd-mgmt.name} -ResourceGroupName ${azurerm_resource_group.prd-mgmt.name} -PublicIpAddressName ${azurerm_public_ip.pip-azurebastion.name} -PublicIpAddressResourceGroupName ${azurerm_resource_group.prd-mgmt.name}
EOC
}`

@MrCaedes
Copy link

MrCaedes commented Apr 25, 2020

Just to muddle the water a bit; came across this issue the other day and pulled my hair out for a while.

A generic URL such as Google will work for PowerShell runbooks, for PowerShell Workflows it won't; you need to provide a URI which will return text/plain (such as raw.githubusercontent.com). No idea why, however, it's the only thing that works for me for deploying a mixture of PoSH and PoSH WF - Using Google (or any other URI) worked fine when deploying just PoSH.

@telekosmos
Copy link

Just to add what @mactator is telling, python scripts don't work either no matter what you set in the publish_content_link argument.

@ghost
Copy link

ghost commented May 8, 2020

This has been released in version 2.9.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.9.0"
}
# ... other configuration ...

@lmicverm
Copy link

This is not fixed in the version 2.9.0.
When creating a new runbook with content type PowerShellWorkflow, I still get a 404: resource not found, but it should create the resource!

@ghost
Copy link

ghost commented Jun 7, 2020

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!

@ghost ghost locked and limited conversation to collaborators Jun 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests