-
Notifications
You must be signed in to change notification settings - Fork 343
/
infra.tf
132 lines (107 loc) · 3.2 KB
/
infra.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# AWS infrastructure resources
resource "tls_private_key" "global_key" {
algorithm = "RSA"
rsa_bits = 2048
}
resource "local_sensitive_file" "ssh_private_key_pem" {
filename = "${path.module}/id_rsa"
content = tls_private_key.global_key.private_key_pem
file_permission = "0600"
}
resource "local_file" "ssh_public_key_openssh" {
filename = "${path.module}/id_rsa.pub"
content = tls_private_key.global_key.public_key_openssh
}
# Temporary key pair used for SSH accesss
resource "aws_key_pair" "quickstart_key_pair" {
key_name_prefix = "${var.prefix}-neuvector-"
public_key = tls_private_key.global_key.public_key_openssh
}
resource "aws_vpc" "neuvector_vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
tags = {
Name = "${var.prefix}-neuvector-vpc"
}
}
resource "aws_internet_gateway" "neuvector_gateway" {
vpc_id = aws_vpc.neuvector_vpc.id
tags = {
Name = "${var.prefix}-neuvector-gateway"
}
}
resource "aws_subnet" "neuvector_subnet" {
vpc_id = aws_vpc.neuvector_vpc.id
cidr_block = "10.0.0.0/24"
availability_zone = var.aws_zone
tags = {
Name = "${var.prefix}-neuvector-subnet"
}
}
resource "aws_route_table" "neuvector_route_table" {
vpc_id = aws_vpc.neuvector_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.neuvector_gateway.id
}
tags = {
Name = "${var.prefix}-neuvector-route-table"
}
}
resource "aws_route_table_association" "neuvector_route_table_association" {
subnet_id = aws_subnet.neuvector_subnet.id
route_table_id = aws_route_table.neuvector_route_table.id
}
# Security group to allow all traffic
resource "aws_security_group" "neuvector_sg_allowall" {
name = "${var.prefix}-neuvector-allowall"
description = "NeuVector quickstart - allow all traffic"
vpc_id = aws_vpc.neuvector_vpc.id
ingress {
from_port = "0"
to_port = "0"
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = "0"
to_port = "0"
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Creator = "neuvector-quickstart"
}
}
# AWS EC2 instance for creating a single node RKE cluster and installing the RKE2 cluster and NeuVector
resource "aws_instance" "neuvector_server" {
depends_on = [
aws_route_table_association.neuvector_route_table_association
]
ami = data.aws_ami.sles.id
instance_type = var.instance_type
key_name = aws_key_pair.quickstart_key_pair.key_name
vpc_security_group_ids = [aws_security_group.neuvector_sg_allowall.id]
subnet_id = aws_subnet.neuvector_subnet.id
associate_public_ip_address = true
root_block_device {
volume_size = 16
}
provisioner "remote-exec" {
inline = [
"echo 'Waiting for cloud-init to complete...'",
"cloud-init status --wait > /dev/null",
"echo 'Completed cloud-init!'",
]
connection {
type = "ssh"
host = self.public_ip
user = local.node_username
private_key = tls_private_key.global_key.private_key_pem
}
}
tags = {
Name = "${var.prefix}-neuvector-server"
Creator = "neuvector-quickstart"
}
}