- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试让资源 azurerm_automation_schedule
在每月发生的特定时间(例如:18:00)
进行部署。
我使用以下代码:
locals {
update_time = "18:00"
update_date = formatdate("YYYY-MM-DD", timeadd(timestamp(), "24h"))
update_timezone = "UTC"
}
resource "azurerm_automation_schedule" "main" {
name = "test"
resource_group_name = "myresourcegroupname"
automation_account_name = "myautomationaccountname"
frequency = "Month"
timezone = local.update_timezone
start_time = "${local.update_date}T${local.update_time}:00+02:00"
description = "This is an example schedule"
monthly_occurrence {
day = "Tuesday"
occurrence = "1"
}
}
“${local.update_date}T${local.update_time}:00+02:00”
在当前时间上添加 2 小时并将日期向前调 1。这是必需的确保时间表在未来开始。
这工作正常,除了下次我回来运行部署时,它会检测到由于日期更改而发生的新更改,即使没有发生真正的更改。start_time 总是向前滴答。
我似乎找不到任何可以提供帮助的地形逻辑。有没有办法在变量中设置静态开始时间,并且只有在发生变化时才更新? (不是日期)。
伪代码为:
if [update_time] has not changed, do not update [azurerm_automation_schedule]
else update [azurerm_automation_schedule] with the new time, incrementing the day forward
更新
我的最终工作代码(奖励:使用 Windows 更新调度程序,这很难工作!)
//== Provider used to store timestamp for updates ==//
provider "time" {
version = "~> 0.4"
}
//== Store 1 day in the future, only update if [local.update_time] is altered ==//
resource "time_offset" "next_day" {
offset_days = 1
triggers = {
update_time = local.update_time
}
}
locals {
update_time = "19:40"
update_date = substr(time_offset.next_day.rfc3339, 0, 10)
update_timezone = "UTC"
update_max_hours = "4"
update_classifications = "Critical, Security, UpdateRollup, ServicePack, Definition, Updates"
update_reboot_settings = "IfRequired"
update_day = "Tuesday"
update_occurrence = "2"
}
#This type should eventually replace the manual deploy via azurerm: azurerm_automation_softwareUpdateConfigurations
#https://github.com/terraform-providers/terraform-provider-azurerm/issues/2812
resource "azurerm_template_deployment" "windows" {
name = "windows-update"
resource_group_name = module.stack.azurerm_resource_group.name
template_body = <<DEPLOY
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"apiVersion": "2017-05-15-preview",
"type": "Microsoft.Automation/automationAccounts/softwareUpdateConfigurations",
"name": "${module.stack.azurerm_automation_account.name}/windows-updates",
"properties": {
"updateConfiguration": {
"operatingSystem": "Windows",
"duration": "PT${local.update_max_hours}H",
"windows": {
"excludedKbNumbers": [
],
"includedUpdateClassifications": "${local.update_classifications}",
"rebootSetting": "${local.update_reboot_settings}"
},
"azureVirtualMachines": [
"${module.server_1.azurerm_virtual_machine.id}",
"${module.server_2.azurerm_virtual_machine.id}"
],
"nonAzureComputerNames": [
]
},
"scheduleInfo": {
"frequency": "Month",
"startTime": "${local.update_date}T${local.update_time}:00",
"timeZone": "${local.update_timezone}",
"interval": 1,
"advancedSchedule": {
"monthlyOccurrences": [
{
"occurrence": "${local.update_occurrence}",
"day": "${local.update_day}"
}
]
}
}
}
}
]
}
DEPLOY
deployment_mode = "Incremental"
}
最佳答案
它不断计划更改的原因是因为您编写的代码指的是当前时间,而不是获取“明天”并以某种方式跟踪它。
为此,您需要一种方法来获取“明天”一次,并将其保留在状态中。存在于状态中的事物是资源,因此您需要一个代表带有偏移量的时间的资源。这就是time provider的地方进来。
这是最重要的部分:
resource "time_offset" "tomorrow" {
offset_days = 1
}
这将为您提供“明天”,应用后它将保存在 Terraform 状态中。
time_offset.tomorrow.rfc3339
将评估为:
2020-05-13T04:28:07Z
但是,我们只想要其中的 YYYY-MM-DD,因此我们使用 substr 来获取前 10 个字符:
substr(time_offset.tomorrow.rfc3339, 0, 10)
把它们放在一起,我们得到这个(添加了 4 行,包括空格,更改了 1 行):
locals {
update_time = "18:00"
update_date = substr(time_offset.tomorrow.rfc3339, 0, 10)
update_timezone = "UTC"
}
resource "time_offset" "tomorrow" {
offset_days = 1
}
resource "azurerm_automation_schedule" "main" {
name = "test"
resource_group_name = "myresourcegroupname"
automation_account_name = "myautomationaccountname"
frequency = "Month"
timezone = local.update_timezone
start_time = "${local.update_date}T${local.update_time}:00+02:00"
description = "This is an example schedule"
monthly_occurrence {
day = "Tuesday"
occurrence = "1"
}
}
您可能需要引入时间提供程序才能使用它(如果没有它就无法工作,请将其与您的 AzureRM 提供程序放在一起):
provider "time" {}
如果需要,您可以使用terraform taint 'time_offset.tomorrow'
强制重新计算时间。
关于azure - Terraform azurerm 计划 start_time 始终在新部署时重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61762648/
我正在尝试执行此操作: Login-AzureRmAccount Login-AzureRmAccount : The term 'Login-AzureRmAccount' is not recog
今天,使用新版本的 AzureRM 应用服务部署版本 2.1.3,我的所有构建都开始失败。 我将托管池用于 Team Services (Windows)。 2016-11-11T13:02:36.2
我正在使用 Terraform,现在我的应用程序的所有应用程序设置都在填充,因为基础架构可能会发生变化。这样一切都是自动的。 但是,我的 Linux 消费计划 Functions 应用程序有一个问题,
我正在尝试创建一个 Terraform 项目来创建 Azure 订阅中所需的所有内容,例如资源组、vnet、子网和 VM。 但是,当我运行一次并重试时,它指出它无法删除正在使用的子网。我没有更改有关子
有人知道创建 Azure WebApp 需要什么权限吗? 我有一个通过 Azure-DevOps 运行的 Ansible playbook,它应该创建一个资源组和应用服务: - hosts: loca
首先,我按照指示 here 进行操作创建点到站点 VPN。然后我在门户 UI 上创建了一个连接到本地网络的站点到站点 VPN。我的本地 VPN 网关设备是运行 SonicOS 增强版 5.9.1.4-
我想安装所有 AzureRM.* 模块的特定版本,因为有 26 个模块,我不想一一手动安装: PS C:\Users\hyar> find-module -name azurerm.* Version
我想使用 environment variables 配置两个 azurerm 提供程序 我尝试过这个: variable "SUBSCRIPTION_ID" { description = "S
在尝试将文件配置到 azure RM VM 时,我收到以下超时消息。 unknown error Post http://terraform.eastus.cloudapp.azure.com:338
我正在尝试在 Terraform 中创建每周 Azure VM 保护策略,在周五下午 6:30 运行,保留期为 1。TF 抛出与格式错误相关的错误“计划时间、计划天数、保留时间和保留天数”错误。我不确
证书的可导出属性设置为“True”。我需要在不同的 Azure 订阅中使用此证书。 最佳答案 在 Azure 自动化中将证书的可导出属性设置为 True 仅意味着该证书将在运行自动化作业的沙箱的证书存
我一直在寻找一种正确的方法来使用内部负载均衡器来改造我的内部虚拟机规模集,该负载均衡器不会通过公共(public) IP 暴露在互联网上。但是,节点应该能够访问互联网来下载 github 中的一些包。
我尝试使用为服务主体授权而初始化的 azurerm 提供程序来运行 terraform,providers.tf 中包含以下内容(服务主体具有订阅的所有者访问权限并可在其他代码中使用): provid
证书的可导出属性设置为“True”。我需要在不同的 Azure 订阅中使用此证书。 最佳答案 在 Azure 自动化中将证书的可导出属性设置为 True 仅意味着该证书将在运行自动化作业的沙箱的证书存
我一直在寻找一种正确的方法来使用内部负载均衡器来改造我的内部虚拟机规模集,该负载均衡器不会通过公共(public) IP 暴露在互联网上。但是,节点应该能够访问互联网来下载 github 中的一些包。
我尝试使用为服务主体授权而初始化的 azurerm 提供程序来运行 terraform,providers.tf 中包含以下内容(服务主体具有订阅的所有者访问权限并可在其他代码中使用): provid
我正在使用 azurerm_network_manager_admin_rule 资源为虚拟网络管理器资源创建管理规则。我只能在每条规则中传递一个地址前缀。有没有办法在同一规则中使用多个地址前缀? 这
我有以下要运行的演示脚本: https://learn.hashicorp.com/tutorials/terraform/azure-dependency?in=terraform/azure-ge
我一直在尝试创建一个脚本,可以获取Azure中所有托管磁盘的列表,其中包括虚拟机名称、磁盘名称、大小、操作系统类型和资源组名称,更重要的是可用空间和剩余可用磁盘空间。 我可以使用 Powershell
错误消息 执行terraform apply时收到以下错误消息: 错误:创建/更新虚拟网络“CTI-NETWORK”(资源组“CTI-RESOURCES”)时出错:network.VirtualNet
我是一名优秀的程序员,十分优秀!