Terraform eks 数据源 vpc 子网安全组

Terraform eks datasource vpc subnets security group

我有一个创建 eks 集群的 terraform 脚本 我有另一个创建 rds 的 terraform 脚本,我想创建这个 rds 在与 eks 集群相同的 VPC 中。

data "aws_eks_cluster" "example" {
  name = "example"
}

output "subnets" {
  value = "${data.aws_eks_cluster.example.vpc_config.vpc_id}"
}

这是我的 rds.tf

resource "aws_db_instance" "rds" {
 allocated_storage    = "${var.rds_allocated_storage}"
 storage_type         = "${var.rds_storage_type}"
 engine               = "${var.rds_engine}"
 engine_version       = "${var.rds_engine_version}"
 instance_class       = "${var.rds_instance_class}"
 name                 = "${var.project_name}_${var.env}_data_rds${var.rds_engine}"
 username             = "dbadmin"
 password             = "${var.rds_db_password}"
 multi_az             = false
 skip_final_snapshot  = true
 db_subnet_group_name = "${aws_db_subnet_group.rds_subnet.name}"
 vpc_security_group_ids = "${var.rds_vpc_security_group_ids}"
 identifier  = "${var.project_name}-${var.env}-data-rds${var.rds_engine}"

我想从我的 eks 得到 db_subnet_group_name 和 vpc_security_group_ids 而不是来自 variables.tf

我相信你需要这样的东西

vpc_security_group_ids = "${data.aws_eks_cluster.example.vpc_config.0.security_group_ids}"