我正在尝试使用terraform模板来配置RDS实例,而我的模板看起来像这样
template.tf
resource "aws_security_group" "web-server-security"{
name = "webserver-sg"
description = "webserver security group"
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
tags{
Name = "web-server-sg"
}
resource "aws_security_group" "db-server-sg" {
name = "db-server"
description = "dbserver security group"
ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
security_groups = ["${aws_security_group.web-server-security.id}"]
}
tags{
Name = "db-server-sg"
}
}
resource "aws_db_instance" "echomany_db" {
name = "echomanydb"
engine = "mysql"
engine_version = "5.7"
storage_type = "gp2"
allocated_storage = 20
instance_class = "db.t2.micro"
username = "${var.AWS_DB_USERNAME}"
password = "${var.AWS_DB_PASSWORD}"
parameter_group_name = "default.mysql5.7"
skip_final_snapshot = true
security_group_names = [
"${aws_security_group.db-server-sg.id}"
]
tags{
Name = "db-server"
}
}
但是我遇到以下错误:
发生1个错误: * aws_db_instance.echomany_db:发生1个错误:
我不知道问题是什么以及如何解决此问题。
答案 0 :(得分:2)
应使用文档vpc_security_group_ids
中提到的内容,而不要使用security_group_names
,后者是已弃用的参数。
答案 1 :(得分:1)
名为
的参数 security_group_names = [
"${aws_security_group.db-server-sg.id}"
]
仅可在使用ec2经典模式或在VPC外部使用时使用。 请改用vpc_security_group_ids。
答案 2 :(得分:0)
您可以使用vpc_security_groups_ids = [ ]
代替security_group_names
,因为它只能在使用ec2经典模式时使用
示例:
vpc_security_group_ids=["${aws_security_group.rds.id}"]