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

Fix/schedules start after planned date #9

Merged
merged 3 commits into from
May 14, 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.

## [Unreleased]

## [2.0.3] - 2024-05-10

### Fixed

- Fixed issue that all schedules were created with a start date after the planned date

## [2.0.2] - 2024-02-19

### Fixed

- Fixed wrong variable name in azure query creation
- fixed typo in regex
- added errorCounter to actualle let the runbook status be "failed" if error occur
Expand Down
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,32 @@ module "update_management" {

No outputs.

## Resource types
## Resource types

| Type | Used |
|------|-------|
| [azurerm_automation_job_schedule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_job_schedule) | 1 |
| [azurerm_automation_runbook](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_runbook) | 1 |
| [azurerm_automation_schedule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_schedule) | 1 |
| [time_static](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/static) | 1 |

**`Used` only includes resource blocks.** `for_each` and `count` meta arguments, as well as resource blocks of modules are not considered.
| Type | Used |
|------|-------|
| [azurerm_automation_job_schedule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_job_schedule) | 1 |
| [azurerm_automation_runbook](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_runbook) | 1 |
| [azurerm_automation_schedule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_schedule) | 1 |
| [time_static](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/static) | 1 |

**`Used` only includes resource blocks.** `for_each` and `count` meta arguments, as well as resource blocks of modules are not considered.

## Modules

No modules.

## Resources by Files
## Resources by Files

### main.tf
### main.tf

| Name | Type |
|------|------|
| [azurerm_automation_job_schedule.set_deployment_schedules](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_job_schedule) | resource |
| [azurerm_automation_runbook.set_deployment_schedules](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_runbook) | resource |
| [azurerm_automation_schedule.every_12h_starting_7am](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_schedule) | resource |
| [time_static.schedule_start_tomorrow_7am](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/static) | resource |
| Name | Type |
|------|------|
| [azurerm_automation_job_schedule.set_deployment_schedules](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_job_schedule) | resource |
| [azurerm_automation_runbook.set_deployment_schedules](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_runbook) | resource |
| [azurerm_automation_schedule.every_12h_starting_7am](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_schedule) | resource |
| [time_static.schedule_start_tomorrow_7am](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/static) | resource |

<!-- END_TF_DOCS -->

# Contribute
Expand Down
16 changes: 12 additions & 4 deletions runbooks/Set-DeploymentSchedules.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ foreach ($severityGroup in $severityGroups) {
$dayInterval = [int]$splitSeverityGroup[0]
$weekdayRepetition = $splitSeverityGroup[1]
$weekday = $splitSeverityGroup[2]
$startTime = (get-date ($splitSeverityGroup[3].Substring(0, 2) + ":" + $splitSeverityGroup[3].Substring(2, 2))).AddDays(1)
$plannedTime = get-date ($splitSeverityGroup[3].Substring(0, 2) + ":" + $splitSeverityGroup[3].Substring(2, 2))
if ($plannedTime -lt (get-date).AddHours(2)) {
$startTime = $plannedTime.AddDays(1)
}
else {
$startTime = $plannedTime
}

Write-Output "StartTime of $severityGroup is $startTime"
$rebootSetting = $rebootOptions[$splitSeverityGroup[5]]
$queryTags = @{
"Severity Group Monthly" = "$($severityGroup)"
Expand All @@ -137,7 +145,7 @@ foreach ($severityGroup in $severityGroups) {
}
catch {
Write-Error -Exception ($_.Exception) -Message "Could not create schedule for $severityGroup." -ErrorAction Continue
$errorCounter +=1
$errorCounter += 1
continue
}

Expand All @@ -151,7 +159,7 @@ foreach ($severityGroup in $severityGroups) {
}
catch {
Write-Error -Exception ($_.Exception) -Message "Could not create azure for $severityGroup." -ErrorAction Continue
$errorCounter +=1
$errorCounter += 1
continue
}

Expand All @@ -169,7 +177,7 @@ foreach ($severityGroup in $severityGroups) {
}
catch {
Write-Error -Exception ($_.Exception) -Message "Could not create Update configuration for $severityGroup" -ErrorAction Continue
$errorCounter +=1
$errorCounter += 1
continue
}

Expand Down