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

Terraform docker splunk deployment #124

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b20d8ff
First completed draft of splunk terraform file.
CSL-Answer Mar 15, 2023
afe2d74
Fixed source urls for modules
CSL-Answer Mar 16, 2023
46356d1
splunk config now successfully runs a splunk instance
CSL-Answer Mar 16, 2023
b9e07db
code style ammendments
CSL-Answer Mar 17, 2023
7fb54f5
moved splunk variables to local folder for the splunk terraform code,…
CSL-Answer Mar 17, 2023
05b9eb8
Added checkov skip comments to avoid the unneeded analysis errors
CSL-Answer Mar 20, 2023
5d3154d
Bump Microsoft.AspNetCore.Mvc.Testing from 7.0.3 to 7.0.4 (#125)
dependabot[bot] Mar 23, 2023
fe16d30
Bump Alba from 7.3.0 to 7.4.0 (#126)
dependabot[bot] Mar 23, 2023
0559494
Bump AWSSDK.CloudWatchLogs from 3.7.104.33 to 3.7.104.40 (#128)
dependabot[bot] Mar 23, 2023
4391999
successfully applied however, broke current splunk instance
CSL-Answer Mar 24, 2023
64facca
updated route 53 record code
CSL-Answer Mar 27, 2023
1b0f2bf
subnet mapping now configured for one subnet
CSL-Answer Mar 28, 2023
5f423d6
Added S3 bucket for splunk
CSL-Answer Mar 28, 2023
1cf066e
Added back certificate and reference. Ammended properties pointed out…
CSL-Answer Mar 28, 2023
da1b104
Added 8000 to ec2 sg. Added certificate validation
CSL-Answer Mar 31, 2023
326b58b
added eip sg to ec2 setup
CSL-Answer Mar 31, 2023
f70c276
Fixed s3 backend
bethcryer Apr 2, 2023
06ff32e
switched to ALB, still not workin :(
bethcryer Apr 3, 2023
bbd6a45
hi :)
bethcryer Apr 3, 2023
e4867a6
Merge branch 'terraform-docker-splunk-deployment' of https://github.c…
Apr 3, 2023
5373000
reverted indentation in bash script
Apr 3, 2023
81ac819
changed ports in security group
Apr 3, 2023
30015bc
removed docker provider
CSL-Answer Apr 5, 2023
572da90
s3 access logs and related config added
CSL-Answer Apr 5, 2023
5b8fcbc
enabled deletion protection for load balancer
CSL-Answer Apr 12, 2023
d2c53e7
Added skip for aws autoscaling EC2 launch template checkov check
CSL-Answer Apr 12, 2023
7a6f5d9
Skipped checkov check for S3 bucket event notifications
CSL-Answer Apr 12, 2023
a10a2ed
Skipped check for EC2 lanch templates for the aws_autoscaling_group r…
CSL-Answer Apr 13, 2023
a91ff96
Checkov check for KMS encryption on S3 buckets has been skipped. Will…
CSL-Answer Apr 13, 2023
c0d6e37
Added checkov skips for the elb_logs resource
CSL-Answer Apr 13, 2023
68d7a0d
Set associate public ip address to false for the splunk ec2 instance
CSL-Answer Apr 13, 2023
ec869d2
Load balancer for splunk is not using TLS 1.2
CSL-Answer Apr 13, 2023
fca116d
Added versioning for the elb logs s3 bucket
CSL-Answer Apr 13, 2023
33f9c62
updated ec2 instance set up to use the new version 2.1.0 for the ec2 …
CSL-Answer Apr 17, 2023
6936d3d
Successfully applies with ec2 update
CSL-Answer Apr 17, 2023
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
5 changes: 5 additions & 0 deletions terraform/splunk/splunk-providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#aws provider here
provider "aws" {
region = "eu-west-2"
skip_credentials_validation = true
}
17 changes: 17 additions & 0 deletions terraform/splunk/splunk-variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "splunk_project_name" {
type = string
description = "Splunk Project Name"
default = "answerking-splunk-instance"
}

variable "splunk_project_owner" {
type = string
description = "Splunk Resource Owner"
default = "answerking"
}

variable "splunk_domain_name" {
type = string
description = "Splunk Domain Name"
default = "splunk.answerking.co.uk"
}
204 changes: 204 additions & 0 deletions terraform/splunk/splunk.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
module "splunk_vpc_subnet" {
bethcryer marked this conversation as resolved.
Show resolved Hide resolved
source = "git::https://github.com/answerdigital/terraform-modules//Terraform_modules/vpc_subnets?ref=v1.0.0"
owner = var.splunk_project_owner
project_name = var.splunk_project_name
azs = ["eu-west-2a"]
}

data "aws_ami" "amazon_linux_2" {
most_recent = true
owners = ["amazon"]

filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-ebs"]
}
}

resource "aws_security_group" "ec2_sg" {
#checkov:skip=CKV_AWS_260:Allowing ingress from 0.0.0.0 for public HTTP(S) access
#checkov:skip=CKV2_AWS_5
name = "${var.splunk_project_name}-ec2-sg"
description = "Security group for ec2_sg"
vpc_id = module.splunk_vpc_subnet.vpc_id

ingress {
from_port = 0
to_port = 0
protocol = "-1"
security_groups = [aws_security_group.lb_sg.id]
description = "Application Load Balancer"
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
description = "All traffic"
}

tags = {
Name = "${var.splunk_project_name}-ec2-sg"
Owner = var.splunk_project_owner
}
}

module "ec2_instance_setup" {
source = "git::https://github.com/AnswerConsulting/AnswerKing-Infrastructure.git//Terraform_modules/ec2_instance?ref=v1.0.0"
project_name = var.splunk_project_name
owner = var.splunk_project_owner
ami_id = data.aws_ami.amazon_linux_2.id
availability_zone = "eu-west-2a"
subnet_id = module.splunk_vpc_subnet.public_subnet_ids[0]
vpc_security_group_ids = [aws_security_group.ec2_sg.id]
needs_elastic_ip = false #true
user_data = <<EOF
#!/bin/bash -xe
#logs all user_data commands into a user-data.log file
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1

sudo yum update -y
sudo yum upgrade -y
sudo yum install docker -y
sudo systemctl enable docker.service
sudo systemctl start docker.service

sudo docker pull splunk/splunk:latest
sudo docker run -d -p 80:8000 -e "SPLUNK_START_ARGS=--accept-license" -e "SPLUNK_PASSWORD={password}" --name splunk splunk/splunk:latest
EOF
}

# route 53

resource "aws_route53_record" "splunk" {
zone_id = "Z0072706JT6B6N2J7Z9H" #data.aws_route53_zone.hosted_zone.zone_id
PietroConvalleAD marked this conversation as resolved.
Show resolved Hide resolved
name = var.splunk_domain_name #"answerking.co.uk"
type = "A"
ttl = 300
records = [module.ec2_instance_setup.instance_public_ip_address] #[aws_lb.lb.dns_name]
PietroConvalleAD marked this conversation as resolved.
Show resolved Hide resolved
}

#resource "aws_route53_zone" "hosted_zone" {
# name = var.splunk_domain_name
#}

# Elastic IP

resource "aws_eip" "lb_eip" {
PietroConvalleAD marked this conversation as resolved.
Show resolved Hide resolved
#checkov:skip=CKV2_AWS_19:IP is being used for load balancer
vpc = true
count = "2"
bethcryer marked this conversation as resolved.
Show resolved Hide resolved

tags = {
Name = "${var.splunk_project_name}-eip-${count.index}"
Owner = var.splunk_project_owner
}
}


# Load balancer

resource "aws_security_group" "lb_sg" {
#checkov:skip=CKV_AWS_260:Allowing ingress from 0.0.0.0 for public HTTP(S) access
#checkov:skip=CKV2_AWS_5
name = "${var.splunk_project_name}-lb-sg"
description = "Security group for lb-sg"
vpc_id = module.splunk_vpc_subnet.vpc_id

ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
description = "HTTP"
}

ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
description = "HTTPS"
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
description = "All traffic"
}

tags = {
Name = "${var.splunk_project_name}-lb-sg"
Owner = var.splunk_project_owner
}
}

resource "aws_lb" "lb" {
name = "${var.splunk_project_name}-lb"
internal = false
load_balancer_type = "network"
ip_address_type = "ipv4"

dynamic "subnet_mapping" {
for_each = module.splunk_vpc_subnet.public_subnet_ids
content {
subnet_id = "${subnet_mapping.value}"
allocation_id = "${aws_eip.lb_eip[subnet_mapping.key].id}"
}
}
bethcryer marked this conversation as resolved.
Show resolved Hide resolved

tags = {
Name = "${var.splunk_project_name}-lb"
}
}

resource "aws_lb_target_group" "target_group" {
name = "${var.splunk_project_name}-lb-tg"
port = 443
protocol = "TCP"
target_type = "alb"
bethcryer marked this conversation as resolved.
Show resolved Hide resolved
vpc_id = module.splunk_vpc_subnet.vpc_id

tags = {
Name = "${var.splunk_project_name}-lb-target-group"
}

lifecycle {
create_before_destroy = true
ignore_changes = [name]
}
}

#resource "aws_acm_certificate" "cert" {
bethcryer marked this conversation as resolved.
Show resolved Hide resolved
# domain_name = var.splunk_domain_name
# validation_method = "DNS"
#
# lifecycle {
# create_before_destroy = true
# }
#}

PietroConvalleAD marked this conversation as resolved.
Show resolved Hide resolved
resource "aws_lb_listener" "lb_listener" {
load_balancer_arn = aws_lb.lb.id
port = "80"
protocol = "TCP"

PietroConvalleAD marked this conversation as resolved.
Show resolved Hide resolved
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.target_group.id
}
}

resource "aws_lb_listener" "lb_listener_443" {
load_balancer_arn = aws_lb.lb.id
port = "443"
protocol = "TCP"

bethcryer marked this conversation as resolved.
Show resolved Hide resolved
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.target_group.id
}
}
5 changes: 5 additions & 0 deletions terraform/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ terraform {
source = "hashicorp/random"
version = ">= 3.4.3"
}

docker = {
bethcryer marked this conversation as resolved.
Show resolved Hide resolved
source = "kreuzwerker/docker"
version = "~> 2.13.0"
}
}
}