前提条件
为确保您的阿里云账号及云资源使用安全,如非必要都应避免直接使用阿里云账号(即主账号)建议您
创建RAM角色,并对角色进行授权。
请确保您已创建服务角色,详情请参见创建可信实体为阿里云服务的RAM角色。
请确保您已为角色进行授权,详情请参见管理RAM角色的权限,权限详情如下表所示。
权限策略名称 | 权限说明 |
AliyunOOSFullAccess | 管理OOS |
AliyunROSFullAccess | 管理ROS |
AliyunECSFullAccess | 管理ECS |
操作步骤
步骤一:确认参数
进入OOS控制台的OOS补丁管理页面。根据页面展示内容以及ROS的资源类型ALIYUN::OOS::Execution确认以下参数。
|
参数
|
类型
|
说明
|
|
OOSTemplateName
|
String
|
OOS模板名称
|
|
ResourceType
|
String
|
资源类型
|
|
Targets
|
Json
|
目标实例
|
|
Timeout
|
Number
|
超时时间
|
|
CancelOnDelete
|
Boolean
|
是否删除时取消
|
|
Action
|
String
|
配置补丁基线的方式
|
|
TimerTrigger
|
Json
|
定时类型
|
|
WhetherCreateSnapshot
|
Boolean
|
是否为系统盘创建快照
|
|
RetentionDays
|
Number
|
快照保留天数
|
|
RebootIfNeed
|
Boolean
|
是否重启
|
步骤二:编写ROS模板
当确认参数后可以编写ROS模板,在Parameters、Resources、Outputs中使用参数。
-
在Parameters中编写用户在页面自定义的参数。
-
-
-
在Metadata中将执行参数排列合理。
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- PatchBaselineName
- OperationSystem
- Product
- Classification
- Severity
- DefaultPatchBaseline
Label:
zh-cn: 补丁基线
en: Patch baseline
- Parameters:
- OOSTemplateName
- ResourceType
- Targets
- Timeout
- CancelOnDelete
- Action
- TimerTrigger
- WhetherCreateSnapshot
- RetentionDays
- RebootIfNeed
Label:
zh-cn: 执行参数
en: Execution parameters
locals {
approval_rules_json = <<EOF
{
"PatchRules": [
{
"EnableNonSecurity": true,
"PatchFilterGroup": [
{
"Values": ["OS"],
"Key": "PatchSet"
},
{
"Values": ["Windows"],
"Key": "ProductFamily"
},
{
"Values": ["Windows 10", "Windows 7", "Windows Server 2022"],
"Key": "Product"
},
{
"Values": ["Security Updates", "Updates", "Update Rollups", "Critical Updates"],
"Key": "Classification"
},
{
"Values": ["Critical", "Important"],
"Key": "Severity"
}
],
"ApproveAfterDays": 7,
"ComplianceLevel": "Medium"
}
]
}
EOF
oos_parameters_json = <<EOF
{
"resourceType": "ALIYUN::ECS::Instance",
"targets": {
"Type": "All",
"Parameters": {
"regionId": "cn-hangzhou",
"Status": "Running"
}
}
}
EOF
}
-
完整的示例模板如下。
ROSTemplateFormatVersion: "2015-09-01"
Description:
zh-cn: 使用ROS定时或立即执行补丁基线。
en: Use ROS to schedule or execute patch baselines.
Parameters:
RegionId:
Required: true
Type: String
Label:
zh-cn: 地域ID
en: RegionId
AssociationProperty: ALIYUN::ECS::RegionId::RegionDeploy
OOSTemplateName:
Type: String
Label:
zh-cn: 模板名称。
en: Template name
Default: ACS-ECS-BulkyApplyPatchBaseline
AssociationProperty: ALIYUN::OOS::Template::TemplateName
AssociationPropertyMetadata:
RegionId:
Ref: RegionId
Description:
zh-cn: ACS-ECS-BulkyApplyPatchBaseline:用于执行补丁操作的模板。
en: ACS-ECS-BulkyApplyPatchBaseline:The template name used to execute patch operations.
MinLength: 2
MaxLength: 128
Action:
Default: install
AssociationPropertyMetadata:
LocaleKey: OOSPatchExecuteType
ValueLabelMapping:
install:
zh-cn: 安装并扫描
en: Install
scan:
zh-cn: 扫描
en: Scan
AllowedValues:
- install
- scan
Type: String
Label:
zh-cn: 配置补丁基线的方式
en: Action
TimerTrigger:
AssociationProperty: ALIYUN::OOS::Component::TimerTrigger
AssociationPropertyMetadata:
MinuteInterval: 30
Type: Json
Label:
zh-cn: 定时类型
en: TimerTrigger
WhetherCreateSnapshot:
Default: false
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${Action}
- install
Type: Boolean
Label:
zh-cn: 是否为系统盘创建快照
en: WhetherCreateSnapshot
RetentionDays:
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${WhetherCreateSnapshot}
- true
Default: 7
MaxValue: 65536
MinValue: 1
Label:
zh-cn: 快照保留天数
en: RetentionDays
Type: Number
RebootIfNeed:
Default: false
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${Action}
- install
Type: Boolean
Label:
zh-cn: 是否重启
en: RebootIfNeed
ResourceType:
Type: String
Label:
en: ResourceType
zh-cn: 资源类型
AssociationPropertyMetadata:
ValueLabelMapping:
ALIYUN::ECS::Instance:
zh-cn: ECS实例
en: ECS instance
ALIYUN::ECD::Desktop:
zh-cn: 无影云桌面
en: Desktop
AllowedValues:
- ALIYUN::ECS::Instance
- ALIYUN::ECD::Desktop
Default: ALIYUN::ECS::Instance
Targets:
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: ResourceType
DeployedRegionId: RegionId
Status: Running
Type: Json
Label:
zh-cn: 目标实例
en: TargetInstance
Timeout:
Type: Number
Label:
zh-cn: 超时时间。
en: Timeout
Default: 1800
Description:
zh-cn: 超时时间,单位为秒。
en: Timeout in seconds'
CancelOnDelete:
Type: Boolean
Label:
zh-cn: 是否删除时取消
en: CancelOnDelete
Default: true
AllowedValues:
- true
- false
AssociationPropertyMetadata:
ValueLabelMapping:
true:
zh-cn: 是
en: true
false:
zh-cn: 否
en: false
Resources:
Execution:
Type: ALIYUN::OOS::Execution
Properties:
TemplateName:
Ref: OOSTemplateName
Parameters:
resourceType:
Ref: ResourceType
targets:
Ref: Targets
Action:
Ref: Action
TimerTrigger:
Ref: TimerTrigger
WhetherCreateSnapshot:
Ref: WhetherCreateSnapshot
RetentionDays:
Ref: RetentionDays
ResourceOptions:
SuccessStatuses:
- Running
- Success
- Queued
- Waiting
Timeout:
Ref: Timeout
CancelOnDelete:
Ref: CancelOnDelete
Outputs:
Execution:
Description:
zh-cn: 执行成功。
en: Whether the execution is successful.
Value:
Fn::GetAtt:
- Execution
- Status
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- OOSTemplateName
- ResourceType
- Targets
- Timeout
- CancelOnDelete
- Action
- TimerTrigger
- WhetherCreateSnapshot
- RetentionDays
- RebootIfNeed
Label:
zh-cn: 执行参数
en: Execution parameters
terraform {
required_providers {
alicloud = {
source = "aliyun/alicloud"
version = "1.229.1"
}
}
}
provider "alicloud" {
region = "cn-hangzhou"
}
variable "patch_baseline_name" {
description = "补丁基线名称"
type = string
}
locals {
approval_rules_json = <<EOF
{
"PatchRules": [
{
"EnableNonSecurity": true,
"PatchFilterGroup": [
{
"Values": ["OS"],
"Key": "PatchSet"
},
{
"Values": ["Windows"],
"Key": "ProductFamily"
},
{
"Values": ["Windows 10", "Windows 7", "Windows Server 2022"],
"Key": "Product"
},
{
"Values": ["Security Updates", "Updates", "Update Rollups", "Critical Updates"],
"Key": "Classification"
},
{
"Values": ["Critical", "Important"],
"Key": "Severity"
}
],
"ApproveAfterDays": 7,
"ComplianceLevel": "Medium"
}
]
}
EOF
oos_parameters_json = <<EOF
{
"resourceType": "ALIYUN::ECS::Instance",
"targets": {
"Type": "All",
"Parameters": {
"regionId": "cn-hangzhou",
"Status": "Running"
}
}
}
EOF
}
resource "alicloud_oos_patch_baseline" "baseline" {
patch_baseline_name = var.patch_baseline_name
operation_system = "Windows"
approval_rules = local.approval_rules_json
}
resource "alicloud_oos_default_patch_baseline" "default" {
patch_baseline_name = alicloud_oos_patch_baseline.baseline.patch_baseline_name
}
resource "alicloud_oos_execution" "example" {
template_name = "ACS-ECS-BulkyApplyPatchBaseline"
parameters = local.oos_parameters_json
depends_on = [alicloud_oos_patch_baseline.baseline,alicloud_oos_default_patch_baseline.default]
}
output "patch_baseline_id" {
value = alicloud_oos_patch_baseline.baseline.id
}
步骤三:使用模板创建资源栈
本节仅展示创建资源栈的主要步骤,更多内容,请参见创建资源栈。
登录资源编排ROS>部署>资源栈,进入资源栈列表页面。
单击创建资源栈。
在创建资源栈页面,将步骤二提供的完整示例模板复制粘贴到模板内容中,并单击下一步。
根据实际情况配置模板、资源栈等信息,并单击下一步。
完成合规预检和检查并确认阶段的任务后,单击创建。
在资源栈列表页面,查看已创建的资源栈。
单击资源页签,然后单击资源ID即可进入对应资源的控制台。