[英]How to create an aws security group rule allowing RDP ports from anywhere using terraform?
I need to create aws security group rule resource aws_security_group_rule
, attach it to AWS EC2 Windows instance and be able to RDP into it from anywhere.我需要创建 aws 安全组规则资源
aws_security_group_rule
,将其附加到 AWS EC2 Windows 实例,并能够从任何地方 RDP 进入它。
sg.tf sg.tf
resource "aws_security_group" "My_VPC_Security_Group" {
vpc_id = aws_vpc.My_VPC.id
name = "My VPC Security Group"
description = "My VPC Security Group"
}
You could use the following where 3389
is default RDP port:您可以使用以下内容,其中
3389
是默认 RDP 端口:
resource "aws_security_group" "My_VPC_Security_Group" {
vpc_id = aws_vpc.My_VPC.id
name = "My VPC Security Group"
description = "My VPC Security Group"
ingress {
from_port = 3389
to_port = 3389
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"]
}
The below code worked for me, which creates security group rules using aws_security_group_rule
as I wanted.下面的代码对我有用,它根据需要使用
aws_security_group_rule
创建安全组规则。
resource "aws_security_group" "My_VPC_Security_Group" {
vpc_id = aws_vpc.My_VPC.id
name = "My VPC Security Group"
description = "My VPC Security Group"
}
resource "aws_security_group_rule" "ingress_rule" {
type = "ingress"
from_port = 3389
to_port = 3389
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.My_VPC_Security_Group.id
}
resource "aws_security_group_rule" "egress_rule" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.My_VPC_Security_Group.id
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.