Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/Answer.King.Api/Answer.King.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ItemGroup>
<PackageReference Include="AWS.Logger.AspNetCore" Version="3.3.0" />
<PackageReference Include="AWS.Logger.SeriLog" Version="3.2.0" />
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.104.33" />
<PackageReference Include="AWSSDK.CloudWatchLogs" Version="3.7.104.40" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.5" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.2.2" />
<PackageReference Include="Serilog" Version="2.12.0" />
Expand Down
12 changes: 6 additions & 6 deletions src/Answer.King.Api/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
},
"AWSSDK.CloudWatchLogs": {
"type": "Direct",
"requested": "[3.7.104.33, )",
"resolved": "3.7.104.33",
"contentHash": "IkG8APzfnH54VfIC8qUwDuuotsOd8kJ4FlXuUspzr9JA6V1QkXTiNHvEfooNnMP5UlFMKLMea1lZbDs8zBDDTw==",
"requested": "[3.7.104.40, )",
"resolved": "3.7.104.40",
"contentHash": "KDl4kHFiTkjGwtU31dgUbhS/ouYRHk/qftZZs+SR3rnR4lQFduvRYN/zWUUppti6MC1XT6uA7JTbE7UzEqjrkQ==",
"dependencies": {
"AWSSDK.Core": "[3.7.105.19, 4.0.0)"
"AWSSDK.Core": "[3.7.106.4, 4.0.0)"
}
},
"AWSSDK.Extensions.NETCore.Setup": {
Expand Down Expand Up @@ -211,8 +211,8 @@
},
"AWSSDK.Core": {
"type": "Transitive",
"resolved": "3.7.105.19",
"contentHash": "RHSJu4gmQMvqGdxcNVNWglueXGFma+d6n3MUvWsMieosLbWvFq3TzCkeNF0Zmf69iUxNTHTWv+zoYNsFygZk+g=="
"resolved": "3.7.106.4",
"contentHash": "U+U7j0k5NxXXjjD9yxsVN5MjRpYlTSMyaDjLqwJaaeoFhycdkJ81t3Baret6VBwIGMmYpjAerk79vLAhvwU5Wg=="
},
"FluentValidation": {
"type": "Transitive",
Expand Down
2 changes: 2 additions & 0 deletions terraform/launch-config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data "template_file" "user_data" {
resource "aws_launch_configuration" "ecs_launch_config" {
#checkov:skip=CKV_AWS_79:TODO: Disable the Instance Metadata Service or enable it with proper configuration (v2)
#checkov:skip=CKV_AWS_8:TODO: Encrypt volume in future security ticket
#checkov:skip=CKV_AWS_315:TODO: Look into aws autoscaling if necessary
image_id = data.aws_ami.ecs_ami.id
iam_instance_profile = aws_iam_instance_profile.ecs_instance_profile.name
security_groups = [aws_security_group.ecs_sg.id]
Expand All @@ -40,6 +41,7 @@ resource "aws_launch_configuration" "ecs_launch_config" {
}

resource "aws_autoscaling_group" "failure_analysis_ecs_asg" {
#checkov:skip=CKV_AWS_315:TODO: Look into aws autoscaling if necessary
name = "${var.project_name}-auto-scaling-group"
launch_configuration = aws_launch_configuration.ecs_launch_config.name
vpc_zone_identifier = [
Expand Down
92 changes: 92 additions & 0 deletions terraform/splunk/ec2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
terraform {
required_version = "~> 1.3"

required_providers {
tls = {
source = "hashicorp/tls"
version = ">= 4.0.4"
}
}
}

resource "aws_iam_instance_profile" "instance_profile" {
name = "${var.project_name}-ec2-monitoring-and-setup"
role = aws_iam_role.instance_role.name
}

resource "aws_iam_role" "instance_role" {
name = "${var.project_name}-ec2-monitoring-and-setup"
assume_role_policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": ["sts:AssumeRole"],
"Effect": "Allow",
"Principal": {
"Service": ["ec2.amazonaws.com"]
}
}
]
}
EOF
}

resource "aws_iam_role_policy_attachment" "instance_role" {
for_each = toset([
"arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM",
"arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
])
role = aws_iam_role.instance_role.name
policy_arn = each.value
}

resource "tls_private_key" "private_key" {
algorithm = "RSA"
rsa_bits = 4096
}

resource "aws_key_pair" "key_pair" {
key_name = "${var.project_name}-key-pair"
public_key = tls_private_key.private_key.public_key_openssh
}

resource "aws_instance" "ec2" {
instance_type = var.ec2_instance_type
key_name = aws_key_pair.key_pair.key_name
ami = var.ami_id
metadata_options {
http_endpoint = "enabled"
http_tokens = "required"
}
root_block_device {
encrypted = true
}

availability_zone = var.availability_zone
subnet_id = var.subnet_id
vpc_security_group_ids = var.vpc_security_group_ids
associate_public_ip_address = var.associate_public_ip_address

iam_instance_profile = aws_iam_instance_profile.instance_profile.name

user_data = var.user_data
user_data_replace_on_change = var.user_data_replace_on_change

tags = {
Name = "${var.project_name}-ec2"
Owner = var.owner
}
}

resource "aws_eip" "public_elastic_ip" {
count = var.needs_elastic_ip == true ? 1 : 0

instance = aws_instance.ec2.id
vpc = true

tags = {
Name = "${var.project_name}-public-elastic-ip"
Owner = var.owner
}
}
9 changes: 9 additions & 0 deletions terraform/splunk/ec2/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "instance_public_ip_address" {
value = aws_instance.ec2.public_ip
description = "This outputs the public IP associated with the EC2 instance. Note that this ouput will be the same as the elastic IP if `needs_elastic_ip` is set to `true`. This output is of type `string`."
}

output "ec2_id" {
value = aws_instance.ec2.id
description = "This outputs the ID of the EC2 instance."
}
65 changes: 65 additions & 0 deletions terraform/splunk/ec2/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
MANDATORY VARIABLES
*/
variable "project_name" {
type = string
description = "This is used to label the resources of the module."
}

variable "owner" {
type = string
description = "This is used to specify the owner of the resources in this module."
}

variable "ami_id" {
type = string
description = "This is the id of the ami image used for the ec2 instance."
}

variable "availability_zone" {
type = string
description = "This is the availability zone you want the ec2 instance to be created in."
}

variable "subnet_id" {
type = string
description = "This is the id of the subnet you want the ec2 instance to be created in."
}

variable "vpc_security_group_ids" {
type = list(string)
description = "This is a list of ids that specifies the security groups you want your EC2 to be in. If you do not wish to specify a security group for your module then please set this value to an empty list"
}

/*
OPTIONAL VARIABLES
*/
variable "ec2_instance_type" {
type = string
default = "t2.micro"
description = "This is the type of EC2 instance you want."
}

variable "associate_public_ip_address" {
type = bool
default = true
description = "This is a boolean value indicating if a public IP address should be associated with the EC2 instance."
}

variable "user_data" {
type = string
default = ""
description = "This allows bash scripts and command line commands to be specified and run in the EC2 instance when launched. Do not pass gzip-compressed data via this argument."
}

variable "needs_elastic_ip" {
type = bool
default = false
description = "This is a boolean value indicating whether an elastic IP should be generated and associated with the EC2 instance."
}

variable "user_data_replace_on_change" {
type = bool
default = true
description = "This value indicates whether changes to the `user_data` value triggers a rebuild of the EC2 instance."
}
51 changes: 51 additions & 0 deletions terraform/splunk/splunk-backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
terraform {
backend "s3" {
bucket = "answerking-splunk-terraform"
key = "answerking-splunk-terraform.tfstate"
region = "eu-west-2"
dynamodb_table = "answerking-splunk-terraform-state"
}
}

/*
resource "aws_s3_bucket" "terraform_backend_bucket" {
bucket = "answerking-splunk-terraform"

tags = {
Name = "answerking-splunk-terraform"
}
}

resource "aws_s3_bucket_acl" "terraform_backend_bucket_acl" {
bucket = aws_s3_bucket.terraform_backend_bucket.id
acl = "private"
}

resource "aws_s3_bucket_public_access_block" "terraform_backend_bucket_public_access_block" {
bucket = aws_s3_bucket.terraform_backend_bucket.id

block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}

resource "aws_s3_bucket_versioning" "terraform_backend_bucket_versioning" {
bucket = aws_s3_bucket.terraform_backend_bucket.id
versioning_configuration {
status = "Enabled"
}
}

resource "aws_dynamodb_table" "terraform_backend_state" {
name = "answerking-splunk-terraform-state"
read_capacity = 20
write_capacity = 20
hash_key = "LockID"

attribute {
name = "LockID"
type = "S"
}
}
*/
Comment on lines +10 to +51

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we keep all of this commented?

Copy link
Contributor

@bethcryer bethcryer Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I think leave it so that it's obvious all this exists on AWS and we could delete the resources in future if we needed to

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
}
23 changes: 23 additions & 0 deletions terraform/splunk/splunk-variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 "dns_base_domain_name" {
type = string
description = "DNS Base Domain Name"
default = "answerking.co.uk"
}

variable "dns_splunk_domain_name" {
type = string
description = "Splunk Domain Name"
default = "splunk.answerking.co.uk"
}
Loading