Terraform Postgres导入失败

问题描述 投票:0回答:1

嗨,我正在导入资源,但是失败了。我不确定是什么问题。有人可以指出我该如何解决此错误。

我尝试通过设置sslmode = "require"来获得相同的错误。我的ssl是数据库中的on,force.ssl是off

Terraform v0.12.20

provider.aws v2.58.0provider.postgresql v1.5.0您的Terraform版本已过时!最新版本

我的模块:locals.tf:

pgauth_dbs = var.env == "prod" ? var.prod_dbs : var.stage_dbs

variables.tf

variable "stage_dbs" {
  type    = list(string)
  default = ["host_configs", "staging", "staging_preview"]
}

提供者

provider "postgresql" {
  version = ">1.4.0"
  alias            = "pg1"
  host             = aws_db_instance.name.address
  port             = aws_db_instance.name.port
  username         = var.username
  password         = var.master_password
  expected_version = aws_db_instance.name.engine_version 
  sslmode          = "disable"
  connect_timeout  = 15
}

模块:

 resource "postgresql_database" "pgauth_dbs" {
  provider = postgresql.pg1
  for_each = toset(local.pgauth_dbs)
  name     = each.value
  owner    = "postgres"
}

根模块:

  module rds {
      source = ../../../../tf_module_rds
      username          = "postgres"
      master_password   = data.aws_kms_secrets.secrets_password.plaintext["password"]
      engine_version    = "11.5"
      instance_class    = "db.m5.xlarge"
      allocated_storage = "300"
      storage_type      = "gp2"    
}

terraform import module.rds.postgresql_database.name_dbs[“host_configs”] host_configs

module.rds.postgresql_database.name_dbs[“host_configs”]: Importing from ID “host_configs”…
module.rds.postgresql_database.name_dbs[“host_configs”]: Import prepared!
Prepared postgresql_database for import
module.rds.postgresql_database.name_dbs[\“host_configs”\]: Refreshing state… [id=host_configs]

Error: could not start transaction: pq: no PostgreSQL user name specified in startup packet
postgresql amazon-web-services terraform amazon-rds terraform-provider-aws
1个回答
0
投票

提供程序应指向实例的用户名而不是变量

provider "postgresql" {
  version = ">1.4.0"
  alias            = "pg1"
  host             = aws_db_instance.name.address
  port             = aws_db_instance.name.port
  username         = aws_db_instance.name.username
  password         = aws_db_instance.name.password
  database         = aws_db_instance.name.name
  expected_version = aws_db_instance.name.engine_version 
  sslmode          = "disable"
  connect_timeout  = 15
}
© www.soinside.com 2019 - 2024. All rights reserved.