gpt4 book ai didi

amazon-web-services - Terraform RDS 数据库凭据

转载 作者:行者123 更新时间:2023-12-04 11:55:09 25 4
gpt4 key购买 nike

我正在尝试使用 AWS secret 管理器来声明 RDS 管理员凭证。

  • 在变量 RdsAdminCred 中将 rds.tf 中的凭据声明为键/值对
  • 也在同一个 tf 文件中声明了 secret
  • variable "RdsAminCred" {
    default = {
    username = "dbadmin"
    password = "dbadmin#02avia"
    }
    type = map(string)
    }

    resource "aws_secretsmanager_secret" "RdsAminCred" {
    name = "RdsAminCred"
    }
    resource "aws_secretsmanager_secret_version" "RdsAminCred" {
    secret_id = aws_secretsmanager_secret.RdsAminCred.id
    secret_string = jsonencode(var.RdsAminCred)
    }
  • 我不确定如何使用下面声明中的 secret 字符串来替换用户名和密码的硬编码值。
  • resource "aws_db_instance" "default" {
    identifier = "testdb"
    allocated_storage = 20
    storage_type = "gp2"
    engine = "mysql"
    engine_version = "5.7"
    instance_class = "db.t2.medium"
    name = "mydb"

    username = "dbadmin"
    password = "dbadmin#01avia"
    任何帮助表示赞赏..

    最佳答案

    我建议使用 random_password资源代替。然后您可以在集群配置和 secret 管理器中引用它。
    例子:

    resource "random_password" "master_password" {
    length = 16
    special = false
    }

    resource "aws_rds_cluster" "default" {
    cluster_identifier = "my-cluster"

    master_username = "admin"
    master_password = random_password.default_master_password.result

    # other configurations
    # .
    # .
    # .
    }

    resource "aws_secretsmanager_secret" "rds_credentials" {
    name = "credentials"
    }

    resource "aws_secretsmanager_secret_version" "rds_credentials" {
    secret_id = aws_secretsmanager_secret.rds_credentials.id
    secret_string = <<EOF
    {
    "username": "${aws_rds_cluster.default.master_username}",
    "password": "${random_password.master_password.result}",
    "engine": "mysql",
    "host": "${aws_rds_cluster.default.endpoint}",
    "port": ${aws_rds_cluster.default.port},
    "dbClusterIdentifier": "${aws_rds_cluster.default.cluster_identifier}"
    }
    EOF
    }

    关于amazon-web-services - Terraform RDS 数据库凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65603923/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com