Skip to content

Commit d89225c

Browse files
committed
up dev default vpc and example ec2 instance
1 parent 79125bf commit d89225c

File tree

5 files changed

+51
-39
lines changed

5 files changed

+51
-39
lines changed

terraform/environments/aws-account-id/us-east-2/dev/ec2/instance/example/main.tf

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,12 @@ module "ubuntu_ami" {
22
source = "../../../../../../../modules/aws/ec2/ami"
33
}
44

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-
355
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance
366
resource "aws_instance" "dev_example" {
377
ami = module.ubuntu_ami.id
388
instance_type = "t3.nano"
399
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
4111
subnet_id = var.subnet_id
4212
associate_public_ip_address = true
4313

@@ -105,4 +75,4 @@ resource "aws_eip" "dev_example_eip" {
10575
resource "aws_eip_association" "dev_example_eip_association" {
10676
instance_id = aws_instance.dev_example.id
10777
allocation_id = aws_eip.dev_example_eip.id
108-
}
78+
}

terraform/environments/aws-account-id/us-east-2/dev/ec2/instance/example/terragrunt.hcl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ dependency "default_vpc" {
2525
mock_outputs = {
2626
vpc_id = "default_vpc_id"
2727
subnet_id = "default_subnet_id"
28+
dev_security_group_name = "dev"
2829
}
2930
}
3031

3132
inputs = {
3233
terraform_key_pair_id = dependency.terraform_key_pair.outputs.id
3334
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]
3536
subnet_id = dependency.default_vpc.outputs.subnet_id
36-
}
37+
}

terraform/environments/aws-account-id/us-east-2/dev/ec2/instance/example/variables.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ variable "terraform_key_pair_private_key_openssh" {
88
type = string
99
}
1010

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"
1313
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+
}

terraform/environments/aws-account-id/us-east-2/dev/vpc/default/main.tf

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,34 @@ data "aws_subnet" "default" {
1414
default_for_az = true
1515
vpc_id = data.aws_vpc.default.id
1616
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+
}

terraform/environments/aws-account-id/us-east-2/dev/vpc/default/output.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ output "vpc_id" {
66
output "subnet_id" {
77
value = data.aws_subnet.default.id
88
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+
}

0 commit comments

Comments
 (0)