RDS 的 Terraform AWS 安全组条目

问题描述

我正在尝试使用安全组创建 VPC,并将它们用于 ec2 和 RDS。

  1. 为开放端口 80 的 ec2 创建安全组 SG1
  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 计划时,出现以下错误

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]

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...