部署密钥对
应用场景
相关资源/数据源
资源
操作步骤
1. 脚本准备
2. 创建KPS密钥对资源
variable "keypair_name" {
description = "The name of the KPS keypair"
type = string
}
variable "keypair_scope" {
description = "The scope of the KPS keypair"
type = string
default = "user"
}
variable "keypair_user_id" {
description = "The user ID to which the KPS keypair belongs"
type = string
default = ""
}
variable "keypair_encryption_type" {
description = "The encryption mode of the KPS keypair"
type = string
default = "kms"
}
variable "kms_key_id" {
description = "The ID of the KMS key"
type = string
default = ""
}
variable "kms_key_name" {
description = "The name of the KMS key"
type = string
default = ""
validation {
condition = var.keypair_encryption_type != "kms" || (var.kms_key_id != "" || var.kms_key_name != "")
error_message = "At least one of kms_key_id and kms_key_name must be provided when keypair_encryption_type set to kms"
}
}
variable "keypair_description" {
description = "The description of the KPS keypair"
type = string
default = ""
}
# 在指定region(region参数缺省时默认继承当前provider块中所指定的region)下创建KPS密钥对资源
resource "huaweicloud_kps_keypair" "test" {
name = var.keypair_name
scope = var.keypair_scope
user_id = var.keypair_user_id != "" ? var.keypair_user_id : null
encryption_type = var.keypair_encryption_type
kms_key_id = var.kms_key_id != "" ? var.kms_key_id : null
kms_key_name = var.kms_key_name != "" ? var.kms_key_name : null
description = var.keypair_description
}3. 预设资源部署所需的入参(可选)
4. 初始化并应用Terraform配置
参考信息
Last updated