variable.tf
variable "private_subnets" {
type = list
default = ["subnet-abc1,subnet-abc2"]
}
main.tf
resource "aws_db_subnet_group" "rds_subnet_group" {
name = var.cluster_name
subnet_ids = "${var.private_subnets}"
tags = {
Name = var.cluster_name,
environment = var.environment
}
}
This the present code i want use varable.tf for subnet this is way i want achive like this subnet-abc1,subnet-abc2
2
Answers
i have sort issue with split this is the answer
Considering that your variable has a wrongly defined default value, the first thing to fix is that:
The way you are currently defining the default value, i.e,
["subnet-abc1,subnet-abc2"]
, is a list, however, it is a list with one element. Each element in a list of strings needs to start and end with double quotes, i.e. "some value". You can read more about lists in [1].Then, you would just need to fix the code in the
main.tf
to look like this:The syntax for subnets in the
main.tf
file is the old terraform syntax, so this will work without double quotes and${}
.[1] https://developer.hashicorp.com/terraform/language/expressions/types#list