【问题标题】:Terraform AWS Security group entries for RDSRDS 的 Terraform AWS 安全组条目
【发布时间】:2021-04-09 15:05:35
【问题描述】:

我正在尝试使用安全组创建 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.

【问题讨论】:

    标签: terraform amazon-rds aws-security-group


    【解决方案1】:

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

    security_groups = [aws_security_group.sg1.id]
    

    【讨论】:

      猜你喜欢
      • 2021-04-06
      • 1970-01-01
      • 2015-08-01
      • 2021-03-25
      • 2021-11-27
      • 2019-07-28
      • 1970-01-01
      • 2020-07-26
      • 1970-01-01
      相关资源
      最近更新 更多