diff --git a/azurerm/internal/services/automation/automation_runbook_resource.go b/azurerm/internal/services/automation/automation_runbook_resource.go index 78bce62e8dea..5ced52d161a9 100644 --- a/azurerm/internal/services/automation/automation_runbook_resource.go +++ b/azurerm/internal/services/automation/automation_runbook_resource.go @@ -259,7 +259,11 @@ func resourceArmAutomationRunbookRead(d *schema.ResourceData, meta interface{}) response, err := client.GetContent(ctx, resGroup, accName, name) if err != nil { - return fmt.Errorf("Error retrieving content for Automation Runbook %q (Account %q / Resource Group %q): %+v", name, accName, resGroup, err) + if utils.ResponseWasNotFound(response.Response) { + d.Set("content", "") + } else { + return fmt.Errorf("retrieving content for Automation Runbook %q (Account %q / Resource Group %q): %+v", name, accName, resGroup, err) + } } if v := response.Value; v != nil { diff --git a/azurerm/internal/services/automation/tests/automation_runbook_resource_test.go b/azurerm/internal/services/automation/tests/automation_runbook_resource_test.go index c7facc854573..c235dda01569 100644 --- a/azurerm/internal/services/automation/tests/automation_runbook_resource_test.go +++ b/azurerm/internal/services/automation/tests/automation_runbook_resource_test.go @@ -90,6 +90,25 @@ func TestAccAzureRMAutomationRunbook_PSWithContent(t *testing.T) { }) } +func TestAccAzureRMAutomationRunbook_PSWorkflowWithoutUri(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_automation_runbook", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMAutomationRunbookDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMAutomationRunbook_PSWorkflowWithoutUri(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMAutomationRunbookExists(data.ResourceName), + ), + }, + data.ImportStep("publish_content_link"), + }, + }) +} + func testCheckAzureRMAutomationRunbookDestroy(s *terraform.State) error { conn := acceptance.AzureProvider.Meta().(*clients.Client).Automation.RunbookClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -300,3 +319,39 @@ CONTENT } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } + +func testAccAzureRMAutomationRunbook_PSWorkflowWithoutUri(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_automation_account" "test" { + name = "acctest-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "Basic" +} + +resource "azurerm_automation_runbook" "test" { + name = "Get-AzureVMTutorial" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + automation_account_name = azurerm_automation_account.test.name + + log_verbose = "true" + log_progress = "true" + description = "This is a test runbook for terraform acceptance test" + runbook_type = "PowerShell" + + publish_content_link { + uri = "" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +}