我正在尝试创建一组 terraform/terragrunt 脚本来创建多个 Redshift 集群。我希望它们都共享相同的子网组和安全组,并且如果它们不存在则创建它们。我最初的尝试是创建一个模块“redshift”,定义如下:
data "aws_vpc" "default" {
default = true
}
data "aws_subnet_ids" "default" {
vpc_id = "${data.aws_vpc.default.id}"
}
resource "aws_security_group" "default" {
name = "${var.redshift_security_group_name}"
vpc_id = "${data.aws_vpc.default.id}"
}
resource "aws_redshift_subnet_group" "default" {
name = "${var.redshift_subnet_group_name}"
subnet_ids = ["${data.aws_subnet_ids.default.ids}"]
}
module "redshift" {
source = "terraform-aws-modules/redshift/aws"
version = "1.4.0"
cluster_identifier = "${var.cluster_identifier}"
cluster_database_name = "${var.cluster_database_name}"
cluster_node_type = "${var.cluster_node_type}"
cluster_master_password = "${var.cluster_master_password}"
cluster_master_username = "${var.cluster_master_username}"
vpc_security_group_ids = ["${aws_security_group.default.id}"]
preferred_maintenance_window = "${var.preferred_maintenance_window}"
publicly_accessible = "${var.publicly_accessible}"
redshift_subnet_group_name = "${var.redshift_subnet_group_name}"
parameter_group_name = "${var.parameter_group_name}"
cluster_number_of_nodes = "${var.cluster_number_of_nodes}"
cluster_iam_roles = ["${var.cluster_iam_roles}"]
tags = ["${var.tags}"]
}
这适用于创建单个集群,当创建第二个集群 terraform 无法识别安全组和子网组已经存在时。处理这个问题的正确方法是什么?将网络设置分解成自己的模块,让 redshift 模块依赖它?