File tree 7 files changed +125
-0
lines changed
7 files changed +125
-0
lines changed Original file line number Diff line number Diff line change
1
+ ## Inputs
2
+
3
+ | Name | Description | Type | Default | Required |
4
+ | ------| -------------| :----:| :-----:| :-----:|
5
+ | cluster | Cluster Name | string | n/a | yes |
6
+ | created\_ by | Created By | string | n/a | yes |
7
+ | environment | Environment | string | n/a | yes |
8
+ | vpc_id | VPC ID | string | n/a | yes |
9
+ | resource_type | Resource Type (public/private/cluster) | string | n/a | yes |
10
+ | resource_group | Resource Group | string | n/a | yes |
11
+ | create_before_destroy | Create SG before destroying | bool | true | no |
12
+ | sg_description | The security group description | string | n/a | yes |
13
+ | allow_all_egress | Add an allow all egress rule to the SG | bool | true | no |
14
+
15
+
16
+ ## Outputs
17
+
18
+ | Name | Description |
19
+ | ------| -------------|
20
+ | id | The ID of the security group |
21
+ | arn | The ARN of the security group |
22
+ | vpc_id | The VPC ID |
23
+ | owner_id | The owner ID |
24
+ | name | The name of the security group |
25
+ | description | The description of the security group |
Original file line number Diff line number Diff line change
1
+ data "aws_region" "current" {}
Original file line number Diff line number Diff line change
1
+ locals {
2
+ resource_identifier = lower (" ${ var . cluster } -${ var . resource_group } -${ var . resource_type } -sg" )
3
+
4
+ default_tags = {
5
+ ManagedBy = " terraform"
6
+ Region = lower (data. aws_region . current . name )
7
+ CreatedBy = lower (var. created_by )
8
+ Cluster = lower (var. cluster )
9
+ Environment = lower (var. environment )
10
+ Name = local.resource_identifier
11
+ ResourceType = lower (var. resource_type )
12
+ ResourceGroup = lower (var. resource_group )
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ output id {
2
+ value = aws_security_group. base_sg . id
3
+ }
4
+
5
+ output arn {
6
+ value = aws_security_group. base_sg . arn
7
+ }
8
+
9
+ output vpc_id {
10
+ value = aws_security_group. base_sg . vpc_id
11
+ }
12
+
13
+ output owner_id {
14
+ value = aws_security_group. base_sg . owner_id
15
+ }
16
+
17
+ output name {
18
+ value = aws_security_group. base_sg . name
19
+ }
20
+
21
+ output description {
22
+ value = aws_security_group. base_sg . description
23
+ }
Original file line number Diff line number Diff line change
1
+ resource "aws_security_group" "base_sg" {
2
+ name = local. resource_identifier
3
+ vpc_id = var. vpc_id
4
+ description = var. sg_description
5
+
6
+ lifecycle {
7
+ create_before_destroy = true
8
+ }
9
+ }
10
+
11
+ resource "aws_security_group_rule" "all_egress" {
12
+ type = " egress"
13
+ count = var. allow_all_egress ? 1 : 0
14
+ security_group_id = aws_security_group. base_sg . id
15
+ cidr_blocks = [" 0.0.0.0/0" ]
16
+ from_port = 0
17
+ to_port = 0
18
+ protocol = " -1"
19
+ }
Original file line number Diff line number Diff line change
1
+ variable cluster {
2
+ description = " Cluster Name"
3
+ }
4
+
5
+ variable created_by {
6
+ description = " Created By"
7
+ }
8
+
9
+ variable environment {
10
+ description = " Environment"
11
+ }
12
+
13
+ variable vpc_id {
14
+ description = " VPC ID"
15
+ }
16
+
17
+ variable resource_type {
18
+ description = " Resource Type (public/private/cluster)"
19
+ }
20
+
21
+ variable resource_group {
22
+ description = " Resource Group (service name)"
23
+ }
24
+
25
+ variable create_before_destroy {
26
+ type = bool
27
+ default = true
28
+ description = " Create SG before destroying"
29
+ }
30
+
31
+ variable sg_description {
32
+ description = " The security group description"
33
+ }
34
+
35
+ variable allow_all_egress {
36
+ type = bool
37
+ default = true
38
+ description = " Add an allow all egress rule to the SG"
39
+ }
Original file line number Diff line number Diff line change
1
+
2
+ terraform {
3
+ required_version = " >= 0.12"
4
+ }
You can’t perform that action at this time.
0 commit comments