简体   繁体   English

如何使用 terraform 创建允许来自任何地方的 RDP 端口的 aws 安全组规则?

[英]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.

相关问题 从安全组中删除 RDP 规则后,为什么 AWS EC2 RDP 会话继续处于活动状态? - Why do AWS EC2 RDP sessions continue to be active after removing the RDP rule from security group? 有条件地使用 terraform 中的计数创建 aws_security_group_rule - Conditionally create aws_security_group_rule with count in terraform AWS 和 Terraform - 安全组中的默认出口规则 - AWS and Terraform - Default egress rule in security group 如何使用 append 或删除安全组的入口/出口规则 Terraform? - How to append or delete the ingress/egress rule for a security group using Terraform? 是否有专门允许访问 AWS KMS 的 AWS 安全组规则? - Is there an AWS security group rule specifically allowing access to AWS KMS? 带有 Terraform 的 AWS - 安全组规则中的安全组参数 - AWS with Terraform - security groups argument inside a security group rule Terraform aws 安全组 revoke_rule_on_delete? - Terraform aws security group revoke_rule_on_delete? 使用Ansible从AWS EC2 Security组中删除规则 - Remove a rule from AWS EC2 Security group using Ansible 从Java中的另一个安全组创建AWS安全组入站规则 - Create Aws Security Group Inbound Rule from another security group in java 如何将安全组附加到 terraform 中的 aws 实例 - How to attach a security group to aws instance in terraform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM