Skip to content

Commit 37a2e8a

Browse files
committed
NRL-1385 use autoscaling ec2 for flexibility
1 parent 8483dd2 commit 37a2e8a

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Initial AMI to use
2+
data "aws_ami" "windows" {
3+
most_recent = true
4+
filter {
5+
name = "name"
6+
values = ["Windows_Server-2022-English-Full-Base-*"]
7+
}
8+
filter {
9+
name = "virtualization-type"
10+
values = ["hvm"]
11+
}
12+
owners = ["801119661308"] # Canonical
13+
}
14+
15+
# AMI to use
16+
data "aws_ami" "final" {
17+
most_recent = true
18+
filter {
19+
name = "name"
20+
values = ["PowerBI-On-Premise-Gateway"]
21+
}
22+
filter {
23+
name = "virtualization-type"
24+
values = ["hvm"]
25+
}
26+
owners = ["self"]
27+
}
28+
29+
# Subnets
30+
data "aws_subnets" "subnets" {
31+
filter {
32+
name = "tag:Type"
33+
values = ["private"]
34+
}
35+
}
36+
37+
# VPC
38+
data "aws_vpc" "account_vpc" {
39+
filter {
40+
name = "tag:Name"
41+
values = [var.account_name]
42+
}
43+
}
44+
45+
# Security group of db
46+
data "aws_security_group" "db_sg" {
47+
filter {
48+
name = "group-name"
49+
values = [var.db_sg_name]
50+
}
51+
52+
vpc_id = data.aws_vpc.account_vpc.id
53+
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,39 @@ module "autoscaling" {
9595
user_data = filebase64("./userdata.txt")
9696
update_default_version = true
9797
}
98+
99+
############################
100+
# Add rule to db managed group
101+
############################
102+
# module "upgrade_db_sg" {
103+
# source = "registry.terraform.io/terraform-aws-modules/security-group/aws"
104+
# version = "4.13.1"
105+
106+
# create_sg = false
107+
# security_group_id = data.aws_security_group.db_sg.id
108+
# ingress_with_source_security_group_id = [
109+
# {
110+
# description = "Allow incoming connections from Power BI Gateway"
111+
# rule = "postgresql-tcp"
112+
# source_security_group_id = module.security-group-outbound.security_group_id
113+
# },
114+
# ]
115+
# }
116+
117+
############################
118+
# Key pair for RDP access
119+
############################
120+
resource "tls_private_key" "instance_key_pair" {
121+
algorithm = "RSA"
122+
}
123+
124+
resource "aws_key_pair" "ec2_key_pair" {
125+
key_name = "PowerBI-GateWay-Key"
126+
public_key = tls_private_key.instance_key_pair.public_key_openssh
127+
}
128+
129+
# Saving Key Pair for ssh login for Client if needed
130+
resource "local_file" "ssh_key" {
131+
filename = "${aws_key_pair.ec2_key_pair.key_name}.pem"
132+
content = tls_private_key.instance_key_pair.private_key_pem
133+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<powershell>
2+
Start-Service AmazonSSMAgent
3+
</powershell>
4+
<persist>true</persist>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
variable "aws_region" {
2+
description = "Default region where to deploy resources"
3+
type = string
4+
}
5+
6+
## Account
7+
variable "account_name" {
8+
description = "Account where to deploy VPC"
9+
type = string
10+
}
11+
12+
## Account
13+
variable "db_sg_name" {
14+
description = "Name of edeal security group"
15+
type = string
16+
}

0 commit comments

Comments
 (0)