Skip to content

Commit d80addc

Browse files
committed
NRL-1385 create key pair to rdp into ec2
1 parent 5464f16 commit d80addc

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

terraform/account-wide-infrastructure/dev/ec2.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module "vpc" {
1111
module "web" {
1212
source = "../modules/ec2"
1313
instance_type = var.instance_type
14-
instance_key = var.instance_key
1514
name_prefix = "nhsd-nrlf--dev"
1615

1716
subnet_id = module.vpc.subnet_id

terraform/account-wide-infrastructure/dev/vars.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,3 @@ variable "instance_type" {
4343
description = "Type for EC2 Instance"
4444
default = "t2.micro"
4545
}
46-
47-
variable "instance_key" {
48-
default = "PowerBIGateway"
49-
}

terraform/account-wide-infrastructure/modules/ec2/ec2.tf

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
resource "aws_instance" "web" {
33
ami = data.aws_ami.windows-2019.id
44
instance_type = var.instance_type
5-
key_name = var.instance_key
5+
key_name = aws_key_pair.ec2_key_pair.key_name
66
subnet_id = var.subnet_id
77
security_groups = var.security_groups
88

@@ -13,3 +13,19 @@ resource "aws_instance" "web" {
1313
}
1414

1515
}
16+
17+
# Key pair for RDP access
18+
resource "tls_private_key" "instance_key_pair" {
19+
algorithm = "RSA"
20+
}
21+
22+
resource "aws_key_pair" "ec2_key_pair" {
23+
key_name = "PowerBI-GateWay-Key"
24+
public_key = tls_private_key.instance_key_pair.public_key_openssh
25+
}
26+
27+
# Saving Key Pair for ssh login for Client if needed
28+
resource "local_file" "ssh_key" {
29+
filename = "${aws_key_pair.ec2_key_pair.key_name}.pem"
30+
content = tls_private_key.instance_key_pair.private_key_pem
31+
}

terraform/account-wide-infrastructure/modules/ec2/vars.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ variable "name_prefix" {
33
description = "The prefix to apply to all resources in the module."
44
}
55
variable "instance_type" {}
6-
variable "instance_key" {}
76
variable "security_groups" {}
87
variable "subnet_id" {}

0 commit comments

Comments
 (0)