File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,4 +24,33 @@ resource "aws_security_group" "ssh_restricted" {
2424 protocol = " -1"
2525 cidr_blocks = [" 0.0.0.0/0" ]
2626 }
27+ }
28+
29+ # Key pair ssh
30+ data "aws_key_pair" "key_pair" {
31+ key_name = var. aws_key_pair_name
32+ }
33+
34+ # Try filtering things out
35+ data "aws_ami" "ami" {
36+ most_recent = true
37+ owners = [" amazon" ] # Official Canonical AWS Account ID
38+
39+ filter {
40+ name = " image-id"
41+ values = [var . aws_ami_image_id ]
42+ }
43+
44+ filter {
45+ name = " virtualization-type"
46+ values = [" hvm" ]
47+ }
48+ }
49+
50+ resource "aws_instance" "ec2_instance" {
51+ ami = data. aws_ami . ami . id
52+ instance_type = var. aws_instance_type
53+ vpc_security_group_ids = concat ([aws_security_group . ssh_restricted . id ], var. aws_additional_security_groups )
54+ key_name = data. aws_key_pair . key_pair . key_name
55+ user_data = var. aws_instance_startup_script
2756}
Original file line number Diff line number Diff line change 11output "home_ip" {
22 description = " IP of your local workstation"
3- value = data. http . my_public_ip . body
3+ value = data. http . my_public_ip . response_body
4+ }
5+
6+ output "home_sg" {
7+ description = " Reference to the home security group"
8+ value = {
9+ arn = aws_security_group.ssh_restricted.arn
10+ id = aws_security_group.ssh_restricted.id
11+ }
12+ }
13+
14+ output "ec2_info" {
15+ value = aws_instance. ec2_instance
16+ }
17+
18+ output "ssh_command" {
19+ description = " SSH Command you can run to access the image"
20+ value = " ssh ec2-user@${ aws_instance . ec2_instance . public_dns } "
421}
Original file line number Diff line number Diff line change 11variable "aws_profile_name" {
22 description = " Name of your local aws profile"
33 type = string
4+ }
5+
6+ variable "aws_key_pair_name" {
7+ description = " Name of your AWS key pair that will be used for ssh"
8+ type = string
9+ }
10+
11+ # TODO: Make this work...
12+ # variable "aws_ami_name_filter" {
13+ # description = "Filter for finding the hvm ami"
14+ # type = list(string)
15+ # default = ["ubuntu/images/hvm-ssd/ubuntu-resolute-26.04-amd64-server-*"]
16+ # }
17+
18+ variable "aws_ami_image_id" {
19+ description = " image id for the ami."
20+ type = string
21+ default = " ami-0b6d9d3d33ba97d99"
22+ }
23+
24+ variable "aws_instance_type" {
25+ description = " Size of the image to stand up"
26+ type = string
27+ default = " t3a.nano"
28+ }
29+
30+ variable "aws_additional_security_groups" {
31+ description = " Additional security groups on top of the ssh only one created by module"
32+ type = list (string )
33+ default = []
34+ }
35+
36+ variable "aws_instance_startup_script" {
37+ description = " Startup script for instance."
38+ type = string
39+ default = null
440}
You can’t perform that action at this time.
0 commit comments