在 RDS AWS 创建的密码部分下,我试图传递aws_secretsmanager_secret_version
价值。我得到以下错误。
resource "aws_db_instance" "airflow" {
allocated_storage = "${var.rds_allocated_storage}"
storage_type = "${var.rds_storage_type}"
storage_encrypted = "true"
engine = "mysql"
engine_version = "${var.rds_engine_version}"
instance_class = "${var.rds_instance_class}"
name = "airflow"
identifier = "airflow"
username = "${var.rds_username}"
password = "${jsondecode(aws_secretsmanager_secret_version.secret.secret_string)["rds_password"]}"
parameter_group_name = "-airflow-mysql"
vpc_security_group_ids = ["${aws_security_group_airflow_sg.id}"]
db_subnet_group_name = "${aws_db_subnet_group.airflow_rds.id}"
kms_key_id = "${data.aws_kms_key.rds.arn}"
license_model = "general-public-license"
depends_on = [
aws_db_parameter_group.airflow_mysql
]
tags = merge(
var.common_tags,
map("Classification", "private"),
map("Name", "-airflow-rds")
)
}
秘密管理器.tf
resource "aws_secretsmanager_secret" "secret" {
description = "airflow"
kms_key_id = "${data.aws_kms_key.sm.arn}"
name = "airflow"
}
resource "random_string" "rds_password" {
length = 16
special = true
override_special = "/@\" "
}
resource "aws_secretsmanager_secret_version" "secret" {
secret_id = "${aws_secretsmanager_secret.secret.id}"
secret_string = <<EOF
{
"rds_password": "${random_string.rds_password.result}"
}
EOF
}
以下是错误日志:-
错误:函数调用错误
在 ../../modules/airflow/outputs.tf 第 27 行,在输出 "rds_password": 27: value = jsondecode(aws_secretsmanager_secret_version.secret.secret_string)["rds_password"] |------ -------- | aws_secretsmanager_secret_version.secret.secret_string 是 "{\n \"rds_password\": \"9Y\"@xu3jy@sNGXt/\"\n }\n"
调用函数“jsondecode”失败:对象键:值对后的无效字符“@”。
错误:函数调用错误
在 ../../modules/airflow/rds.tf 第 12 行,在资源 "aws_db_instance" "airflow": 12: password = "${jsondecode(aws_secretsmanager_secret_version.secret.secret_string)["rds_password"]}" |- --------------- | aws_secretsmanager_secret_version.secret.secret_string 是 "{\n \"rds_password\": \"9Y\"@xu3jy@sNGXt/\"\n }\n"
调用函数“jsondecode”失败:对象键:值对后的无效字符“@”。