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

azurerm_automation_runbook: retain functionality for job_schedule for 4.0 #26798

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion internal/services/automation/automation_runbook_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,41 @@ func resourceAutomationRunbook() *pluginsdk.Resource {
ValidateFunc: validation.StringIsNotEmpty,
},

"job_schedule": helper.JobScheduleSchema(),
"job_schedule": {
Type: pluginsdk.TypeSet,
Optional: true,
Computed: true,
ConfigMode: pluginsdk.SchemaConfigModeAttr,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"schedule_name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.ScheduleName(),
},

"parameters": {
Type: pluginsdk.TypeMap,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
ValidateFunc: validate.ParameterNames,
},

"run_on": {
Type: pluginsdk.TypeString,
Optional: true,
},

"job_schedule_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
Set: helper.ResourceAutomationJobScheduleHash,
},

"publish_content_link": contentLinkSchema(false),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)
Expand Down Expand Up @@ -494,8 +493,7 @@ CONTENT
}

func (AutomationRunbookResource) withoutJobSchedule(data acceptance.TestData) string {
if !features.FourPointOhBeta() {
return fmt.Sprintf(`
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
Expand Down Expand Up @@ -540,52 +538,6 @@ CONTENT

job_schedule = []
}
`, data.RandomInteger, data.Locations.Primary)
}

return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}

resource "azurerm_automation_account" "test" {
name = "acctest-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku_name = "Basic"
}

resource "azurerm_automation_schedule" "test" {
name = "acctestAS-%[1]d"
resource_group_name = azurerm_resource_group.test.name
automation_account_name = azurerm_automation_account.test.name
frequency = "Week"
timezone = "Etc/UTC"
}

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"

content = <<CONTENT
param(
[string]$Output = "World",
)
"Hello, " + $Output + "!"
CONTENT
}
`, data.RandomInteger, data.Locations.Primary)
}

Expand Down
80 changes: 2 additions & 78 deletions internal/services/automation/helper/automation_job_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,86 +12,10 @@ import (
"github.com/gofrs/uuid"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2023-11-01/jobschedule"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func JobScheduleSchema() *pluginsdk.Schema {
if !features.FourPointOhBeta() {
return &pluginsdk.Schema{
Type: pluginsdk.TypeSet,
Optional: true,
Computed: true,
ConfigMode: pluginsdk.SchemaConfigModeAttr,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"schedule_name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.ScheduleName(),
},

"parameters": {
Type: pluginsdk.TypeMap,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
ValidateFunc: validate.ParameterNames,
},

"run_on": {
Type: pluginsdk.TypeString,
Optional: true,
},

"job_schedule_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
Set: resourceAutomationJobScheduleHash,
}
}

return &pluginsdk.Schema{
Type: pluginsdk.TypeSet,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"schedule_name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.ScheduleName(),
},

"parameters": {
Type: pluginsdk.TypeMap,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
ValidateFunc: validate.ParameterNames,
},

"run_on": {
Type: pluginsdk.TypeString,
Optional: true,
},

"job_schedule_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
Set: resourceAutomationJobScheduleHash,
}
}

func ExpandAutomationJobSchedule(input []interface{}, runBookName string) (*map[string]jobschedule.JobScheduleCreateParameters, error) {
res := make(map[string]jobschedule.JobScheduleCreateParameters)
if len(input) == 0 || input[0] == nil {
Expand Down Expand Up @@ -136,7 +60,7 @@ func ExpandAutomationJobSchedule(input []interface{}, runBookName string) (*map[

func FlattenAutomationJobSchedule(jsMap map[uuid.UUID]jobschedule.JobScheduleProperties) *pluginsdk.Set {
res := &pluginsdk.Set{
F: resourceAutomationJobScheduleHash,
F: ResourceAutomationJobScheduleHash,
}
for jsId, js := range jsMap {
var scheduleName, runOn string
Expand Down Expand Up @@ -207,6 +131,6 @@ func ResourceAutomationJobScheduleDigest(v interface{}) string {
return buf.String()
}

func resourceAutomationJobScheduleHash(v interface{}) int {
func ResourceAutomationJobScheduleHash(v interface{}) int {
return pluginsdk.HashString(ResourceAutomationJobScheduleDigest(v))
}
Loading