File tree 5 files changed +51
-39
lines changed
terraform/environments/aws-account-id/us-east-2/dev
5 files changed +51
-39
lines changed Original file line number Diff line number Diff line change @@ -2,42 +2,12 @@ module "ubuntu_ami" {
2
2
source = " ../../../../../../../modules/aws/ec2/ami"
3
3
}
4
4
5
- # https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
6
- resource "aws_security_group" "dev_security_group" {
7
- name = " dev_security_group"
8
- description = " Allow SSH"
9
- vpc_id = var. vpc_id
10
-
11
- ingress {
12
- description = " SSH"
13
- from_port = 22
14
- to_port = 22
15
- protocol = " tcp"
16
- cidr_blocks = [" 0.0.0.0/0" ]
17
- }
18
-
19
- /* ingress {
20
- description = "Same group"
21
- from_port = 0
22
- to_port = 0
23
- protocol = "-1"
24
- self = true
25
- } */
26
-
27
- egress {
28
- from_port = 0
29
- to_port = 0
30
- protocol = " -1"
31
- cidr_blocks = [" 0.0.0.0/0" ]
32
- }
33
- }
34
-
35
5
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance
36
6
resource "aws_instance" "dev_example" {
37
7
ami = module. ubuntu_ami . id
38
8
instance_type = " t3.nano"
39
9
key_name = var. terraform_key_pair_id
40
- security_groups = [ aws_security_group . dev_security_group . name ]
10
+ vpc_security_group_ids = var . security_groups
41
11
subnet_id = var. subnet_id
42
12
associate_public_ip_address = true
43
13
@@ -105,4 +75,4 @@ resource "aws_eip" "dev_example_eip" {
105
75
resource "aws_eip_association" "dev_example_eip_association" {
106
76
instance_id = aws_instance. dev_example . id
107
77
allocation_id = aws_eip. dev_example_eip . id
108
- }
78
+ }
Original file line number Diff line number Diff line change @@ -25,12 +25,13 @@ dependency "default_vpc" {
25
25
mock_outputs = {
26
26
vpc_id = " default_vpc_id"
27
27
subnet_id = " default_subnet_id"
28
+ dev_security_group_name = " dev"
28
29
}
29
30
}
30
31
31
32
inputs = {
32
33
terraform_key_pair_id = dependency.terraform_key_pair.outputs.id
33
34
terraform_key_pair_private_key_openssh = dependency.terraform_key_pair.outputs.private_key_openssh
34
- vpc_id = dependency.default_vpc.outputs.vpc_id
35
+ security_groups = [ dependency.default_vpc.outputs.dev_security_group_name]
35
36
subnet_id = dependency.default_vpc.outputs.subnet_id
36
- }
37
+ }
Original file line number Diff line number Diff line change @@ -8,7 +8,13 @@ variable "terraform_key_pair_private_key_openssh" {
8
8
type = string
9
9
}
10
10
11
- variable "vpc_id " {
12
- description = " The ID of the default vpc in a region"
11
+ variable "subnet_id " {
12
+ description = " The ID of the default vpc subnet in a region"
13
13
type = string
14
- }
14
+ }
15
+
16
+ variable "security_groups" {
17
+ description = " List of security groups for attaching into instance"
18
+ type = list
19
+ default = []
20
+ }
Original file line number Diff line number Diff line change @@ -14,4 +14,34 @@ data "aws_subnet" "default" {
14
14
default_for_az = true
15
15
vpc_id = data. aws_vpc . default . id
16
16
state = " available"
17
- }
17
+ }
18
+
19
+ # https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
20
+ resource "aws_security_group" "dev" {
21
+ name = " dev"
22
+ description = " Allow SSH"
23
+ vpc_id = data. aws_vpc . default . id
24
+
25
+ ingress {
26
+ description = " SSH"
27
+ from_port = 22
28
+ to_port = 22
29
+ protocol = " tcp"
30
+ cidr_blocks = [" 0.0.0.0/0" ]
31
+ }
32
+
33
+ /* ingress {
34
+ description = "Same group"
35
+ from_port = 0
36
+ to_port = 0
37
+ protocol = "-1"
38
+ self = true
39
+ } */
40
+
41
+ egress {
42
+ from_port = 0
43
+ to_port = 0
44
+ protocol = " -1"
45
+ cidr_blocks = [" 0.0.0.0/0" ]
46
+ }
47
+ }
Original file line number Diff line number Diff line change @@ -6,4 +6,9 @@ output "vpc_id" {
6
6
output "subnet_id" {
7
7
value = data. aws_subnet . default . id
8
8
description = " The ID of the default subnet in default vpc"
9
- }
9
+ }
10
+
11
+ output "dev_security_group_name" {
12
+ value = aws_security_group. dev . name
13
+ description = " The name of the 'dev' security group"
14
+ }
You can’t perform that action at this time.
0 commit comments