Skip to content

Commit 6b3bbf6

Browse files
Merge pull request #30887 from chris-troupe/d-security_group
Updating basic usage to include updated security group flow
2 parents 0a9dc7e + ba42f1c commit 6b3bbf6

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

website/docs/r/security_group.html.markdown

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,41 @@ Provides a security group resource.
2525
```terraform
2626
resource "aws_security_group" "allow_tls" {
2727
name = "allow_tls"
28-
description = "Allow TLS inbound traffic"
28+
description = "Allow TLS inbound traffic and all outbound traffic"
2929
vpc_id = aws_vpc.main.id
3030
31-
ingress {
32-
description = "TLS from VPC"
33-
from_port = 443
34-
to_port = 443
35-
protocol = "tcp"
36-
cidr_blocks = [aws_vpc.main.cidr_block]
37-
ipv6_cidr_blocks = [aws_vpc.main.ipv6_cidr_block]
38-
}
39-
40-
egress {
41-
from_port = 0
42-
to_port = 0
43-
protocol = "-1"
44-
cidr_blocks = ["0.0.0.0/0"]
45-
ipv6_cidr_blocks = ["::/0"]
46-
}
47-
4831
tags = {
4932
Name = "allow_tls"
5033
}
5134
}
35+
36+
resource "aws_vpc_security_group_ingress_rule" "allow_tls_ipv4" {
37+
security_group_id = aws_security_group.allow_tls.id
38+
cidr_ipv4 = aws_vpc.main.cidr_block
39+
from_port = 443
40+
ip_protocol = "tcp"
41+
to_port = 443
42+
}
43+
44+
resource "aws_vpc_security_group_ingress_rule" "allow_tls_ipv6" {
45+
security_group_id = aws_security_group.allow_tls.id
46+
cidr_ipv6 = aws_vpc.main.ipv6_cidr_block
47+
from_port = 443
48+
ip_protocol = "tcp"
49+
to_port = 443
50+
}
51+
52+
resource "aws_vpc_security_group_egress_rule" "allow_all_traffic_ipv4" {
53+
security_group_id = aws_security_group.allow_tls.id
54+
cidr_ipv4 = "0.0.0.0/0"
55+
ip_protocol = "-1" # semantically equivalent to all ports
56+
}
57+
58+
resource "aws_vpc_security_group_egress_rule" "allow_all_traffic_ipv6" {
59+
security_group_id = aws_security_group.allow_tls.id
60+
cidr_ipv6 = "::/0"
61+
ip_protocol = "-1" # semantically equivalent to all ports
62+
}
5263
```
5364

5465
~> **NOTE on Egress rules:** By default, AWS creates an `ALLOW ALL` egress rule when creating a new Security Group inside of a VPC. When creating a new Security Group inside a VPC, **Terraform will remove this default rule**, and require you specifically re-create it if you desire that rule. We feel this leads to fewer surprises in terms of controlling your egress rules. If you desire this rule to be in place, you can use this `egress` block:
@@ -246,7 +257,7 @@ The following arguments are required:
246257

247258
* `from_port` - (Required) Start port (or ICMP type number if protocol is `icmp` or `icmpv6`).
248259
* `to_port` - (Required) End range port (or ICMP code if protocol is `icmp`).
249-
* `protocol` - (Required) Protocol. If you select a protocol of `-1` (semantically equivalent to `all`, which is not a valid value here), you must specify a `from_port` and `to_port` equal to 0. The supported values are defined in the `IpProtocol` argument on the [IpPermission](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_IpPermission.html) API reference. This argument is normalized to a lowercase value to match the AWS API requirement when using with Terraform 0.12.x and above, please make sure that the value of the protocol is specified as lowercase when using with older version of Terraform to avoid an issue during upgrade.
260+
* `protocol` - (Required) Protocol. If you select a protocol of `-1` (semantically equivalent to `all`, which is not a valid value here), you must specify a `from_port` and `to_port` equal to 0. The supported values are defined in the `IpProtocol` argument on the [IpPermission](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_IpPermission.html) API reference. This argument is normalized to a lowercase value to match the AWS API requirement when using with Terraform 0.12.x and above, please make sure that the value of the protocol is specified as lowercase when using with older version of Terraform to avoid an issue during upgrade.
250261

251262
The following arguments are optional:
252263

@@ -276,7 +287,7 @@ The following arguments are optional:
276287
* `description` - (Optional) Description of this egress rule.
277288
* `ipv6_cidr_blocks` - (Optional) List of IPv6 CIDR blocks.
278289
* `prefix_list_ids` - (Optional) List of Prefix List IDs.
279-
* `protocol` - (Required) Protocol. If you select a protocol of `-1` (semantically equivalent to `all`, which is not a valid value here), you must specify a `from_port` and `to_port` equal to 0. The supported values are defined in the `IpProtocol` argument in the [IpPermission](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_IpPermission.html) API reference. This argument is normalized to a lowercase value to match the AWS API requirement when using Terraform 0.12.x and above. Please make sure that the value of the protocol is specified as lowercase when used with older version of Terraform to avoid issues during upgrade.
290+
* `protocol` - (Required) Protocol. If you select a protocol of `-1` (semantically equivalent to `all`, which is not a valid value here), you must specify a `from_port` and `to_port` equal to 0. The supported values are defined in the `IpProtocol` argument in the [IpPermission](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_IpPermission.html) API reference. This argument is normalized to a lowercase value to match the AWS API requirement when using Terraform 0.12.x and above. Please make sure that the value of the protocol is specified as lowercase when used with older version of Terraform to avoid issues during upgrade.
280291
* `security_groups` - (Optional) List of security groups. A group name can be used relative to the default VPC. Otherwise, group ID.
281292
* `self` - (Optional) Whether the security group itself will be added as a source to this egress rule.
282293

0 commit comments

Comments
 (0)