RDS 的 Terraform AWS 安全组条目

标签 terraform amazon-rds aws-security-group

我正在尝试创建带有安全组的 VPC 并将其与 ec2 和 RDS 一起使用。

  1. 为 ec2 创建安全组 SG1,并开放端口 80
  2. 引用第一个安全组 sg1 创建安全组 rdssg

resource "aws_vpc" "dev-vpc" {
    cidr_block = var.vpc_cidr
    enable_dns_hostnames = true
    tags = {
        Name = "Dev-VPC"
    }
}

resource "aws_security_group" "sg1" {
    name = "sg1"
    vpc_id =  aws_vpc.dev-vpc.id

    ingress {
        from_port = 80
        to_port = 80
        protocol = "tcp"
        cidr_blocks = ["0.0.0.0/0"]
    }

    egress {
        from_port = 0
        to_port = 0
        protocol = "-1"
        cidr_blocks = ["0.0.0.0/0"]

    }

}

resource "aws_security_group" "rdssg" {
    name = "rdssg"
    vpc_id =  aws_vpc.dev-vpc.id

    ingress {
        from_port = 3306
        to_port = 3306
        protocol = "tcp"
        security_groups = aws_security_group.sg1.id

    }

    egress {
        from_port = 0
        to_port = 0
        protocol = "-1"
        cidr_blocks = ["0.0.0.0/0"]

    }

当我运行 terraform plan 时,出现以下错误

Error: Incorrect attribute value type

  on ../module/vpc/vpc.tf line 152, in resource "aws_security_group" "rdssg":
 152:         security_groups = aws_security_group.sg1.id

Inappropriate value for attribute "security_groups": set of string required.
``

Not able to understand the error . Appreciate the help.

最佳答案

security_groups 属性是一组安全组,因此您需要提供如下值:

security_groups = [aws_security_group.sg1.id]

关于RDS 的 Terraform AWS 安全组条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65552221/

相关文章:

java - Postgresql 使用 Java 应用程序发送到后端时发生 I/O 错误

mysql - 无法连接到通过 Route53 托管的 RDS 只读副本的域名

azure - 将 Terraform 的 Azure SQL 资源从 `azurerm_sql_database` 升级到 `azurerm_mssql_database`

terraform - 将多行文件拆分为 Terraform 变量以通过键访问值

amazon-web-services - Terraform:如何确保我在预期的 AWS 账户上运行 terraform

mysql - AWS数据管道-从外部源提取数据?

postgresql - 如何在 Elastic Beanstalk 上更新 pg_dump

amazon-web-services - 实例无法通信 - 相同的 VPC 和子网,不同的安全组

python - 如何在 boto3 中创建源为 sg 的入口规则

terraform - 使用 Terraform 的 GCP 中的 Stackdriver "Alert & Notification"