Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding internet gateway to fix autogenerate VPC and subnet issue #33

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 53 additions & 27 deletions aws/network.tf
Original file line number Diff line number Diff line change
@@ -1,28 +1,54 @@
# This code creates a VPC and Subnet. The code applies just fine. But Systems Manager (SSM) is unusable. Says something isn't right. Been tracking it down for far too long and it's outside the scope of this change anyway so commenting and moving along. This VPC/Subnet issue is tracked in #9.
# resource "aws_vpc" "opencti_vpc" {
# cidr_block = "10.1.0.0/16"

# tags = {
# Name = "OpenCTI VPC"
# }
# }

# resource "aws_subnet" "opencti_subnet" {
# vpc_id = aws_vpc.opencti_vpc.id
# cidr_block = "10.1.10.0/24"
# availability_zone = var.availability_zone

# tags = {
# Name = "OpenCTI subnet"
# }
# }

# resource "aws_network_interface" "opencti_nic" {
# subnet_id = aws_subnet.opencti_subnet.id
# # private_ips = ["10.1.10.100"]
# security_groups = [ aws_security_group.opencti_sg.id ]

# tags = {
# Name = "primary_network_interface"
# }
# }
resource "aws_vpc" "opencti_vpc" {
cidr_block = "10.1.0.0/16"

tags = {
Name = "OpenCTI VPC"
}
}

resource "aws_subnet" "opencti_subnet" {
vpc_id = aws_vpc.opencti_vpc.id
cidr_block = "10.1.10.0/24"
availability_zone = var.availability_zone

tags = {
Name = "OpenCTI subnet"
}
}

resource "aws_internet_gateway" "opencti_gw" {
vpc_id = aws_vpc.opencti_vpc.id

tags = {
Name = "opencti_internet_gateway"
}
}

resource "aws_route_table" "opencti_rt" {
vpc_id = aws_vpc.opencti_vpc.id

route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.opencti_gw.id
}

tags = {
Name = "opencti_route_table"
}
}

resource "aws_route_table_association" "opencti_route_assoc" {
subnet_id = aws_subnet.opencti_subnet.id
route_table_id = aws_route_table.opencti_rt.id
}

resource "aws_network_interface" "opencti_nic" {
subnet_id = aws_subnet.opencti_subnet.id
# private_ips = ["10.1.10.100"]
security_groups = [aws_security_group.opencti_sg.id]

tags = {
Name = "primary_network_interface"
}
}
2 changes: 1 addition & 1 deletion aws/security_group.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Security group
resource "aws_security_group" "opencti_sg" {
name = "opencti_sg"
vpc_id = var.vpc_id
vpc_id = aws_vpc.opencti_vpc.id

ingress {
description = "Allow access to application on port 4000"
Expand Down
2 changes: 0 additions & 2 deletions aws/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ login_email = "login.email@example.com"
# region = "us-east-1"
# root_volume_size = 32
# storage_bucket = "opencti-storage"
subnet_id = ""
vpc_id = ""
22 changes: 12 additions & 10 deletions aws/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
variable "aws_profile" {
description = "AWS profile to use"
type = string
default = "open-cti"
}

variable "shared_config_files" {
description = "List of IP addresses allowed to access application on port 4000 of public IP. Default is all IPs."
type = list(string)
default = ["~/.aws/config"]
}

variable "allowed_ips_application" {
description = "List of IP addresses allowed to access application on port 4000 of public IP. Default is all IPs."
type = list(string)
Expand Down Expand Up @@ -39,13 +51,3 @@ variable "storage_bucket" {
type = string
default = "opencti-storage"
}

variable "subnet_id" {
description = "The subnet ID to use."
type = string
}

variable "vpc_id" {
description = "The VPC ID to use."
type = string
}
2 changes: 1 addition & 1 deletion aws/vm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resource "aws_instance" "opencti_instance" {
root_block_device {
volume_size = var.root_volume_size
}
subnet_id = var.subnet_id
subnet_id = aws_subnet.opencti_subnet.id

# The wrapper script is used by each of the providers and each variable has to be filled out in order to run. Unfortunately, this means that if you change something in one provider, you have to change it in each of the others. It's not ideal, but FYI.
user_data = templatefile("../userdata/installation-wrapper-script.sh", {
Expand Down