Skip to content

aws-samples/eks-jumphost

EKS Jumphost

Terraform module to create an EC2 instance used as a jumphost to interact with a private EKS cluster.

Architecture

architecture

Usage

module "eks_jumphost_instance" {
  source = "../.."

  https_egress_cidr_blocks      = var.https_egress_cidr_blocks
  https_egress_ipv6_cidr_blocks = var.https_egress_ipv6_cidr_blocks
  kms_key_id                    = var.kms_key_id
  monitoring                    = var.monitoring
  subnet_id                     = var.subnet_id
  tags                          = var.tags
  vpc_id                        = var.vpc_id
}


resource "null_resource" "deploy_eks_sample_app" {
  provisioner "local-exec" {
    command = file(module.eks_jumphost_instance.start_eks_jumphost_path)
    environment = {
      AWS_PAGER   = "",
      INSTANCE_ID = module.eks_jumphost_instance.instance_id,
      REGION      = var.region,
    }
  }
  provisioner "local-exec" {
    command = "aws eks update-kubeconfig --name $CLUSTER_ID --region $REGION"
    environment = {
      AWS_PAGER  = "",
      CLUSTER_ID = var.cluster_id,
      REGION     = var.region,
    }
  }
  provisioner "local-exec" {
    command = templatefile(module.eks_jumphost_instance.execute_script_jumphost_path, {
      script = <<-EOT
      HTTPS_PROXY=socks5://127.0.0.1:8443 kubectl apply -f app/manifests
      EOT
    })
    environment = {
      AWS_PAGER   = "",
      INSTANCE_ID = module.eks_jumphost_instance.instance_id,
      LOCAL_PORT  = 8443,
      NO_PROXY    = "",
      REGION      = var.region,
    }
  }
  provisioner "local-exec" {
    command = file(module.eks_jumphost_instance.stop_eks_jumphost_path)
    environment = {
      AWS_PAGER   = "",
      INSTANCE_ID = module.eks_jumphost_instance.instance_id,
      REGION      = var.region,
    }
  }
  triggers = {
    app = sha1(join("", [for file in fileset(path.cwd, "app/**") : filesha1(file)])),
  }
}

Considerations

This Terraform module creates an EC2 instance that can be used as a jumphost to interact with a private EKS cluster.

Its usage is meant for development environments, not production: in the latter case provisioning should be done via a continuous integration and deployment platform.

The scripts provided as part of the module are compatible with UNIX-based workstations only.

Prerequisites to run the scripts are:

Examples

Contributing

Follow the instructions in prerequisites then refer to the contributing guidelines.

Prerequisites

Install on your workstation the following tools:

Then initialize pre-commit by running:

pre-commit install

License

See LICENSE.

About

Terraform module to create an EC2 instance used as a jumphost to interact with a private EKS cluster.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published