Skip to content

Commit

Permalink
git reset --soft $(git merge-base main HEAD)
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Weber <[email protected]>
  • Loading branch information
mm-weber committed Jun 4, 2024
1 parent b2c7284 commit 6dbde2f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
2 changes: 2 additions & 0 deletions aws/ec2-instances/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ This repository contains Terraform code for provisioning AWS EC2 instances for t
| Oracle 8 cnspec | Latest Oracle 8 image with latest cnspec | `create_oracle8_cnspec` | |
| Oracle 8 CIS | CIS Oracle Linux 8 Benchmark - Level 1 | `create_oracle8_cis` | [CIS Oracle Linux 8 Benchmark - Level 1](https://aws.amazon.com/marketplace/pp/prodview-qohiqfju7iecs?sr=0-1&ref_=beagle&applicationId=AWSMPContessa) |
| Oracle 8 CIS cnspec | CIS Oracle Linux 8 Benchmark - Level 1 with latest cnspec | `create_oracle8_cis_cnspec` | [CIS Oracle Linux 8 Benchmark - Level 1](https://aws.amazon.com/marketplace/pp/prodview-qohiqfju7iecs?sr=0-1&ref_=beagle&applicationId=AWSMPContessa) |
| RHEL 7 | Latest Red Hat Enterprise Linux 7 | `create_rhel7` | |
| RHEL 7 cnspec | Latest Red Hat Enterprise Linux 7 with latest cnspec | `create_rhel7_cnspec` |
| RHEL 7 CIS | CIS Red Hat Enterprise Linux 7 Benchmark - Level 2 | `create_rhel7_cis` | [CIS Red Hat Enterprise Linux 7 Benchmark - Level 2](https://aws.amazon.com/marketplace/server/procurement?productId=03540ff7-d998-4f87-888a-db80e0f993ef) |
| RHEL 7 CIS cnspec | CIS Red Hat Enterprise Linux 7 Benchmark - Level 2 with latest cnspec | `create_rhel7_cis_cnspec` | [CIS Red Hat Enterprise Linux 7 Benchmark - Level 2](https://aws.amazon.com/marketplace/server/procurement?productId=03540ff7-d998-4f87-888a-db80e0f993ef) |
| RHEL 8 | Latest Red Hat Enterprise Linux 8 | `create_rhel8` | |
Expand Down
16 changes: 16 additions & 0 deletions aws/ec2-instances/amis.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ data "aws_ami" "rhel8_cis" {
owners = ["679593333241"]
}

data "aws_ami" "rhel7" {
most_recent = true

filter {
name = "name"
values = ["RHEL_HA-7*_HVM-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["309956199498"]
}

data "aws_ami" "rhel7_cis" {
most_recent = true

Expand Down
42 changes: 40 additions & 2 deletions aws/ec2-instances/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ resource "random_id" "instance_id" {
byte_length = 4
}

# and assigned the IP address of the person who runs the terraform to the ource_address_prefix
data "http" "clientip" {
url = "https://ipv4.icanhazip.com/"
}

locals {

userIP = "${chomp(data.http.clientip.response_body)}/32"

linux_user_data = <<-EOT
#!/bin/bash
bash -c "$(curl -sSL https://install.mondoo.com/sh)"
Expand Down Expand Up @@ -72,7 +80,7 @@ module "linux_sg" {
to_port = 0
protocol = "-1"
description = "Allow all from my ip"
cidr_blocks = "10.0.0.0/8,${var.publicIP}"
cidr_blocks = "10.0.0.0/8,${local.userIP}"
}
]

Expand Down Expand Up @@ -515,6 +523,36 @@ module "rhel8_cis_cnspec" {
}

// Red Hat Linux 7
module "rhel7" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "~> 5.2.1"

create = var.create_rhel7
name = "${var.prefix}-rhel7-${random_id.instance_id.id}"
ami = data.aws_ami.rhel7.id
instance_type = var.linux_instance_type
vpc_security_group_ids = [module.linux_sg.security_group_id]
subnet_id = module.vpc.public_subnets[0]
key_name = var.aws_key_pair_name
associate_public_ip_address = true
}

module "rhel7_cnspec" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "~> 5.2.1"

create = var.create_rhel7_cnspec
name = "${var.prefix}-rhel7-cnspec-${random_id.instance_id.id}"
ami = data.aws_ami.rhel7.id
instance_type = var.linux_instance_type
vpc_security_group_ids = [module.linux_sg.security_group_id]
subnet_id = module.vpc.public_subnets[0]
key_name = var.aws_key_pair_name
associate_public_ip_address = true
user_data = base64encode(local.linux_user_data)
user_data_replace_on_change = true
}

module "rhel7_cis" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "~> 5.2.1"
Expand Down Expand Up @@ -864,7 +902,7 @@ module "windows_sg" {
to_port = 0
protocol = "-1"
description = "Allow all from my ip"
cidr_blocks = "10.10.0.0/16,${var.publicIP}"
cidr_blocks = "10.10.0.0/16,${local.userIP}"
}
]

Expand Down
27 changes: 27 additions & 0 deletions aws/ec2-instances/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ output "vpc-name" {
value = module.vpc.name
}

output "deployer_ip_address" {
value = local.userIP
}

output "data_public_ip_address" {
value = chomp(data.http.clientip.response_body)
}

# amazon2_instances
output "amazon2" {
value = module.amazon2.public_ip == null ? "" : "ssh -o StrictHostKeyChecking=no -i ~/.ssh/${var.aws_key_pair_name} ec2-user@${module.amazon2.public_ip}"
Expand All @@ -28,6 +36,25 @@ output "amazon2023_cnspec" {
value = module.amazon2023_cnspec.public_ip == null ? "" : "ssh -o StrictHostKeyChecking=no -i ~/.ssh/${var.aws_key_pair_name} ec2-user@${module.amazon2023_cnspec.public_ip}"
}

# rhel 7
output "rhel7" {
value = module.rhel7.public_ip == null ? "" : "ssh -o StrictHostKeyChecking=no -i ~/.ssh/${var.aws_key_pair_name} ec2-user@${module.rhel7.public_ip}"
}

output "rhel7_cnspec" {
value = module.rhel7_cnspec.public_ip == null ? "" : "ssh -o StrictHostKeyChecking=no -i ~/.ssh/${var.aws_key_pair_name} ec2-user@${module.rhel7_cnspec.public_ip}"
}


output "rhel7_cis" {
value = module.rhel7_cis.public_ip == null ? "" : "ssh -o StrictHostKeyChecking=no -i ~/.ssh/${var.aws_key_pair_name} ec2-user@${module.rhel7_cis.public_ip}"
}

output "rhel7_cis_cnspec" {
value = module.rhel7_cis_cnspec.public_ip == null ? "" : "ssh -o StrictHostKeyChecking=no -i ~/.ssh/${var.aws_key_pair_name} ec2-user@${module.rhel7_cis_cnspec.public_ip}"
}


# rhel8
output "rhel8" {
value = module.rhel8.public_ip == null ? "" : "ssh -o StrictHostKeyChecking=no -i ~/.ssh/${var.aws_key_pair_name} ec2-user@${module.rhel8.public_ip}"
Expand Down
11 changes: 11 additions & 0 deletions aws/ec2-instances/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ variable "create_rhel8_cis_cnspec" {
default = false
}

variable "create_rhel7" {
default = false
}

variable "create_rhel7_cnspec" {
default = false
}

variable "create_rhel7_cis" {
default = false
}
Expand Down Expand Up @@ -350,4 +358,7 @@ variable "windows_admin_password" {

variable "publicIP" {
description = "Your home PublicIP to configure access to ec2 instances"

# usually automatically pulled by data "http" "clientip" resource
default = ""
}

0 comments on commit 6dbde2f

Please sign in to comment.